VB and VBA Users Source Code: Determining the visible portion of the desktop area (exc. the taskbar)
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Determining the visible portion of the desktop area (exc. the taskbar)
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, August 04, 2003
Hits:
1138
Category:
Windows API
Article:
The following code returns the screen dimensions excluding the width of the taskbar. Private Const SPI_GETWORKAREA = 48 Private Const ABS_ALWAYSONTOP = &H2 Private Const ABS_AUTOHIDE = &H1 Private Const ABS_BOTH = &H3 Private Const ABM_GETSTATE = &H4 Private Const ABM_GETTASKBARPOS = &H5 Private Const ABE_BOTTOM = 3 Private Const ABE_LEFT = 0 Private Const ABE_RIGHT = 2 Private Const ABE_TOP = 1 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 Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type APPBARDATA cbSize As Long hwnd As Long uCallbackMessage As Long uEdge As Long tRec As RECT lParam As Long ' message specific End Type Public Enum etbPostion etbBottom = ABE_BOTTOM etbLeft = ABE_LEFT etbRight = ABE_RIGHT etbTop = ABE_TOP etbFailed = -1 End Enum 'Purpose : Returns details on the desktop area including the position of the taskbar 'Inputs : N/A 'Outputs : Returns the postion of the taskbar and the coordinates of the desktop area 'Author : Andrew Baker 'Date : 03/09/2004 'Notes : 'Revisions : Function TaskBarPosition(Optional lDesktopLeft As Long, Optional lDesktopTop As Long, Optional lDesktopWidth As Long, Optional lDesktopHeight As Long) As etbPostion Dim tDesktopWorkArea As RECT Dim tTaskBar As APPBARDATA Const clBorder As Long = 120 On Error GoTo ErrFailed Call SystemParametersInfo(SPI_GETWORKAREA, vbNull, tDesktopWorkArea, 0) Call SHAppBarMessage(ABM_GETTASKBARPOS, tTaskBar) Select Case tTaskBar.uEdge Case ABE_BOTTOM TaskBarPosition = etbBottom lDesktopLeft = tDesktopWorkArea.Left * Screen.TwipsPerPixelX lDesktopWidth = tDesktopWorkArea.Right * Screen.TwipsPerPixelX - lDesktopLeft lDesktopTop = tDesktopWorkArea.Top * Screen.TwipsPerPixelY lDesktopHeight = tTaskBar.tRec.Top * Screen.TwipsPerPixelY Case ABE_LEFT TaskBarPosition = etbLeft lDesktopLeft = tTaskBar.tRec.Right * Screen.TwipsPerPixelX lDesktopWidth = tDesktopWorkArea.Right * Screen.TwipsPerPixelX - lDesktopLeft lDesktopTop = tDesktopWorkArea.Top * Screen.TwipsPerPixelY lDesktopHeight = tDesktopWorkArea.Bottom * Screen.TwipsPerPixelY - lDesktopTop Case ABE_RIGHT TaskBarPosition = etbRight lDesktopLeft = tDesktopWorkArea.Left * Screen.TwipsPerPixelX lDesktopWidth = tTaskBar.tRec.Left * Screen.TwipsPerPixelX - lDesktopLeft lDesktopTop = tDesktopWorkArea.Top * Screen.TwipsPerPixelY lDesktopHeight = tDesktopWorkArea.Bottom * Screen.TwipsPerPixelY - lDesktopTop Case ABE_TOP TaskBarPosition = etbTop lDesktopLeft = tDesktopWorkArea.Left * Screen.TwipsPerPixelX lDesktopWidth = tDesktopWorkArea.Right * Screen.TwipsPerPixelX - lDesktopLeft lDesktopTop = tTaskBar.tRec.Bottom * Screen.TwipsPerPixelY lDesktopHeight = tDesktopWorkArea.Bottom * Screen.TwipsPerPixelY - lDesktopTop End Select lDesktopHeight = lDesktopHeight + clBorder lDesktopWidth = lDesktopWidth + clBorder Exit Function ErrFailed: Debug.Print "Error in TaskBarPosition " & Err.Description & vbNewLine & "Note, VBA programmers should refer to http://www.vbusers.com/code/codeget.asp?ThreadID=48&PostID=1&NumReplies=0 to obtain the screen dimensions" TaskBarPosition = etbFailed End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder