Hi,
mit
EnumThreadWindows müsste es
IMHO auch gehen, die Fenster in der Liste müsstest du eventuell nochmal filtern.
Mal schnell zusammengetippt:
Delphi-Quellcode:
uses TLHelp32, Contnrs;
type
TWndItem = class(TObject)
Wnd: HWND;
end;
function EnumThreadWndProc(Wnd: HWND; WndList: TObjectList): BOOL; stdcall;
var
WndItem: TWndItem;
begin
WndItem:= TWndItem.Create;
WndItem.Wnd:= Wnd;
WndList.Add(WndItem);
Result:= true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
WndList: TObjectList;
Thread32: TThreadEntry32;
hThreadSnap: THandle;
ProcId: DWord;
i: integer;
myBuf: array[0..250] of Char;
begin
WndList:= TObjectList.Create;
try
ProcId := ...;//GetCurrentProcessId();
hThreadSnap := CreateToolHelp32Snapshot(TH32CS_SNAPTHREAD, ProcId);
if (hThreadSnap > 0) and (hThreadSnap <> INVALID_HANDLE_VALUE) then
try
ZeroMemory(@Thread32, SizeOf(TThreadEntry32));
Thread32.dwSize := SizeOf(TThreadEntry32);
if Thread32First(hThreadSnap, Thread32) then
repeat
if ProcId = Thread32.th32OwnerProcessID then
EnumThreadWindows(Thread32.th32ThreadID, @EnumThreadWndProc, DWord(WndList));
until not Thread32Next(hThreadSnap, Thread32);
finally
CloseHandle(hThreadSnap);
end;
for i:= 0 to Pred(WndList.Count) do
begin
if Windows.IsWindowVisible(TWndItem(WndList.Items[i]).Wnd) then
begin
GetWindowText(TWndItem(WndList.Items[i]).Wnd, myBuf, sizeof(myBuf));
ListBox1.Items.Add(myBuf);
end;
end;
finally
WndList.Free;
end;
end;