Click here to Skip to main content
Licence CPOL
First Posted 21 Mar 2006
Views 34,254
Bookmarked 12 times

Hiding the Windows XP Start button correctly

By | 21 Mar 2006 | Article
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

AndrewVos

Software Developer

United Kingdom United Kingdom

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralFunny, but... PinmemberS. Töpfer0:18 13 Mar '09  
Generalconvert int[] to IntPtr PinmemberM.N.7:05 2 Oct '07  
Generalno hiding Pinmembermohit narang7:23 26 Jul '06  
GeneralRe: no hiding PinmemberAndrewVos23:58 30 Oct '06  
Generalfor hook lover PinmemberKedar V2:23 30 Jun '06  
GeneralRe: for hook lover PinmemberSandeeep Sachan0:20 15 Nov '06  
GeneralCannot convert System.IntPtr. to int Pinmemberjoejoe GOD's Son0:28 14 Apr '06  
GeneralRe: Cannot convert System.IntPtr. to int Pinmember1tg468:18 9 Aug '06  
QuestionWhat would be nice PinmemberAndrewVos6:11 22 Mar '06  
Generalsystem tray returns start button space PinmemberSDragon424:43 22 Mar '06  
GeneralRe: system tray returns start button space PinmemberAndrewVos6:04 22 Mar '06  
GeneralRe: system tray returns start button space PinmemberAndrewVos6:05 22 Mar '06  
GeneralSource-Code Pinmemberjoejoe GOD's Son1:48 22 Mar '06  
GeneralRe: Source-Code PinmemberSDragon424:37 22 Mar '06  
GeneralRe: Source-Code Pinmember1tg468:22 9 Aug '06  
Generalhi PinmemberThe_Myth23:07 21 Mar '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 22 Mar 2006
Article Copyright 2006 by AndrewVos
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid