Sign in Join
Wiki copytemporary

Application full screen mode: what changed

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

Title: Application full screen mode

OldNewLine
1+## Introduction
2+
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.
4+
5+## Standard way
6+
7+You 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:
8+
9+``` pascal
10+procedure TForm1.FormShow(Sender: TObject);
11+begin
12+ WindowState := wsFullScreen;
13+end;
14+```
15+
16+## Universal way to use full-screen
17+
18+Universal 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:
19+
20+``` pascal
21+uses
22+ ..., LCLIntf, LCLType;
23+
24+procedure TfmMain.SetFullScreen_Universal(AValue: boolean);
25+begin
26+ if AValue then
27+ ShowWindow(Handle, SW_SHOWFULLSCREEN)
28+ else
29+ ShowWindow(Handle, SW_SHOWNORMAL);
30+ //maybe consider here previous maximized state?
31+end;
32+```
33+
34+## Win32 way to use full-screen
35+
36+Universal way, above, works for Win32, but window border still stays, so better code which works:
37+
38+``` pascal
39+procedure TfmMain.SetFullScreen_Win32(AValue: boolean);
40+begin
41+ if AValue then
42+ begin
43+ FOrigWndState:= WindowState;
44+ FOrigBounds:= BoundsRect;
45+
46+ BorderStyle:= bsNone;
47+ BoundsRect:= Monitor.BoundsRect;
48+ end
49+ else
50+ begin
51+ WindowState:= FOrigWndState;
52+ BoundsRect:= FOrigBounds;
53+ BorderStyle:= bsSizeable;
54+ BoundsRect:= FOrigBounds; //again
55+ end;
56+end;
57+```
58+
59+### Win32 example program
60+
61+This is example for Win32 only, since it don't use native full-screen mode on Linux/MacOS, it is here from old times.
62+
63+To be able to switch to full screen mode you will need:
64+
65+- Remember previous form state as position and size and window state
66+- Be able to determine screen size
67+- Capture some key and perform operation
68+
69+Best 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.
70+
71+``` pascal
72+unit Unit1;
73+
74+{$mode objfpc}{$H+}
75+
76+interface
77+
78+uses
79+ Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
80+ Menus;
81+
82+type
83+ TForm1 = class(TForm)
84+ procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
85+ private
86+ public
87+ OriginalBounds: TRect;
88+ OriginalWindowState: TWindowState;
89+ ScreenBounds: TRect;
90+ procedure SwitchFullScreen;
91+ end;
92+
93+var
94+ Form1: TForm1;
95+
96+implementation
97+
98+{$R *.lfm}
99+
100+{ TForm1 }
101+
102+procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
103+begin
104+ if Key = VK_F11 then
105+ begin
106+ SwitchFullScreen;
107+ Key := 0;
108+ end;
109+end;
110+
111+procedure TForm1.SwitchFullScreen;
112+begin
113+ if BorderStyle <> bsNone then begin
114+ // To full screen
115+ OriginalWindowState := WindowState;
116+ OriginalBounds := BoundsRect;
117+
118+ BorderStyle := bsNone;
119+ BoundsRect := Screen.MonitorFromWindow(Handle).BoundsRect;
120+ end else begin
121+ // From full screen
122+ BorderStyle := bsSizeable;
123+ if OriginalWindowState = wsMaximized then
124+ WindowState := wsMaximized
125+ else
126+ BoundsRect := OriginalBounds;
127+ end;
128+end;
129+
130+end.
131+```
132+
133+### Win32: get task bar size
134+
135+If you want to have task bar visible you have to adjust size according task bar position and size. For Windows:
136+
137+``` pascal
138+function GetTaskBarSize: TRect;
139+begin
140+ SystemParametersInfo(SPI_GETWORKAREA, 0, @Result, 0);
141+end;
142+```
143+
144+## GTK way to use full-screen
145+
146+This is low-level code for GTK2, it is used already by LCL in "universal way" above.
147+
148+To switch form to full screen dimensions:
149+
150+``` pascal
151+gdk_window_fullscreen(PGtkWidget(Handle)^.window);
152+```
153+
154+To roll back to normal mode:
155+
156+``` pascal
157+gdk_window_unfullscreen(PGtkWidget(Handle)^.window);
158+```
159+
160+This is GTK2 only. You must add to uses section such modules as gtk2, gdk2, glib2. You can do it by the directive
161+
162+``` pascal
163+{$IFDEF LCLGTK2}, gtk2, gdk2, glib2{$ENDIF}
164+```
165+
166+## Changing screen resolution
167+
168+There is no OS independent way to switch screen resolution now.
169+
170+For 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)
171+
172+## See also
173+
174+- [[WinCE Programming Tips|WinCE Programming Tips - Making a Fullscreen Application]]
175+
176+## External links
177+
178+- [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)
179+- [Very simple way to make your form Fullscreen & Restore (LazPlanet)](http://lazplanet.blogspot.com/2014/02/make-your-form-fullscreen.html)
180+
181+---
182+*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).*
183+Category: Lazarus
184+Category: Tutorials

Back to history