[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1518
  • Last Modified:

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?
0
CaitlinRoberts
Asked:
CaitlinRoberts
  • 3
1 Solution
 
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...
0
 
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.
0
 
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
' http://blogs.msdn.com/oldnewthing/archive/2005/05/06/415158.aspx
'  <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
    Unknown
    Top
    Left
    Right
    Bottom
  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()
    Me.GetState()
  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

      Case ABS_ALWAYSONTOP
        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
    Get
      Return m_autoHide
    End Get
    Set(ByVal Value As Boolean)
      Me.SetState()
    End Set
  End Property   'AutoHide

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

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

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

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

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

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

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

End Class

Bob
0
 
CaitlinRobertsAuthor Commented:
Bob,
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?

Thanks!
Caitlin
0
 
CaitlinRobertsAuthor Commented:
Bob,
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!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now