Delphi取所有窗口句柄

来源:百度知道 编辑:UC知道 时间:2024/07/07 18:50:49
有什么办法用Delphi取所有窗口的句柄啊?最好加上详细备注

定义一个全局变量
var
handlelist: tstringlist;

procedure TForm1.Button1Click(Sender: TObject);

function GetProcessExePath(h: HWND): BOOL; stdcall;
function getfilename(str: string): string;
begin
result := UpperCase(ExtractFileName(str));
end;
var
pid: Cardinal;
pHandle: THandle;
buf: array[0..MAX_PATH] of Char;
str: string;
begin
GetWindowThreadProcessId(h, @pid);
pHandle := OpenProcess(PROCESS_ALL_ACCESS, False, pid);
GetModuleFileNameEx(pHandle, 0, buf, Length(buf));
CloseHandle(pHandle);
str := StrPas(buf);
handlelist.Add(IntTostr(h)+str);//句柄加文件路径
Result := True;
end;
var
i: integer;
begin
if form1.OpenDialog1.Execute then
begin
Edit1.Text := OpenDialog1.FileName;
EnumWindows(@getprocessexepath, 0);
for i := 0 to handlelist.count - 1 do
listbox1.items.add(handlelist.strin