Visual Basic Screen & System Metrics
SystemParametersInfo: Determine Available Screen Real Estate
     
Posted:   Monday May 19, 1997
Updated:   Monday December 26, 2011
     
Applies to:   VB4-32, VB5, VB6
Developed with:   VB4-32, Windows 95
OS restrictions:   None
Author:   VBnet - Randy Birch
     

Related:  

SHAppBarMessage: Determine TaskBar Position
     
 Prerequisites
None.

Using SystemParametersInfo with the message SPI_GETWORKAREA will return a RECT structure (Type) containing the currently available free screen space - that is, the desktop area that is not covered by any visible taskbars.  With this information, an application can position itself full-screen without interfering in the user's choice of taskbar options.

The values returned in the RECT structure are in screen units (pixels), so conversion to Twips is required in order to position the application window correctly.

 BAS Module Code
None.

 Form Code
To a form add a command button (Command1) and a textbox (Text1). Set the textbox to multiline, and the scrollbars to 2 - Vertical.

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Private Const SPI_GETWORKAREA& = 48

Private Declare Function SystemParametersInfo Lib "user32" _
   Alias "SystemParametersInfoA" _
  (ByVal uAction As Long, _
   ByVal uParam As Long, _
   lpvParam As Any, _
   ByVal fuWinIni As Long) As Long
      
Private Sub Command1_Click()

  Dim rc As RECT
  Dim msg As String
  
  Call SystemParametersInfo(SPI_GETWORKAREA, 0&, rc, 0&)
  
  msg = "The coordinates indicating area not used by taskbars is:" & vbCrLf
  msg = msg & "  left - " & rc.Left & vbCrLf
  msg = msg & "  top  - " & rc.Top & vbCrLf
  msg = msg & "  rght - " & rc.Right & vbCrLf
  msg = msg & "  bttm - " & rc.Bottom & vbCrLf & vbCrLf

  msg = msg & "To position full-screen, the syntax is:" & vbCrLf
  msg = msg & "  Me.Move rc.Left * Screen.TwipsPerPixelX, _" & vbCrLf
  msg = msg & "                  rc.Top * Screen.TwipsPerPixelY, _" & vbCrLf
  msg = msg & "                  rc.Right * Screen.TwipsPerPixelX, _" & vbCrLf
  msg = msg & "                  rc.Bottom * Screen.TwipsPerPixelY" & vbCrLf & vbCrLf

  Text1.Text = msg

End Sub
 Comments
Armed with this information, the Move syntax to position the application window full-screen is:

      Me.Move rc.Left * Screen.TwipsPerPixelX, _
                     rc.Top * Screen.TwipsPerPixelY, _
                     rc.Right * Screen.TwipsPerPixelX, _
                     rc.Bottom * Screen.TwipsPerPixelY

Note that the first two members, rc.Left and rc.Top, are also multiplied by the Screen.TwipsPerPixel values. This assures that, while most users position the taskbar on the bottom, those that position to the top will not have the application window placed over it.

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter