[RESOLVED] Detect taskbar height
I have routine that checks users resolution and adjust the form height using this:
Code:
Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CXSCREEN = 0
Private Const SM_CYMAXIMIZED = 62
Public Const SM_CXFULLSCREEN = 16
Public Const SM_CYFULLSCREEN = 17
Public Sub MaxFormHeight(frm As Form)
Dim lgScreenY As Long
lgScreenY = GetSystemMetrics(SM_CYMAXIMIZED)
frm.Height = Screen.Height - lgScreenY
End Sub
Detect taskbar height
I have routine that checks users resolution and adjust the form height using this:
Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CXSCREEN = 0
Private Const SM_CYMAXIMIZED = 62
Public Const SM_CXFULLSCREEN = 16
Public Const SM_CYFULLSCREEN = 17
Public Sub MaxFormHeight(frm As Form)
Dim lgScreenY As Long
lgScreenY = GetSystemMetrics(SM_CYMAXIMIZED)
frm.Height = Screen.Height - lgScreenY
End Sub
I am not concerned with the forms width only the height. This works fine until a user increases the taskbar height. Then when the form loads it does not allow for the increased height of the taskbar. The taskbar then covers the bottom portion of the form. How can i correct this ?
Re: Detect taskbar height
The taskbar can also be along the left or right side of the screen, which may mess you up with the approach from the OP.
Better to use the system's desktop dimensions. Send four variables to the following function and they'll get stuffed (by reference) with the usable desktop's dimensions:
vb Code:
' Get desktop coords excluding any taskbars
' Thanks to bushmobile from vbforums.com
Public Sub GetDesktop(plngLeft As Long, plngTop As Long, plngWidth As Long, plngHeight As Long)
Const SPI_GETWORKAREA As Long = 48
Dim rc As rect
Call SystemParametersInfo(SPI_GETWORKAREA, 0&, rc, 0&)
With rc
plngLeft = .Left * Screen.TwipsPerPixelX
plngTop = .Top * Screen.TwipsPerPixelY
plngWidth = (.Right - .Left) * Screen.TwipsPerPixelX
plngHeight = (.Bottom - .Top) * Screen.TwipsPerPixelY
End With
End Sub
Re: Detect taskbar height
Quote:
Originally Posted by
Ellis Dee
The taskbar can also be along the left or right side of the screen, which may mess you up with the approach from the OP.
Better to use the system's desktop dimensions. Send four variables to the following function and they'll get stuffed (by reference) with the usable desktop's dimensions:
vb Code:
' Get desktop coords excluding any taskbars
' Thanks to bushmobile from vbforums.com
Public Sub GetDesktop(plngLeft As Long, plngTop As Long, plngWidth As Long, plngHeight As Long)
Const SPI_GETWORKAREA As Long = 48
Dim rc As rect
Call SystemParametersInfo(SPI_GETWORKAREA, 0&, rc, 0&)
With rc
plngLeft = .Left * Screen.TwipsPerPixelX
plngTop = .Top * Screen.TwipsPerPixelY
plngWidth = (.Right - .Left) * Screen.TwipsPerPixelX
plngHeight = (.Bottom - .Top) * Screen.TwipsPerPixelY
End With
End Sub
Thanks, That works
Re: [RESOLVED] Detect taskbar height
I placed this code into module:
Code:
Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CXSCREEN = 0
Private Const SM_CYMAXIMIZED = 62
Public Const SM_CXFULLSCREEN = 16
Public Const SM_CYFULLSCREEN = 17
Public Sub MaxFormHeight(frm As Form)
Dim lgScreenY As Long
lgScreenY = GetSystemMetrics(SM_CYMAXIMIZED)
frm.Height = Screen.Height - lgScreenY
End Sub
In the form_load I placed
Code:
Private Sub Form_Load()
MaxFormHeight (Me)
End Sub
I get Type Mismatch Error
Re: [RESOLVED] Detect taskbar height
Remove the parentheses from ME