Sign in Join
Wiki copytemporary

Application full screen mode: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Introduction
22
3-Some applications like some web browsers allow show in full screen mode using key <span class="kbd">F11</span>. In full screen mode window hasn't border and uses entire screen space.
3+Some applications like some web browsers allow show in full screen mode using key `F11`. In full screen mode window hasn't border and uses entire screen space.
44
55## Standard way
66
77You can switch form to full screen mode simply by assigning **wsFullScreen** value to **TForm.WindowState** property. You can do that directly in design time in Object Inspector window or in runtime:
88
99``` pascal
1010procedure TForm1.FormShow(Sender: TObject);
1111begin
1212 WindowState := wsFullScreen;
1313end;
1414```
1515
1616## Universal way to use full-screen
1717
1818Universal way exists, using LCL, you need to call ShowWindow() with SW_SHOWFULLSCREEN. This ShowWindow call is handled inside widgetset, using low-level API (for example, OS X Carbon API, or GTK2 API). Example:
1919
2020``` pascal
2121uses
2222 ..., LCLIntf, LCLType;
2323
2424procedure TfmMain.SetFullScreen_Universal(AValue: boolean);
2525begin
2626 if AValue then
2727 ShowWindow(Handle, SW_SHOWFULLSCREEN)
2828 else
2929 ShowWindow(Handle, SW_SHOWNORMAL);
3030 //maybe consider here previous maximized state?
3131end;
3232```
3333
3434## Win32 way to use full-screen
3535
3636Universal way, above, works for Win32, but window border still stays, so better code which works:
3737
3838``` pascal
3939procedure TfmMain.SetFullScreen_Win32(AValue: boolean);
4040begin
4141 if AValue then
4242 begin
4343 FOrigWndState:= WindowState;
4444 FOrigBounds:= BoundsRect;
4545
4646 BorderStyle:= bsNone;
4747 BoundsRect:= Monitor.BoundsRect;
4848 end
4949 else
5050 begin
5151 WindowState:= FOrigWndState;
5252 BoundsRect:= FOrigBounds;
5353 BorderStyle:= bsSizeable;
5454 BoundsRect:= FOrigBounds; //again
5555 end;
5656end;
5757```
5858
5959### Win32 example program
6060
6161This is example for Win32 only, since it don't use native full-screen mode on Linux/MacOS, it is here from old times.
6262
6363To be able to switch to full screen mode you will need:
6464
6565- Remember previous form state as position and size and window state
6666- Be able to determine screen size
6767- Capture some key and perform operation
6868
6969Best way to capture desired key is using Actions. Simply define new action in action manager and assign key shortcut. Than shortcut will work even if main form would lost focus.
7070
7171``` pascal
7272unit Unit1;
7373
7474{$mode objfpc}{$H+}
7575
7676interface
7777
7878uses
7979 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
8080 Menus;
8181
8282type
8383 TForm1 = class(TForm)
8484 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
8585 private
8686 public
8787 OriginalBounds: TRect;
8888 OriginalWindowState: TWindowState;
8989 ScreenBounds: TRect;
9090 procedure SwitchFullScreen;
9191 end;
9292
9393var
9494 Form1: TForm1;
9595
9696implementation
9797
9898{$R *.lfm}
9999
100100{ TForm1 }
101101
102102procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
103103begin
104104 if Key = VK_F11 then
105105 begin
106106 SwitchFullScreen;
107107 Key := 0;
108108 end;
109109end;
110110
111111procedure TForm1.SwitchFullScreen;
112112begin
113113 if BorderStyle <> bsNone then begin
114114 // To full screen
115115 OriginalWindowState := WindowState;
116116 OriginalBounds := BoundsRect;
117117
118118 BorderStyle := bsNone;
119119 BoundsRect := Screen.MonitorFromWindow(Handle).BoundsRect;
120120 end else begin
121121 // From full screen
122122 BorderStyle := bsSizeable;
123123 if OriginalWindowState = wsMaximized then
124124 WindowState := wsMaximized
125125 else
126126 BoundsRect := OriginalBounds;
127127 end;
128128end;
129129
130130end.
131131```
132132
133133### Win32: get task bar size
134134
135135If you want to have task bar visible you have to adjust size according task bar position and size. For Windows:
136136
137137``` pascal
138138function GetTaskBarSize: TRect;
139139begin
140140 SystemParametersInfo(SPI_GETWORKAREA, 0, @Result, 0);
141141end;
142142```
143143
144144## GTK way to use full-screen
145145
146146This is low-level code for GTK2, it is used already by LCL in "universal way" above.
147147
148148To switch form to full screen dimensions:
149149
150150``` pascal
151151gdk_window_fullscreen(PGtkWidget(Handle)^.window);
152152```
153153
154154To roll back to normal mode:
155155
156156``` pascal
157157gdk_window_unfullscreen(PGtkWidget(Handle)^.window);
158158```
159159
160160This is GTK2 only. You must add to uses section such modules as gtk2, gdk2, glib2. You can do it by the directive
161161
162162``` pascal
163163{$IFDEF LCLGTK2}, gtk2, gdk2, glib2{$ENDIF}
164164```
165165
166166## Changing screen resolution
167167
168168There is no OS independent way to switch screen resolution now.
169169
170170For Windows you can find information in article for Delphi [Get and Set Screen Resolution (Display Device Modes)](http://delphi.about.com/od/graphics/a/change_display.htm)
171171
172172## See also
173173
174174- [[WinCE Programming Tips|WinCE Programming Tips - Making a Fullscreen Application]]
175175
176176## External links
177177
178178- [Run Your Delphi Application in Full Screen - Implement "F11 - Full Screen"](http://delphi.about.com/od/delphitips2010/qt/delphi-application-full-screen-mode-f11.htm)
179179- [Very simple way to make your form Fullscreen & Restore (LazPlanet)](http://lazplanet.blogspot.com/2014/02/make-your-form-fullscreen.html)
180180
181181---
182182*From the Free Pascal wiki, page "Application full screen mode", as it stood on 2020-11-26 after a change by Chronos, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
183183Category: Lazarus
184184Category: Tutorials

Back to history