CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2002
    Location
    Greece
    Posts
    42

    Windows taskbar width and height

    Hello.
    I like having the windows taskbar on the top of my screen, so sometimes new windows that appear on the top are covered by it, I can't move them and it gets annoying.

    I have made a program which can see where the taskbar is and positions itself a little better. For example, if the taskbar is on the top of the screen and the user has selected the program to appear on the top of the screen as well, then I subtract something from Form1.top.
    This works perfectly on my machine, as I subtract exactly the taskbar height, but this number may vary in other machines.
    I have Windows XP but I have selected the old windows 98 style. The normal XP taskbar is thicker. Or someone could have a bigger taskbar by dragging it...

    So the problem is, how can I know the windows taskbar's real height (when it's on top or bottom) and width (when it's left or right of the screen)?
    Visit www.greekroms.net

    Greek translations of roms

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    One way is to use the SystemParametersInfo API function with the SPI_GETWORKAREA value set to get the portion of the screen obscure by the taskbar and then from there you can compute the height of the taskbar.

    And the other way is to use the API function.. See sample code below..
    Code:
    Option Explicit
    
    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
    
    
    Private Sub Form_Load()
    Dim ABD As APPBARDATA
      
      SHAppBarMessage ABM_GETTASKBARPOS, ABD
      
      MsgBox "Width:" & ABD.rc.Right - ABD.rc.Left & " Height:" & ABD.rc.Bottom - ABD.rc.Top
      
    End Sub
    I hope that will help you.
    Busy

  3. #3
    Join Date
    Apr 2002
    Location
    Greece
    Posts
    42
    Well, it looks it's what I want :-)
    Even though I don't have time to test it now, I thank you very much.
    Visit www.greekroms.net

    Greek translations of roms

  4. #4
    Join Date
    Apr 2002
    Location
    Greece
    Posts
    42
    I tested the code, it works, but there is something weird...

    For example, if the taskbar is on the top of the screen and has its normal size, then (ABD.rc.Bottom - ABD.rc.Top) gives 32 but if I want the window to be placed right under the taskbar, I should set form1.top=450 (or something near that).

    I found that if I multiply (ABD.rc.Bottom - ABD.rc.Top) by 14.2, it does the trick, but not all the times!

    If the taskbar has been expanded more, I should multiply by a bigger number, maybe 14.9, depending on the taskbar height.

    It looks like (ABD.rc.Bottom - ABD.rc.Top) and form1.top are using diferent metric systems, I don't know what to do.

    Multiplying by 14.2 works ok if the user hasn't expanded the taskbar much, but I would really like to fix that. Can someone please explain?
    Visit www.greekroms.net

    Greek translations of roms

  5. #5
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Hi Vag,

    It is because they are in different scale. Your app measures in twips by default while the API is in pixels. So you have to scale the API..

    Me.Top = Me.ScaleY((ABD.rc.Bottom - ABD.rc.Top), vbPixels, vbTwips)


    By the way, the ABD.uEdge specifies the alignment of the taskbar in the screen

    Private Const ABE_BOTTOM = 3
    Private Const ABE_LEFT = 0
    Private Const ABE_RIGHT = 2
    Private Const ABE_TOP = 1
    Last edited by Thread1; September 12th, 2003 at 08:31 AM.
    Busy

  6. #6
    Join Date
    Apr 2002
    Location
    Greece
    Posts
    42
    I tried it, the window now appears below the taskbar.
    It leaves some space though but that's ok, I have to subtract 30.
    Perfect, thanks!
    Visit www.greekroms.net

    Greek translations of roms

  7. #7
    Join Date
    Jul 2009
    Posts
    1

    Smile Re: Windows taskbar width and height

    Thanks - exactly what I needed - I had the same issue with scaling as the OP and the replies fixed it.

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Windows taskbar width and height

    FYI You can use the sysinfo control and access the work area top, left, height and width properties to determine the screen area-the task bar. If you set all of your form properties = the proper workarea property the result will be a properly positioned form that takes full screen - the taskbar area no matter where the task bar is located or what size it may be.

    I generally use this for my mdi parent forms.

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

Featured