Results 1 to 5 of 5

Thread: [RESOLVED] Detect taskbar height

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] Detect taskbar height

    I have routine that checks users resolution and adjust the form height using this:

    Code:
    Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Private Const SM_CXSCREEN = 0
    Private Const SM_CYMAXIMIZED = 62
    
    Public Const SM_CXFULLSCREEN = 16
    Public Const SM_CYFULLSCREEN = 17
    
    
    Public Sub MaxFormHeight(frm As Form)
    Dim lgScreenY As Long
    
      lgScreenY = GetSystemMetrics(SM_CYMAXIMIZED)
      frm.Height = Screen.Height - lgScreenY  
    End Sub
    
    
    
    Detect taskbar height
    
    I have routine that checks users resolution and adjust the form height using this:
    Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Private Const SM_CXSCREEN = 0
    Private Const SM_CYMAXIMIZED = 62
    
    Public Const SM_CXFULLSCREEN = 16
    Public Const SM_CYFULLSCREEN = 17
    
    
    Public Sub MaxFormHeight(frm As Form)
    Dim lgScreenY As Long
     lgScreenY = GetSystemMetrics(SM_CYMAXIMIZED)
      frm.Height = Screen.Height - lgScreenY  
    End Sub
    I am not concerned with the forms width only the height. This works fine until a user increases the taskbar height. Then when the form loads it does not allow for the increased height of the taskbar. The taskbar then covers the bottom portion of the form. How can i correct this ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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

    Re: Detect taskbar height

    The taskbar can also be along the left or right side of the screen, which may mess you up with the approach from the OP.

    Better to use the system's desktop dimensions. Send four variables to the following function and they'll get stuffed (by reference) with the usable desktop's dimensions:
    vb Code:
    1. ' Get desktop coords excluding any taskbars
    2. ' Thanks to bushmobile from vbforums.com
    3. Public Sub GetDesktop(plngLeft As Long, plngTop As Long, plngWidth As Long, plngHeight As Long)
    4.     Const SPI_GETWORKAREA As Long = 48
    5.     Dim rc As rect
    6.    
    7.     Call SystemParametersInfo(SPI_GETWORKAREA, 0&, rc, 0&)
    8.     With rc
    9.         plngLeft = .Left * Screen.TwipsPerPixelX
    10.         plngTop = .Top * Screen.TwipsPerPixelY
    11.         plngWidth = (.Right - .Left) * Screen.TwipsPerPixelX
    12.         plngHeight = (.Bottom - .Top) * Screen.TwipsPerPixelY
    13.     End With
    14. End Sub

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Detect taskbar height

    Quote Originally Posted by Ellis Dee View Post
    The taskbar can also be along the left or right side of the screen, which may mess you up with the approach from the OP.

    Better to use the system's desktop dimensions. Send four variables to the following function and they'll get stuffed (by reference) with the usable desktop's dimensions:
    vb Code:
    1. ' Get desktop coords excluding any taskbars
    2. ' Thanks to bushmobile from vbforums.com
    3. Public Sub GetDesktop(plngLeft As Long, plngTop As Long, plngWidth As Long, plngHeight As Long)
    4.     Const SPI_GETWORKAREA As Long = 48
    5.     Dim rc As rect
    6.    
    7.     Call SystemParametersInfo(SPI_GETWORKAREA, 0&, rc, 0&)
    8.     With rc
    9.         plngLeft = .Left * Screen.TwipsPerPixelX
    10.         plngTop = .Top * Screen.TwipsPerPixelY
    11.         plngWidth = (.Right - .Left) * Screen.TwipsPerPixelX
    12.         plngHeight = (.Bottom - .Top) * Screen.TwipsPerPixelY
    13.     End With
    14. End Sub
    Thanks, That works
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    362

    Re: [RESOLVED] Detect taskbar height

    I placed this code into module:
    Code:
    Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Private Const SM_CXSCREEN = 0
    Private Const SM_CYMAXIMIZED = 62
    
    Public Const SM_CXFULLSCREEN = 16
    Public Const SM_CYFULLSCREEN = 17
    Public Sub MaxFormHeight(frm As Form)
    Dim lgScreenY As Long
     lgScreenY = GetSystemMetrics(SM_CYMAXIMIZED)
      frm.Height = Screen.Height - lgScreenY
    End Sub
    In the form_load I placed
    Code:
    Private Sub Form_Load()
        MaxFormHeight (Me)
    End Sub
    I get Type Mismatch Error
    Last edited by chapran; Feb 20th, 2015 at 08:00 AM.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Detect taskbar height

    Remove the parentheses from ME
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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