When maximizing a Form via WindowState:=wsMaximized, the title bar looks like this:
When setting the form to WindowState:=wsNormal and setting the form size manualy to a fullscreen state, the content of the frame is identical but the title bar is slightly moved.
The wsNormal
form Rect on a 800*600 screen to simulate a wsMaxed
form is TRect(-8,-8,808,608).
(See this question why the difference of the size is necessary)
My Question: How can i fix the moved title bar content for the wsNormal window, so it would look correct like the following mock up?
Simple example form with one button, which reproduces both form states.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
FState: Integer;
public
{ Public-Deklarationen }
procedure WMGetMinMaxInfo(var Message: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
LBRect: TRect;
begin
LBRect := Screen.Monitors[0].BoundsRect;
case FState of
0:
begin
WindowState := wsMaximized;
end;
1:
begin
WindowState := wsNormal;
LBRect := Screen.Monitors[0].WorkareaRect;
LBRect.Inflate(8,8); //offset 8 for a form with bsSizeable
BoundsRect := LBRect;
end;
end;
Inc(FState);
FState := FState mod 2;
end;
procedure TForm1.WMGetMinMaxInfo(var Message: TWMGetMinMaxInfo);
begin
//slightly smaller MaxTrackSize would prevent the wsNormal form the fully cover the screen on the right side
Message.MinMaxInfo.ptMaxTrackSize := Message.MinMaxInfo.ptMaxSize;
end;
end.
Edit1:
To clarify why this might be usefull: We have a multi-monitor set up with identical resolution screens and want to span the form over this verly large "virtual screen. The desktop can not be unified to one large screen via e.g. AMDs Virtual Destkop settings.
The problem occurs because the title bar rect of a maximized Form has a slightly smaller height than a non-maximized form title bar.
Also, there is a need for the negative positions and enlarged size, caused by the (backwards compatible) way windows handles the border calculations and positioning. The actual offset/enlargement comes from the chosen borderstyle.