[RESOLVED] Detecting the height of the start bar?
I have a program that displays an alert (toast) just above the start bar, (like MSN does). However at the moment, its programmed to go just above the start bar, if it was only small and on the bottom.
My question is, that if I drag my Start bar up one or two clicks, (or put it up top) how can I detect that?
So that my alert is just above the start bar?
Thanks guys :) (and girls :p)
Re: Detecting the height of the start bar?
Re: Detecting the height of the start bar?
Here is a bit on how to locate the actual taskbar:
Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function FindWindowW Lib "user32" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Sub Form_Load()
Dim lngWnd As Long, udtRC As RECT
lngWnd = FindWindowW(StrPtr("Shell_TrayWnd"), 0&)
If lngWnd Then
GetWindowRect lngWnd, udtRC
MsgBox "Height: " & udtRC.Bottom - udtRC.Top & " pixels"
End If
End Sub
udtRC constains the information about the location, you get the exact location. Note that there can be another window using the exact same classname (although unlikely, but possible). Use Spy++ or Winspector to further investigate window information to be sure.
Re: Detecting the height of the start bar?
(reading your post again)
Merri's code will work best it this case.
Re: Detecting the height of the start bar?
Quote:
Originally Posted by Merri
Note that there can be another window using the exact same classname (although unlikely, but possible). Use Spy++ or Winspector to further investigate window information to be sure.
There is API to get the taskbar coordinates directly, instead of indirectly using the class name:
Code:
Private Const ABM_GETSTATE = &H4
Private Const ABM_GETTASKBARPOS = &H5
Private Const ABS_ALWAYSONTOP = &H2
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 ' message specific
End Type
Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long
Sample usage:
vb Code:
Public Sub Sample()
Dim typBar As APPBARDATA
Dim lngState As Long
' Query the taskbar state
lngState = SHAppBarMessage(ABM_GETSTATE, typBar)
If lngState = ABS_ALWAYSONTOP Then ' AlwaysOnTop and doesn't AutoHide
lngState = SHAppBarMessage(ABM_GETTASKBARPOS, typBar)
Debug.Print "Taskbar Left: " & typBar.rc.Left
Debug.Print "Taskbar Top: " & typBar.rc.Top
Debug.Print "Taskbar Width: " & typBar.rc.Width
Debug.Print "Taskbar Height: " & typBar.rc.Height
Else
Debug.Print "Taskbar AutoHides or is not AlwaysOnTop"
End If
End Sub
This code is untested. It's taken from this post, which is fully tested code, so you may want to work from that if you run into problems.
Note that the linked code also shows you how to identify which edge of the screen the taskbar is docked to using typBar.uEdge.
Re: Detecting the height of the start bar?
Yes, I did mean task bar :) thank you all...
I've decided to run with Merri's code as its pretty simple and I don't need any more big lumps of code just to do something small ;)
Thanks eveyone
Re: [RESOLVED] Detecting the height of the start bar?
Hey guys, I have another problem. With Merri's code, how do I get the task bar in Twips?
Re: [RESOLVED] Detecting the height of the start bar?
MsgBox "Height: " & (udtRC.Bottom - udtRC.Top) * Screen.TwipsPerPixelY & " twips"
Re: [RESOLVED] Detecting the height of the start bar?
Ellis Dee, you are awesome! Thank you so much! Works beautifully :)