1,183
社区成员
发帖
与我相关
我的任务
分享
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc, // pointer to callback function
LPARAM lParam // application-defined value
);
BOOL CALLBACK EnumWindowsProc(
HWND hwnd, // handle to parent window
LPARAM lParam // application-defined value
);
library dllTest1;
uses
Windows,
SysUtils;
{$R *.res}
type
TEnumBuff = record
hTextBuf: PChar;
FBuffSize: Integer;
FCount: Integer;
end;
PEnumBuff = ^TEnumBuff;
function EnumWindowsProcCB(Wnd: HWND; lParam: Integer): Boolean; stdcall;
var
X: Integer;
P: PEnumBuff;
begin
P:= Pointer(lParam);
with P^ do begin
X:= GetWindowText(Wnd, hTextBuf, FBuffSize);
Result:= (X < FBuffSize);
if Result and (X <> 0) then begin
Inc(hTextBuf, X);
hTextBuf^:= #0;
Inc(hTextBuf);
FBuffSize:= FBuffSize - (X+1);
Inc(FCount);
end;
end;
end;
function EnumWindowsNames(lpTextBuf: Pointer; BuffSize: Integer): Integer; stdcall;
var
FBuff: TEnumBuff;
begin
Result:= 0;
with FBuff do begin
hTextBuf:= lpTextBuf;
FBuffSize:= BuffSize;
FCount:= 0;
end;
if EnumWindows(@EnumWindowsProcCB, Integer(@FBuff)) then begin
Result:= FBuff.FCount;
end;
end;
exports
EnumWindowsNames name 'EnumWindowsNames';
begin end.
function EnumWindowsNames(lpTextBuf: Pointer; BuffSize: Integer): Integer; stdcall; external 'dlltest1.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
P: PChar;
N: Integer;
Buf: array [0..8191] of Char;
begin
P:= @Buf;
N:= EnumWindowsNames(P, 8192);
if N <> 0 then repeat
ListBox1.Items.Add(P);
Inc(P, StrLen(P) + 1);
Dec(N);
until N = 0;
end;