1,105,423 Community Members

Getting the height of the taskbar in VB

Member Avatar
Yomet
Junior Poster
139 posts since Nov 2005
Reputation Points: 1 [?]
Q&As Helped to Solve: 10 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
yello
Light Poster
30 posts since Nov 2006
Reputation Points: 3 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
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
Member Avatar
hopalongcassidy
Junior Poster
148 posts since Oct 2007
Reputation Points: 35 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
Yomet
Junior Poster
139 posts since Nov 2005
Reputation Points: 1 [?]
Q&As Helped to Solve: 10 [?]
Skill Endorsements: 0 [?]
 
0
 

Yello,

Thanks a million, it works flawlessly.

Yomet

Member Avatar
yello
Light Poster
30 posts since Nov 2006
Reputation Points: 3 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Yomet, you are most welcome

Member Avatar
tzatziki
Newbie Poster
6 posts since Oct 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article