Results 1 to 9 of 9

Thread: [RESOLVED] Detecting the height of the start bar?

  1. #1

    Thread Starter
    Lively Member feneck's Avatar
    Join Date
    Mar 2007
    Location
    Australia, Queensland, Gympie
    Posts
    85

    Resolved [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 )
    Last edited by feneck; Jun 15th, 2008 at 04:38 AM.

    REMEMBER TO RATE

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Detecting the height of the start bar?

    I guess you mean 'Task Bar'.
    You'll need to determine the desktop area:
    http://www.vb-helper.com/howto_center_form.html
    http://www.vb-helper.com/howto_net_p...wer_right.html

    If you need to check AutoHide:
    http://www.vbforums.com/showthread.php?t=471594
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Detecting the height of the start bar?

    (reading your post again)
    Merri's code will work best it this case.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  5. #5
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    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:
    1. Public Sub Sample()
    2.     Dim typBar As APPBARDATA
    3.     Dim lngState As Long
    4.    
    5.     ' Query the taskbar state
    6.     lngState = SHAppBarMessage(ABM_GETSTATE, typBar)
    7.     If lngState = ABS_ALWAYSONTOP Then ' AlwaysOnTop and doesn't AutoHide
    8.         lngState = SHAppBarMessage(ABM_GETTASKBARPOS, typBar)
    9.         Debug.Print "Taskbar Left: " & typBar.rc.Left
    10.         Debug.Print "Taskbar Top: " & typBar.rc.Top
    11.         Debug.Print "Taskbar Width: " & typBar.rc.Width
    12.         Debug.Print "Taskbar Height: " & typBar.rc.Height
    13.     Else
    14.         Debug.Print "Taskbar AutoHides or is not AlwaysOnTop"
    15.     End If
    16. 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.

  6. #6

    Thread Starter
    Lively Member feneck's Avatar
    Join Date
    Mar 2007
    Location
    Australia, Queensland, Gympie
    Posts
    85

    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

    REMEMBER TO RATE

  7. #7

    Thread Starter
    Lively Member feneck's Avatar
    Join Date
    Mar 2007
    Location
    Australia, Queensland, Gympie
    Posts
    85

    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?

    REMEMBER TO RATE

  8. #8
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: [RESOLVED] Detecting the height of the start bar?

    MsgBox "Height: " & (udtRC.Bottom - udtRC.Top) * Screen.TwipsPerPixelY & " twips"

  9. #9

    Thread Starter
    Lively Member feneck's Avatar
    Join Date
    Mar 2007
    Location
    Australia, Queensland, Gympie
    Posts
    85

    Re: [RESOLVED] Detecting the height of the start bar?

    Ellis Dee, you are awesome! Thank you so much! Works beautifully

    REMEMBER TO RATE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width