Changeset 622 for trunk/Packages


Ignore:
Timestamp:
Sep 15, 2024, 10:04:45 PM (2 months ago)
Author:
chronos
Message:
  • Modified: Show windows by default on primary screen if multiple monitors present.
Location:
trunk/Packages
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CevoComponents/BaseWin.pas

    r620 r622  
    103103  TitleHeight := WideFrame;
    104104  ModalFrameIndent := 45;
    105   UserLeft := (Screen.Width - Width) div 2;
    106   UserTop := (Screen.Height - Height) div 2;
     105  UserLeft := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2;
     106  UserTop := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) div 2;
    107107end;
    108108
  • trunk/Packages/CevoComponents/DrawDlg.pas

    r617 r622  
    3535    destructor Destroy; override;
    3636    procedure SmartInvalidate; virtual;
     37    procedure CenterToScreen; overload;
     38    procedure CenterToScreen(AWidth, AHeight: Integer); overload;
    3739  end;
    3840
     
    210212end;
    211213
     214procedure TDrawDlg.CenterToScreen;
     215begin
     216  BoundsRect := Bounds(
     217    Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2,
     218    Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - Height) div 2,
     219    Width, Height);
     220end;
     221
     222procedure TDrawDlg.CenterToScreen(AWidth, AHeight: Integer);
     223begin
     224  BoundsRect := Bounds(
     225    Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - AWidth) div 2,
     226    Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - AHeight) div 2,
     227    Width, Height);
     228end;
     229
    212230{ TBaseMessgDlg }
    213231
    214232procedure TBaseMessgDlg.FormCreate(Sender: TObject);
    215233begin
    216   Left := (Screen.Width - Width) div 2;
     234  Left := Screen.PrimaryMonitor.Left + (Screen.PrimaryMonitor.Width - Width) div 2;
    217235  Canvas.Font.Assign(UniFont[ftNormal]);
    218236  Canvas.Brush.Style := TBrushStyle.bsClear;
    219237  MessgText := '';
    220238  TopSpace := 0;
    221   TitleHeight := Screen.Height;
     239  TitleHeight := Screen.PrimaryMonitor.Height;
    222240  if csDesigning in ComponentState then Exit;
    223241  InitButtons;
     
    287305var
    288306  I: Integer;
    289 begin
    290   Height := 72 + Border + TopSpace + Lines * MessageLineSpacing;
    291   Top := (Screen.Height - Height) div 2;
    292   for i := 0 to ControlCount - 1 do
    293     Controls[i].Top := Height - (34 + Border);
     307  NewHeight: Integer;
     308  NewTop: Integer;
     309begin
     310  NewHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing;
     311  NewTop := Screen.PrimaryMonitor.Top + (Screen.PrimaryMonitor.Height - NewHeight) div 2;
     312  BoundsRect := Bounds(Left, NewTop, Width, NewHeight);
     313  for I := 0 to ControlCount - 1 do
     314    Controls[I].Top := NewHeight - (34 + Border);
    294315end;
    295316
  • trunk/Packages/DpiControls/Dpi.Forms.pas

    r500 r622  
    202202  end;
    203203
     204  { TMonitor }
     205
     206  TMonitor = class
     207  private
     208    function GetLeft: Integer;
     209    function GetHeight: Integer;
     210    function GetTop: Integer;
     211    function GetWidth: Integer;
     212    function GetBoundsRect: TRect;
     213  public
     214    NativeMonitor: Forms.TMonitor;
     215    property Left: Integer read GetLeft;
     216    property Height: Integer read GetHeight;
     217    property Top: Integer read GetTop;
     218    property Width: Integer read GetWidth;
     219    property BoundsRect: TRect read GetBoundsRect;
     220  end;
     221
    204222  { TScreen }
    205223
     
    209227    FActiveForm: TForm;
    210228    FPrevActiveForms: TForms;
     229    FPrimaryMonitor: TMonitor;
    211230    FForms: TForms;
    212231    procedure AddForm(AForm: TForm);
     
    215234    function GetDesktopTop: Integer;
    216235    function GetDesktopWidth: Integer;
     236    function GetPrimaryMonitor: TMonitor;
    217237    procedure RemoveForm(AForm: TForm);
    218238    function GetActiveForm: TForm;
     
    248268    property DesktopWidth: Integer read GetDesktopWidth;
    249269    property DesktopHeight: Integer read GetDesktopHeight;
     270    property PrimaryMonitor: TMonitor read GetPrimaryMonitor;
    250271  end;
    251272
     
    477498begin
    478499  Result := Application.MessageBox(Text, Caption, Flags);
     500end;
     501
     502{ TMonitor }
     503
     504function TMonitor.GetLeft: Integer;
     505begin
     506  Result := ScaleFromNative(NativeMonitor.Left);
     507end;
     508
     509function TMonitor.GetHeight: Integer;
     510begin
     511  Result := ScaleFromNative(NativeMonitor.Height);
     512end;
     513
     514function TMonitor.GetTop: Integer;
     515begin
     516  Result := ScaleFromNative(NativeMonitor.Top);
     517end;
     518
     519function TMonitor.GetWidth: Integer;
     520begin
     521  Result := ScaleFromNative(NativeMonitor.Width);
     522end;
     523
     524function TMonitor.GetBoundsRect: TRect;
     525begin
     526  Result := ScaleRectFromNative(NativeMonitor.BoundsRect);
    479527end;
    480528
     
    944992end;
    945993
     994function TScreen.GetPrimaryMonitor: TMonitor;
     995begin
     996  if not Assigned(FPrimaryMonitor) then begin
     997    FPrimaryMonitor := TMonitor.Create;
     998    FPrimaryMonitor.NativeMonitor := LCLScreen.PrimaryMonitor;
     999  end;
     1000  Result := FPrimaryMonitor;
     1001end;
     1002
    9461003procedure TScreen.RemoveForm(AForm: TForm);
    9471004begin
     
    10061063  FreeAndNil(FForms);
    10071064  FreeAndNil(FPrevActiveForms);
     1065  if Assigned(FPrimaryMonitor) then
     1066    FreeAndNil(FPrimaryMonitor);
    10081067  inherited;
    10091068end;
Note: See TracChangeset for help on using the changeset viewer.