What is the best way to make a Delphi Application completely full screen?

前端 未结 9 1562
一生所求
一生所求 2020-12-07 23:07

What is the best way to make a delphi application (delphi 2007 for win32 here) go completely full screen, removing the application border and covering windows task bar ?

相关标签:
9条回答
  • 2020-12-07 23:45

    Try:

    Align = alClient    
    FormStyle = fsStayOnTop
    

    This always align to the primary monitor;

    0 讨论(0)
  • 2020-12-07 23:46

    Put to the form onShow event such code:

      WindowState:=wsMaximized;
    

    And to the OnCanResize this:

      if (newwidth<width) and (newheight<height) then
        Resize:=false;
    
    0 讨论(0)
  • 2020-12-07 23:51

    You need to make sure Form position is poDefaultPosOnly.

    Form1.Position := poDefaultPosOnly;
    Form1.FormStyle := fsStayOnTop;
    Form1.BorderStyle := bsNone;
    Form1.Left := 0;
    Form1.Top := 0;
    Form1.Width := Screen.Width;
    Form1.Height := Screen.Height;
    

    Tested and works on Win7 x64.

    0 讨论(0)
  • 2020-12-07 23:55

    A Google search turned up the following, additional methods:

    (though I think I'd try Roddy's method first)

    Manually fill the screen (from: About Delphi)

    procedure TSomeForm.FormShow(Sender: TObject) ;
    var
       r : TRect;
    begin
       Borderstyle := bsNone;
       SystemParametersInfo
          (SPI_GETWORKAREA, 0, @r,0) ;
       SetBounds
         (r.Left, r.Top, r.Right-r.Left, r.Bottom-r.Top) ;
    end;
    

    Variation on a theme by Roddy

    FormStyle := fsStayOnTop;
    BorderStyle := bsNone;
    Left := 0;
    Top := 0;
    Width := Screen.Width;
    Height := Screen.Height;
    

    The WinAPI way (by Peter Below from TeamB)

    private  // in form declaration
        Procedure WMGetMinMaxInfo(Var msg: TWMGetMinMaxInfo);
          message WM_GETMINMAXINFO;
    
    Procedure TForm1.WMGetMinMaxInfo(Var msg: TWMGetMinMaxInfo);
      Begin
        inherited;
        With msg.MinMaxInfo^.ptMaxTrackSize Do Begin
          X := GetDeviceCaps( Canvas.handle, HORZRES ) + (Width - ClientWidth);
          Y := GetDeviceCaps( Canvas.handle, VERTRES ) + (Height - ClientHeight
    );
        End;
      End;
    
    procedure TForm1.Button2Click(Sender: TObject);
    Const
      Rect: TRect = (Left:0; Top:0; Right:0; Bottom:0);
      FullScreen: Boolean = False;
    begin
      FullScreen := not FullScreen;  
      If FullScreen Then Begin
        Rect := BoundsRect;
        SetBounds(
          Left - ClientOrigin.X,
          Top - ClientOrigin.Y,
          GetDeviceCaps( Canvas.handle, HORZRES ) + (Width - ClientWidth),
          GetDeviceCaps( Canvas.handle, VERTRES ) + (Height - ClientHeight ));
      //  Label2.caption := IntToStr(GetDeviceCaps( Canvas.handle, VERTRES ));
      End
      Else
        BoundsRect := Rect;
    end; 
    
    0 讨论(0)
  • 2020-12-07 23:58

    Hm. Looking at the responses I seem to remember dealing with this about 8 years ago when I coded a game. To make debugging easier, I used the device-context of a normal, Delphi form as the source for a fullscreen display.

    The point being, that DirectX is capable of running any device context fullscreen - including the one allocated by your form.

    So to give an app "true" fullscreen capabilities, track down a DirectX library for Delphi and it will probably contain what you need out of the box.

    0 讨论(0)
  • 2020-12-08 00:01

    Maximize the form and hide the title bar. The maximize line is done from memory, but I'm pretty sure WindowState is the property you want.

    There's also this article, but that seems too complicated to me.

    procedure TForm1.FormCreate(Sender: TObject) ;
    begin
       //maximize the window
       WindowState := wsMaximized;
       //hide the title bar
       SetWindowLong(Handle,GWL_STYLE,GetWindowLong(Handle,GWL_STYLE) and not WS_CAPTION);
       ClientHeight := Height;
    end;
    

    Edit: Here's a complete example, with "full screen" and "restore" options. I've broken out the different parts into little procedures for maximum clarity, so this could be greatly compressed into just a few lines.

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        btnGoFullScreen: TButton;
        btnNotFullScreen: TButton;
        btnShowTitleBar: TButton;
        btnHideTitleBar: TButton;
        btnQuit: TButton;
        procedure btnGoFullScreenClick(Sender: TObject);
        procedure btnShowTitleBarClick(Sender: TObject);
        procedure btnHideTitleBarClick(Sender: TObject);
        procedure btnNotFullScreenClick(Sender: TObject);
        procedure btnQuitClick(Sender: TObject);
      private
        SavedLeft : integer;
        SavedTop : integer;
        SavedWidth : integer;
        SavedHeight : integer;
        SavedWindowState : TWindowState;
        procedure FullScreen;
        procedure NotFullScreen;
        procedure SavePosition;
        procedure HideTitleBar;
        procedure ShowTitleBar;
        procedure RestorePosition;
        procedure MaximizeWindow;
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.btnQuitClick(Sender: TObject);
    begin
      Application.Terminate;
    end;
    
    procedure TForm1.btnGoFullScreenClick(Sender: TObject);
    begin
      FullScreen;
    end;
    
    procedure TForm1.btnNotFullScreenClick(Sender: TObject);
    begin
      NotFullScreen;
    end;
    
    procedure TForm1.btnShowTitleBarClick(Sender: TObject);
    begin
      ShowTitleBar;
    end;
    
    procedure TForm1.btnHideTitleBarClick(Sender: TObject);
    begin
      HideTitleBar;
    end;
    
    procedure TForm1.FullScreen;
    begin
      SavePosition;
      HideTitleBar;
      MaximizeWindow;
    end;
    
    procedure TForm1.HideTitleBar;
    begin
      SetWindowLong(Handle,GWL_STYLE,GetWindowLong(Handle,GWL_STYLE) and not WS_CAPTION);
      ClientHeight := Height;
    end;
    
    procedure TForm1.MaximizeWindow;
    begin
      WindowState := wsMaximized;
    end;
    
    procedure TForm1.NotFullScreen;
    begin
      RestorePosition;
      ShowTitleBar;
    end;
    
    procedure TForm1.RestorePosition;
    begin
      //this proc uses what we saved in "SavePosition"
      WindowState := SavedWindowState;
      Top := SavedTop;
      Left := SavedLeft;
      Width := SavedWidth;
      Height := SavedHeight;
    end;
    
    procedure TForm1.SavePosition;
    begin
      SavedLeft := Left;
      SavedHeight := Height;
      SavedTop := Top;
      SavedWidth := Width;
      SavedWindowState := WindowState;
    end;
    
    procedure TForm1.ShowTitleBar;
    begin
      SetWindowLong(Handle,gwl_Style,GetWindowLong(Handle,gwl_Style) or ws_Caption or ws_border);
      Height := Height + GetSystemMetrics(SM_CYCAPTION);
      Refresh;
    end;
    
    end.
    
    0 讨论(0)
提交回复
热议问题