So you can do something like this (like you mentioned) but it's far from optimal.
uses Windows, dwmapi;
function GetRealWindowRect(Handle: HWND; var R: TRect): Boolean;
begin
Result := (GetParent(Handle) = 0) and DwmCompositionEnabled and
(DwmGetWindowAttribute(Handle, DWMWA_EXTENDED_FRAME_BOUNDS, @R, SizeOf(R)) = S_OK);
if not Result then
Result := GetWindowRect(Handle, R);
end;
function GetInvisibleBorder(Handle: Hwnd): Integer;
var
R1, R2: TRect;
begin
Result := 0;
if GetRealWindowRect(Handle, R1) and GetWindowRect(Handle, R2) then
begin
Result := R1.Left - R2.Left;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitDwmLibrary;
Top := 0;
Left := 0;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
Left := 0 - GetInvisibleBorder(Handle); // only possible after window is visible
end;