function EnumWindowsProc(Wnd : HWND; WindowListInt : ptruint) : BOOL; stdcall;
{ this function is called by the EnumWindows call. It fills the a window }
{ list with the window information we are interested in. }
var
WindowList : PWindowList absolute WindowListInt;
ProcessHandle : THANDLE;
TimeOfNoInterest : TFILETIME;
ProcessExecutableSize : DWORD;
begin
EnumWindowsProc := TRUE; { continue enumerating until no more windows }
with WindowList^.WindowInfo[WindowList^.WindowCount] do
begin
WindowHandle := Wnd;
WindowThreadId := GetWindowThreadProcessId(Wnd, @WindowProcessId);
WindowVisible := IsWindowVisible(Wnd);
GetWindowText(Wnd, WindowCaption, sizeof(WindowCaption));
{ get the process times for this process. NOTE: the method used here is }
{ very inefficient since a handle for the same process is obtained for }
{ every window the process has created. }
ProcessHandle := OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
FALSE,
WindowProcessId);
if ProcessHandle <> 0 then
begin
{ IMPORTANT: the size must be reset every time because QueryFullProcess }
{ ImageName sets it to the length of the returned string }
{ every time it's called. }
ProcessExecutableSize := sizeof(WindowProcessExecutable);
QueryFullProcessImageName(ProcessHandle,
0,
WindowProcessExecutable,
ProcessExecutableSize);
GetProcessTimes(ProcessHandle,
WindowProcessCreationTime,
TimeOfNoInterest,
TimeOfNoInterest,
TimeOfNoInterest);
CloseHandle(ProcessHandle);
end;
end;
with WindowList^ do
begin
WindowInfoPointers[WindowCount] := @WindowInfo[WindowCount];
inc(WindowCount);
if WindowCount > high(WindowInfo) then
begin
EnumWindowsProc := FALSE; { no more room, stop enumerating }
end;
end;
end;