I try to get the main window handle using following code in Lazarus (Free Pascal):
function FindMainWindow(Pid: LongWord): LongWord;
type
TParam = record
Window: HWnd;
Test: Integer;
Pid: LongWord;
end;
PParam = ^TParam;
var
Params: TParam;
function _FindMainWindow(Wnd: HWnd; MyLParam: PParam): Bool; stdcall;
var
WinPid: DWord;
begin
with MyLParam^ do
begin
Test := 2;
GetWindowThreadProcessID(Wnd, @WinPid);
Result := (WinPid <> Pid) or (not IsWindowVisible(Wnd))
or (not IsWindowEnabled(Wnd));
if not Result then begin
Window := Wnd;
end;
end;
end;
begin
Params.Pid := Pid;
Params.Test := 1;
EnumWindows(@_FindMainWindow, LParam(@Params));
ShowMessage('Done!');
ShowMessage(IntToStr(Params.Test));
Result := Params.Window;
end;
The Problem is that Params.Test
is still 1 after running the callback. I want to modify the Params
in the _FindMainWindow
function.
Note: I could not access Params
in _FindMainWindow
directly because i get an "Access violation" error.