From a newsgroup I got hold on this piece of sourcecode, which is supposed to get me the window handle from a processID. Well my question is in fact quite simple. It doesn't work, but whats wrong. I know that the if statement in the callback function EnumProc() never equals true, so no handle can be returned. Unfortunatly I can't seem to udnerstand exactly what is going on. Please help
Type
TEnumData = Record
hW: HWND;
pID: DWORD;
End;
Function EnumProc( hw: HWND; Var data: TEnumData ): Bool; stdcall;
Var
pID: DWORD;
Begin
Result := True;
If (GetWindowLong(hw, GWL_HWNDPARENT) = 0) and
(IsWindowVisible( hw ) or IsIconic(hw)) and
((GetWindowLong(hw, GWL_EXSTYLE) and WS_EX_APPWINDOW) <> 0)
Then Begin
GetWindowThreadProcessID( hw, @pID );
If pID = data.pID Then Begin
data.hW := hW;
Result := False;
End; { If }
End; { If }
End; { EnumProc }
Function WindowFromProcessID( pID: DWORD ): HWND;
Var
data: TEnumData;
Begin
data.pID := pID;
data.hW := 0;
EnumWindows( @EnumProc, longint(@data) );
Result := data.hW;
End; { WindowFromProcessID }
Start Free Trial