Detailed DELPHI API function (1)

zhaozj2021-02-11  259

(1) Controls and message functions

1, grammar: 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, grammar: enableWindow (hwnd: hwnd; b parkle: 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, grammar: 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 the begini: = 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;

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

New Post(0)