I have tried getting the main window:
var
ScreenDC: HDC;
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
ScreenDC := GetDC(0);
Bitmap.LoadFromDevice(ScreenDC);
ReleaseDC(0, ScreenDC);
Canvas.Draw(0, 0, Bitmap);
finally
Bitmap.Free;
end;
end;
and it works fine. I could extract the window I want from this bitmap.
I get in trouble if my target window is moved or resized.
Another attempt getting the foreground window:
MyBitmap := TBitmap.Create;
hWin := GetForegroundWindow;
and I get my Lazarus window (as expected).