1.11M Members

Getting the height of the taskbar in VB

 
0
 

Hi,

I have a form of variable height. When the form grows in height I have code that verifies if the bottom of the form will come below the bottom of the screen and, if so, moves the form up - no problem until here.

However, some of my users have taskbars that are two lines in height and my code only deals with sinlge-line taskbars by moving the form 450 twips further up (hardcoded is bad - I know). I would like to be able to tell how high the taskbar is and then move the form accordingly.

Here's my current code:

Private Sub cmdGrowForm_Click()
   Dim NewH As Integer
   Dim TBarH As Integer
   
   TBarH = 450 'Assumes a single row taskbar
   NewH = 11010   'New form height
   If Me.Top + NewH + TBarH > Screen.Height Then
      Me.Top = Screen.Height - NewH - TBarH
   End If
   Me.Height = NewH
End Sub

So my question is - is there a way of getting the taskbar height in VB?

Could somebody try to point me in the correct direction? Even if it is only "You can't get the taskbar height in VB." as answer that's great for me.

Thanks

Yomet

 
2
 

Using the following API function you can get it!!

Private Const ABM_GETTASKBARPOS = &H5

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
    rc As RECT
    lParam As Long
End Type

Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long


Function GetTaskBarSize()
    Dim ABD As APPBARDATA

    SHAppBarMessage ABM_GETTASKBARPOS, ABD

    MsgBox "Width:" & ABD.rc.Right - ABD.rc.Left 
    MsgBox " Height:" & ABD.rc.Bottom -    ABD.rc.Top

End Sub
 
0
 

Using the following API function you can get it!!

Private Const ABM_GETTASKBARPOS = &H5

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
    rc As RECT
    lParam As Long
End Type

Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long


Function GetTaskBarSize()
    Dim ABD As APPBARDATA

    SHAppBarMessage ABM_GETTASKBARPOS, ABD

    MsgBox "Width:" & ABD.rc.Right - ABD.rc.Left 
    MsgBox " Height:" & ABD.rc.Bottom -    ABD.rc.Top

End Sub

Hey, that's pretty nifty!

Hoppy

 
0
 

Yello,

Thanks a million, it works flawlessly.

Yomet

 
0
 

Yomet, you are most welcome

 
0
 

But be warned that not all users have the taskbar in bottom or even in the screen that your program runs (ex. they may have two different screens side by side)

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article