给你我的小工具里的一段代码参考
function EnumThreadProc(AHandle:HWND;
lParam:LPARAM): Boolean;
stdcall;
procedure GetWindowInfo(
const AHandle : HWND;
const AList : TStrings
);
var
szText : array[0..MAXBYTE] of char;
begin
AList.Add(IntToStr(AHandle));
GetWindowText(AHandle, szText, MAXBYTE);
AList.Add(StrPas(szText));
GetClassName(AHandle, szText, MAXBYTE);
AList.Add(StrPas(szText));
end;
begin
GetWindowInfo(AHandle, TStrings(Pointer(lParam)));
Result:=True;
end;
procedure TProcessInfo.EnumWindows(const AList: TStrings);
var
snap : THandle;
ThreadStruct: TThreadEntry32;
begin
if FHandle = 0 then
Exit;
snap := CreateToolHelp32Snapshot(TH32CS_SNAPTHREAD, FHandle);
if snap <> 0 then
try
ThreadStruct.dwSize := sizeOf(TThreadEntry32);
if Thread32First(snap, ThreadStruct) then
repeat
if ThreadStruct.th32OwnerProcessID = FHandle then
EnumThreadWindows(ThreadStruct.th32ThreadID, @EnumThreadProc, Integer(AList));
until not Thread32Next(snap, ThreadStruct);
finally
CloseHandle(snap);
end;
end;