Registriert seit: 31. Aug 2004
Ort: Traiskirchen
575 Beiträge
Turbo Delphi für Win32
|
Re: ProzessID: Alle Fenster auflisten
22. Mär 2005, 14:35
diese funktion sollte genau das sein, was du brauchst
Delphi-Quellcode:
function StartProgram(Filename: String): HWND;
function EnumWindowsProc(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
begin
TList(lParam).Add(Pointer(hWnd));
Result := True;
end;
var
SI: TStartupInfo;
PI: TProcessInformation;
List: TList;
ProcessId: DWORD;
I: Integer;
myHWND: HWND;
begin
Result := 0;
myHWND := 0;
FillChar(SI, SizeOf(TStartupInfo), 0);
SI.cb := SizeOf(TStartupInfo);
SI.dwFlags := STARTF_USESHOWWINDOW;
SI.wShowWindow := SW_SHOW;
if CreateProcess(nil, PChar(Filename), nil, nil, False, 0, nil, nil, SI, PI) then
begin
WaitForInputIdle(PI.hProcess, INFINITE);
CloseHandle(PI.hProcess);
CloseHandle(PI.hThread);
List := TList.Create;
try
if EnumWindows(@EnumWindowsProc, Longint(List)) then
begin
for I := 0 to List.Count - 1 do
if GetWindowThreadProcessId(HWND(List.Items[I]), @ProcessId) <> 0 then
if ProcessId = PI.dwProcessId then
begin
myHWND := HWND(List.Items[I]);
Break;
end;
if IsWindow(myHWND) then
begin
Result := myHWND;
end;
end;
finally
List.Free;
end;
end;
end;
|
|
Zitat
|