Programmatically resize Windows taskbar

Does anyone know how to programmatically resize the Windows taskbar?

I'm trying to "minimize" the taskbar to allow for a IE browser based application to take up the entire screen.  I've been able to hide the taskbar using the following code:
ShowWindow(FindWindow("Shell_TrayWnd", vbnullString), SW_HIDE)

But that does not allow for other windows to be resized where the toolbar used to be.  But if I manually resize the taskbar to be minimized, then I can make my app fit the entire screen.  

Any suggestions?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
If you're using IE have you considered putting it into full screen mode?  Press F11 in IE to see what I mean...
CaitlinRobertsAuthor Commented:
Yes, that's a great suggestion.  However, as part of amy requirements I need to disable the minimize, maximize, close, and IE toolbar functions.  And it seems like the only way to do this without opening a new window is by resizing the window and moving it so that the toolbar is out of sight.  Although that's not the best of solutions, it's all I have to work with right now.  

So right now, I can move the browser to hide the IE toolbar.  And I can hide the toolbar using the ShowWindow(FindWindow("shell_trayWnd",null), SW_HIDE) command, but if I use that command, I cannot resize the window to cover the portion of the screen where the taskbar used to be.
Bob LearnedCommented:
You need to use the SHAppBarMessage API call when changing the state of the AppBar, or the other windows won't know about the change.  

Here is a class that I use (somewhat untested):

' Interesting reading:
' The Old New Thing (Raymond Chen) -- How to Query Properties of the TaskBar
'  <Quote>
'    You can also use the ABM_SETSTATE message to change these states.
'    Note that doing so from a program is discouraged; these state bits
'    belong to the user's preferences. A program shouldn't be messing
'    with the user's preferences. (Well, unless the whole point of the
'    program is to change the user's preferences, of course. But the
'    frequency with which I see this question makes me wonder whether
'    there really are that many settings-tweaking programs out there.
'    I suspect people are using this power for evil, not for good.)
'    And to stave off follow-up questions: ABS_ALWAYSONTOP and ABS_AUTOHIDE
'    are the only two properties of the taskbar that are programmable.
'  </Quote>

Imports System.Runtime.InteropServices

Public Class AppBar

  Public Enum AppBarPosition
  End Enum   'AppBarPosition

  Private Const ABM_NEW As Int32 = &H0
  Private Const ABM_REMOVE As Int32 = &H1
  Private Const ABM_QUERYPOS As Int32 = &H2
  Private Const ABM_SETPOS As Int32 = &H3S
  Private Const ABM_GETSTATE As Int32 = &H4
  Private Const ABM_GETTASKBARPOS As Int32 = &H5
  Private Const ABM_ACTIVATE As Int32 = &H6
  Private Const ABM_GETAUTOHIDEBAR As Int32 = &H7
  Private Const ABM_SETAUTOHIDEBAR As Int32 = &H8
  Private Const ABM_WINDOWPOSCHANGED As Int32 = &H9
  Private Const ABM_SETSTATE As Int32 = &HA
  Private Const ABN_STATECHANGE As Int32 = &H0
  Private Const ABN_POSCHANGED As Int32 = &H1
  Private Const ABN_FULLSCREENAPP As Int32 = &H2
  Private Const ABN_WINDOWARRANGE As Int32 = &H3

  Private Const ABS_AUTOHIDE As Int32 = &H1
  Private Const ABS_ALWAYSONTOP As Int32 = &H2

  Private Const ABE_LEFT As Int32 = &H0
  Private Const ABE_TOP As Int32 = &H1
  Private Const ABE_RIGHT As Int32 = &H2
  Private Const ABE_BOTTOM As Int32 = &H3

  Private Declare Function GetAppBarMessage Lib "shell32" Alias "SHAppBarMessage" _
     (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As Integer

  Private Declare Function SetAppBarMessage Lib "shell32" Alias "SHAppBarMessage" _
   (ByVal dwMessage As Integer, ByVal pData As APPBARDATA) As Integer

  Private Structure APPBARDATA
    Dim cbSize As Integer
    Dim hwnd As Integer
    Dim uCallbackMessage As Integer
    Dim uEdge As Integer
    Dim rc As Rectangle
    Dim lParam As Integer     'message specific
  End Structure

  Private m_autoHide As Boolean
  Private m_alwaysOnTop As Boolean
  Private m_dockPosition As AppBarPosition = AppBarPosition.Unknown
  Private m_bounds As Rectangle

  Public Sub New()
  End Sub

  Private Sub GetState()

    Dim rc As New Rectangle
    Dim data As New APPBARDATA

    ' Initialize the APPBARDATA structure
    data.cbSize = Marshal.SizeOf(data)

    ' Get the appbar state  
    Dim state As Int32 = GetAppBarMessage(ABM_GETSTATE, data)

    Select Case state

      Case 0
        m_autoHide = False
        m_alwaysOnTop = False

        m_autoHide = False
        m_alwaysOnTop = True

      Case Else
        m_autoHide = True

    End Select     'state

    ' See which edge has a taskbar
    For position As Int32 = ABE_LEFT To ABE_BOTTOM

      data.uEdge = position
      Dim hWndAppBar As Int32 = GetAppBarMessage(ABM_GETAUTOHIDEBAR, data)

      If hWndAppBar > 0 Then

        Select Case position

          Case ABE_TOP
            m_dockPosition = AppBarPosition.Top

          Case ABE_LEFT
            m_dockPosition = AppBarPosition.Left

          Case ABE_RIGHT
            m_dockPosition = AppBarPosition.Right

          Case ABE_BOTTOM
            m_dockPosition = AppBarPosition.Bottom

        End Select          'position

      End If

    Next position

    Dim pos As Int32 = GetAppBarMessage(ABM_GETTASKBARPOS, data)

    If pos > 0 Then
      m_bounds = data.rc
    End If

  End Sub   'GetState

  Private Sub SetState()

    Dim data As New APPBARDATA
    data.cbSize = Marshal.SizeOf(data)

    If Me.AutoHide Then
      data.lParam = ABS_AUTOHIDE
    End If

    If Me.AlwaysOnTop Then
      data.lParam = data.lParam Or ABS_ALWAYSONTOP
    End If

    SetAppBarMessage(ABM_SETSTATE, data)

  End Sub  'SetState

  Public Property AutoHide() As Boolean
      Return m_autoHide
    End Get
    Set(ByVal Value As Boolean)
    End Set
  End Property   'AutoHide

  Public Property AlwaysOnTop() As Boolean
      Return m_alwaysOnTop
    End Get
    Set(ByVal Value As Boolean)
      m_alwaysOnTop = Value
    End Set
  End Property   'AlwaysOnTop

  Public ReadOnly Property DockPosition() As AppBarPosition
      Return m_dockPosition
    End Get
  End Property   'DockPosition

  Public ReadOnly Property Bounds() As Rectangle
      Return m_bounds
    End Get
  End Property   'Bounds

  Public ReadOnly Property Left() As Integer
      Return m_bounds.Left
    End Get
  End Property  'Left

  Public ReadOnly Property Top() As Integer
      Return m_bounds.Top
    End Get
  End Property  'Top

  Public ReadOnly Property Location() As Point
      Return m_bounds.Location
    End Get
  End Property  'Location

  Public ReadOnly Property Size() As Size
      Return m_bounds.Size
    End Get
  End Property  'Size

End Class


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CaitlinRobertsAuthor Commented:
Thanks for post!  Looks exactly like what I needed.  I'm just having a little trouble get it to work.  
I get a "Object reference not set to an instance of an object" error when it's trying to call the SetAppBarMessage method.  Any suggestions?

CaitlinRobertsAuthor Commented:
I've got it!!  It looks like it didn't like the ByVal in:
  Private Declare Function SetAppBarMessage Lib "shell32" Alias "SHAppBarMessage" _
   (ByVal dwMessage As Integer, ByVal pData As APPBARDATA) As Integer
  ...for the pData.

It seems like it need to be passed in by reference.  Thanks so much for your help, you have no idea how long I've been working on this problem!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.