Mega Code Archive

 
Categories / Delphi / System
 

Run Your Delphi Application in Full Screen Over the TaskBar and Other Desktop Bars

Title: Run Your Delphi Application in Full Screen - Over the TaskBar and Other Desktop Bars I guess you know you can run your browser in full screen using the F11 shortcut key. Windows Explorer also supports this feature. Running in full screen, where an application UI covers the entire screen, over the TaskBar and any Desktop/Tool bars, is handy when a user has a limited screen size (netbooks) or when you just want more to be visible by the browser or the Windows Explorer. Running your application in full screen might also be handy if your users want to be focused only on your application's window. F11 - Full Screen Full screen means "full screen" - where the UI of the application gets "on top" of the TaskBar or any other tool bars - the entire UI of your application covers Windows desktop. If you have a main menu in your application you can add a menu item "full screen" and have it assigned the "f11" key for Shortcut property. Here's how to allow switching to the full screen view and back to the "normal" view - taking into account what "normal" was before your application went to the "full screen" mode. {$J+} //writeable constants on const rect: TRect = (Left:0; Top:0; Right:0; Bottom:0); ws : TWindowState = wsNormal; {$J-} //writeable constants off var r : TRect; begin if BorderStyle bsNone then begin ws := WindowState; rect := BoundsRect; BorderStyle := bsNone; r := Screen.MonitorFromWindow(Handle).BoundsRect; SetBounds(r.Left, r.Top, r.Right-r.Left, r.Bottom-r.Top) ; end else begin BorderStyle := bsSizeable; if ws = wsMaximized then WindowState := wsMaximized else SetBounds(rect.Left, rect.Top, rect.Right-rect.Left, rect.Bottom-rect.Top) ; end; end; The code above presumes that when not in full screen mode your main window has a border - i.e. the BorderStyle is not bsNone. To get the size of the full screen the MonitorFromWindow method of the Screen global variable is used. MonitorFromWindow retrieves the Monitor (TMonitor) that has the largest area of intersection with the bounding rectangle of a specified window (your main form in this case). The BoundsRect property gives the dimensions of the monitor in pixels, where (0,0) represents the top-left corner of the monitor. The BoundsRect property does not take into account any task bars or tool bars docked on the monitor. By using the "{$J+}" and "{$J-}" the typed constants declared in the code ("rect" and "ws") are made writable - their value will not get lost when the above code is called several times. Therefore: if the BorderStyle is not bsNone we presume that we are not in full screen mode. To enter the full screen mode, we set the BorderStyle property to bsNone and also use SetBounds to set the Left, Top, Width, and Height properties of the main form all at once. We also store the current bounds of the main window along with the WindowStyle - when going back from the full screen to restore the last state of the UI of the main application window. Note: To fill the usable area (not hiding the TaskBar) you can use the SystemParametersInfo API with SPI_GETWORKAREA