//set a new function
function GetHwndFromProcess(ProcessId: DWORD): HWND;
function _EnumWindowsProc(P_HWND: Cardinal; lParam: Cardinal): Boolean; stdcall;
var
PID: DWORD;
begin
GetWindowThreadProcessId(P_HWND, @PID);
if PCardinal(lParam)^ <> PID then
Result := True
else
begin
Result := False;
PCardinal(lParam+4)^ := P_HWND;
end;
end;
var
Buffer: array[0..1] of Cardinal;
begin
Result := 0;
Buffer[0] := ProcessId;
Buffer[1] := 0;
EnumWindows(@_EnumWindowsProc, Integer(@Buffer));
if Buffer[1] > 0 then Result := Buffer[1];
end;