Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Hiding the Windows XP Start button correctly

0.00/5 (No votes)
21 Mar 2006 1  
How to properly hide the Windows XP Start button, and resize the task button area to remove the blank space left after hiding the Start button.

Introduction

Recently, I was working on a project that required the Start button to be hidden. After searching through about 1 million code snippets, I found no code that would do this to my requirements. All the snippets I found used the user32 ShowWindow API to hide the window, but this left a blank space where the Start button used to be.

Here is a new way to hide the Start button and resize the ReBar (if that's what it's called) to take over the space previously occupied by the Start button.

Hope this helps someone ;)

Screenshot

Sample Image - screen.jpg

Usage

Dim sb As New StartButton
sb.Visible = True 'Hide the StartButton
sb.Visible = False 'Show the StartButton

Code

Public Class StartButton
    Private Declare Ansi Function FindWindow Lib "user32" Alias "FindWindowA" _
           (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Private Declare Ansi Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
           (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, _
            ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
    Private Declare Auto Function ShowWindow Lib "user32" _
           (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As IntPtr
    Private Declare Function GetWindowRect Lib "user32.dll" _
           (ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
    Private Declare Function MoveWindow Lib "user32.dll" (ByVal hWnd As IntPtr, _
            ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, _
            ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean

    Private Structure RECT
        Public left As Integer
        Public top As Integer
        Public right As Integer
        Public bottom As Integer
    End Structure

    Private Enum SW As Integer
        SW_FORCEMINIMIZE = 11
        SW_HIDE = 0
        SW_MAXIMIZE = 3
        SW_MINIMIZE = 6
        SW_RESTORE = 9
        SW_SHOW = 5
        SW_SHOWDEFAULT = 10
        SW_SHOWMAXIMIZED = 3
        SW_SHOWMINIMIZED = 2
        SW_SHOWMINNOACTIVE = 7
        SW_SHOWNA = 8
        SW_SHOWNOACTIVATE = 4
        SW_SHOWNORMAL = 1
    End Enum

    Private TaskbarHandle As IntPtr = FindWindow("Shell_TrayWnd", Nothing)
    Private StartButtonHandle As IntPtr = _
      FindWindowEx(TaskbarHandle, IntPtr.Zero, "Button", Nothing)
    Private RebarWindowHandle As IntPtr = _
      FindWindowEx(TaskbarHandle, IntPtr.Zero, "ReBarWindow32", Nothing)
    Private ReBarRectangle As Rectangle
    Private StartButtonRectangle As Rectangle
    Private TaskBarRectangle As Rectangle
    Private blnVisible As Boolean = True

    Public Sub New()
        Dim rect As New RECT
        GetWindowRect(Me.TaskbarHandle, rect)
        Me.TaskBarRectangle = _
           Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom)
        GetWindowRect(Me.StartButtonHandle, rect)
        Me.StartButtonRectangle = Rectangle.FromLTRB(rect.left - _
                  Me.TaskBarRectangle.Left, rect.top - Me.TaskBarRectangle.Top, _
                  rect.right - Me.TaskBarRectangle.Left, _
                  rect.bottom - Me.TaskBarRectangle.Top)
        GetWindowRect(Me.RebarWindowHandle, rect)
        Me.ReBarRectangle = Rectangle.FromLTRB(rect.left - Me.TaskBarRectangle.Left, _
                            rect.top - Me.TaskBarRectangle.Top, _
                            rect.right - Me.TaskBarRectangle.Left, _
                            rect.bottom - Me.TaskBarRectangle.Top)
    End Sub

    Public Property Visible() As Boolean
        Get
            Return blnVisible
        End Get
        Set(ByVal value As Boolean)
            If value Then
                ShowWindow(Me.StartButtonHandle, SW.SW_SHOW)
                MoveWindow(Me.RebarWindowHandle, Me.ReBarRectangle.X, _
                  Me.ReBarRectangle.Y, Me.ReBarRectangle.Width, _
                  Me.ReBarRectangle.Height, True)
                Me.blnVisible = True
            Else
                ShowWindow(Me.StartButtonHandle, SW.SW_HIDE)
                MoveWindow(Me.RebarWindowHandle, Me.StartButtonRectangle.X, _
                  Me.StartButtonRectangle.Y, Me.ReBarRectangle.Width + _
                  Me.StartButtonRectangle.Width, Me.ReBarRectangle.Height, True)
                Me.blnVisible = False
            End If
        End Set
    End Property
End Class

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here