Coming back to this thread because I have found a very strange issue with the code...
I build the code on my year-old HP Zbook G5 workstation with Windows 10 and it works well here.
But when I copy the program to my wife's HP laptop (same age but a simpler model), then the display is not the same!
I have placed two TStaticText controls on the lower left corner, one holds the current xy size of the form in pixels and the other holds the letter X. This latter TStaticText simulates a close button.
The lower right corner of the form has a bit more space to allow for grabbing the form to drag it into position.
The attached image shows the way the form is displayed on the two laptops, on my wife's there is no sign of the two TStaticText containers, which are clearly visible when the exact same program is run on my own laptop.
What in the world can cause this to happen?
Below is my code for creating the hole in the form as suggested earlier in this thread.
I have tried to figure out the reason for the different behaviour but failed. Changing the color of the form does not help. It seems like the TStaticText controls are hidden on the other laptop....
procedure TfrmMain.FormCreate(Sender : TObject);
begin
PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Self.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));
Self.Color := clFuchsia; // clAqua;
//Defaults:
InitialWidth := 860;
InitialHeight := 480;
InitialPosx := (Screen.Width - InitialWidth) div 2;
InitialPosy := (Screen.Height - InitialHeight) div 2;
{$IFNDEF MAINAPP}
InitialWidth := ReadIniInt('configure', 'InitialWidth', InitialWidth);
InitialHeight := ReadIniInt('configure', 'InitialHeight', InitialHeight);
InitialPosx := ReadIniInt('configure', 'InitialPosx', InitialPosx);
InitialPosy := ReadIniInt('configure', 'InitialPosy', InitialPosy);
{$ENDIF}
Self.Width := InitialWidth;
Self.Height := InitialHeight;
end;
procedure TfrmMain.CreateTransparentForm;
var
HoleRegion, FormRegion: HRGN;
Polygon: array of TPoint;
begin
if FIsBusy then
Exit;
FIsBusy := True;
FormRegion := CreateRectRgn(0, 0, Self.Width, Self.Height);
try
SetLength(Polygon, 6);
Polygon[0].X := 2; Polygon[0].Y := 2;
Polygon[1].X := Self.Width - 2; Polygon[1].Y := 2;
Polygon[2].X := Self.Width - 2; Polygon[2].Y := Self.Height - stxSize.Height;
Polygon[3].X := Self.Width - stxSize.Width - stxClose.Width - 25; Polygon[3].Y := Self.Height - stxSize.Height;
Polygon[4].X := Self.Width - stxSize.Width - stxClose.Width - 25; Polygon[4].Y := Self.Height - 2;
Polygon[5].X := 2; Polygon[5].Y := Self.Height - 2;
Polygon[6].X := 2; Polygon[6].Y := 2;
HoleRegion := CreatePolygonRgn(@Polygon[0], Length(Polygon), WINDING);
try
CombineRgn(FormRegion, FormRegion, HoleRegion, RGN_DIFF);
finally
DeleteObject(HoleRegion);
end;
SetWindowRgn(Self.Handle, FormRegion, True);
finally
DeleteObject(FormRegion);
FIsBusy := False;
end;
end;
procedure TfrmMain.FormResize(Sender : TObject);
begin
frmMain.CreateTransparentForm;
stxSize.Caption := IntToStr(Self.Width) + 'x' + IntToStr(Self.Height);
end;