|
-
Jun 15th, 2008, 04:33 AM
#1
Thread Starter
Lively Member
-
Jun 15th, 2008, 04:54 AM
#2
Re: Detecting the height of the start bar?
-
Jun 15th, 2008, 04:55 AM
#3
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.
-
Jun 15th, 2008, 04:59 AM
#4
Re: Detecting the height of the start bar?
(reading your post again)
Merri's code will work best it this case.
-
Jun 15th, 2008, 06:33 AM
#5
Re: Detecting the height of the start bar?
 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.
Last edited by Ellis Dee; Jun 15th, 2008 at 06:38 AM.
-
Jun 17th, 2008, 07:07 PM
#6
Thread Starter
Lively Member
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
-
Jun 18th, 2008, 06:30 AM
#7
Thread Starter
Lively Member
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?
-
Jun 18th, 2008, 07:05 AM
#8
Re: [RESOLVED] Detecting the height of the start bar?
MsgBox "Height: " & (udtRC.Bottom - udtRC.Top) * Screen.TwipsPerPixelY & " twips"
-
Jun 18th, 2008, 09:03 AM
#9
Thread Starter
Lively Member
Re: [RESOLVED] Detecting the height of the start bar?
Ellis Dee, you are awesome! Thank you so much! Works beautifully
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|