Detailed use of API functions in Delphi

zhaozj2021-02-11  272

Everyone doesn't misunderstand. It is not a soldier, but it is not a soldier, but it is the Chinese translation of the INPRISE's signature product! Introducing Delphi's article has been much more, is everyone who suffer from its powerful development function? Visual programming has made many friends a dream. Indeed, several controls are equipped with several statements, maybe a software is coming out. But is you not satisfied with the components of using others? Want to know more about Windows programming? Replacement Master Delphi? OK, please continue to look down.

The INT21H under DOS is important for the development of the DOS program, and for the development program under Windows, it is necessary to understand the API function. Components are like moving, and the API function is like a heart, with a deep internal force, then learning the move is easy. Therefore, the more API functions you have mastered, the more likely it be a Delphi master, even Windows programming masters. Therefore, both C , VB or Delphi has no exception to support the API function call, C and Delphi are fully supported API functions, and VB only supports some API functions (there are many parts of some. , Especially the Delphi call API function is most convenient, and has reached the realm of the API function, call the API function and almost the same. Below I will explain the use of the API function in Delphi in detail, I will write a small example of each statement, so that everyone can understand how it is used. If you carefully read this article, I believe that everyone will have a deeper understanding of Delphi programming. But don't take halfway, afraid of fear, remember: For those who want to practice, there must be hard work! Learn to program, can not play games, can't get a FPE cheating.

(1) Controls and message functions

1 Syntax: annpopup: bool;

Unit: windows.pas (this unit Delphi will be in Uses, below)

Role: Judgment Whether there is any pop-up window on the screen

Return Value: BOOL, Returns true if there is a pop-up menu

Note: For this function, the pop-up menu contains all visible tolerance top-level windows, regardless of pop-up or overlapping windows

Example:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

IF (AnyPopup) THEN

Label1.caption: = 'Pop-Ups Found: True'

Else

Label1.caption: = 'Pop-Ups Found: false';

END;

2 Syntax: EnableWindow (hwnd: hwnd; Benable: Bool): BOOL; Unit: Windows.Pas

Role: All mouse and keyboard input are allowed or prohibited in the specified window.

Return Value: Bool, if it is true, Windows has been disabled, otherwise returns false

Example:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

IF (ISWindowenabled (Edit1.Handle) THEN

Begin

EnableWindow (Edit1.Handle, False);

Button1.caption: = 'enable window'; edit1.text: = 'this window is disabled';

end

Else

Begin

EnableWindow (Edit1.Handle, True);

Button1.caption: = 'disable window';

Edit1.Text: = 'this window is enabled';

END;

END;

3 Syntax: FlashWindow (hwnd: hwnd; binvert: bool): bool;

Unit: Windows.PAS

Role: Blink Displays the specified window. This means that the title and instructions of the window will change, and it seems to switch from the activity to the non-active state, or switch in reverse. Usually apply this function to the inactive window, causing the attention of the user

Return Value: BOOL, if the window is active before calling, return True

Note: This function is usually used in combination with a counter to generate a continuous flicker.

In Windows NT and Windowsfor Workgroup, Binvert parameters are ignored.

But will not ignore in Windows 95

Example:

Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT);

Begin

FlashWindow (Form1.Handle, True);

FlashWindow (Application.handle, True);

END;

4 Syntax: setWindowText (hwnd: hwnd; lpstring: pchar): BOOL;

Unit: Windows.PAS

Role: Set the contents of the title text or control of the window

Return Value: Set successfully returns true, otherwise returns false

Example:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

VAR

Thet: pchar;

TEXTLEN: Integer;

Begin

TEXTLEN: = getWindowTextLength; Form1.Handle;

GetMem (THETEXT, TEXTLEN);

GetWindowText (Form1.Handle, ThetExt, Textlen 1);

Edit1.text: = String (ThetExt);

FreeMem (Thetxt);

END;

Procedure TFORM1.BUTTON2CLICK (Sender: TOBJECT);

Begin

SetwindowText (form1.handle, pchar (edit1.text));

END;

5 Syntax: IsWindow (hwnd: hwnd): BOOL;

Unit: Windows.PAS

Role: Determine if a window handle is valid

Return Value: Returns True effectively, otherwise return FALSE

Example:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

IF (iswindow (Button1.Handle) THEN

Button1.caption: = 'True'

Else

Button1.caption: = 'FALSE';

END;

How, still addictive? Today is the first time, introduce some functions that are easily acceptable, otherwise friends will definitely call. Don't you know that your friends can accept this form of arrangement? Also, I will introduce according to the classification of the API function (control and message function / hardware and system function / menu function / text and font function / print functions, etc., I will not introduce all API functions, otherwise it is The suspicion of the scam fees, and I have an example of each statement, only the usual use of usually used, sometimes introducing the API function that is more secure but very useful. With TIPS (Delphi Tips):

If there is such a directory:

C: /Windows/media/temp/abc/sound/chime.wav

I hope it can shorten:

C: / windows /../ Sound / Chime.wav

How to write the program?

Reply:

Try with the following procedure:

Function ShortenFileName (S: String): String;

VAR Drive, Curdrive: String [2];

Dir, Curdir: String [80];

Name: String [20];

EXT: STRING [5];

i: byte;

Begin

For i: = 1 to length (s) do s [i]: = Upcase (s [i]);

S: = fEXPAND (S);

FSPLIT (S, DIR, NAME, EXT);

Drive: = COPY (DIR, 1, 2);

DIR: = COPY (DIR, 4, Length (DIR) -3);

Getdir (0, Curdir);

Curdrive: = COPY (Curdir, 1, 2);

Curdir: = COPY (Curdir, 4, Length (Curdir) -3) '/';

if Drive = Curdrive Then Begin

IF Copy (Dir, 1, Length (Curdir) = Curdir Then Begin

I: = Length (Curdir);

If Length <> I THEN DIR: = DIR '/';

ShortenFileName: = COPY (DIR, I 1, Length (DIR) -i-1) Name EXT;

END ELSE ShortenFileName: = COPY (S, 3, Length (s) -2);

ELSE ShortenFileName: = S;

END;

Note: This article is only written to improve Delphi's ability to write, non-general entry-level tutorial, so all Delphi's own functions and some basic skills in the text will no longer explain, ask friends to check the Delphi online help manual.

转载请注明原文地址:https://www.9cbs.com/read-3926.html

New Post(0)