Click here to Skip to main content
15,312,347 members
Articles / Programming Languages / Visual Basic
Article
Posted 21 Mar 2006

Stats

47.3K views
13 bookmarked

Hiding the Windows XP Start button correctly

Rate me:
Please Sign up or sign in to vote.
1.23/5 (11 votes)
21 Mar 2006CPOL
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

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

Code

VB
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)

Share

About the Author

AndrewVos
Software Developer
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralMy vote of 3 Pin
Member-949016822-Mar-13 5:37
MemberMember-949016822-Mar-13 5:37 
GeneralFunny, but... Pin
Sebastian Br.13-Mar-09 0:18
MemberSebastian Br.13-Mar-09 0:18 
Generalconvert int[] to IntPtr Pin
M.N.2-Oct-07 7:05
MemberM.N.2-Oct-07 7:05 
Generalno hiding Pin
mohit narang26-Jul-06 7:23
Membermohit narang26-Jul-06 7:23 
GeneralRe: no hiding Pin
AndrewVos30-Oct-06 23:58
MemberAndrewVos30-Oct-06 23:58 
Generalfor hook lover Pin
K edar V30-Jun-06 2:23
MemberK edar V30-Jun-06 2:23 
GeneralRe: for hook lover Pin
Sandeeep Sachan15-Nov-06 0:20
MemberSandeeep Sachan15-Nov-06 0:20 
GeneralCannot convert System.IntPtr. to int Pin
JL#14-Apr-06 0:28
MemberJL#14-Apr-06 0:28 
GeneralRe: Cannot convert System.IntPtr. to int Pin
Thomas Stockwell9-Aug-06 8:18
professionalThomas Stockwell9-Aug-06 8:18 
QuestionWhat would be nice Pin
AndrewVos22-Mar-06 6:11
MemberAndrewVos22-Mar-06 6:11 
Generalsystem tray returns start button space Pin
SDragon4222-Mar-06 4:43
MemberSDragon4222-Mar-06 4:43 
GeneralRe: system tray returns start button space Pin
AndrewVos22-Mar-06 6:04
MemberAndrewVos22-Mar-06 6:04 
GeneralRe: system tray returns start button space Pin
AndrewVos22-Mar-06 6:05
MemberAndrewVos22-Mar-06 6:05 
GeneralSource-Code Pin
JL#22-Mar-06 1:48
MemberJL#22-Mar-06 1:48 
GeneralRe: Source-Code Pin
SDragon4222-Mar-06 4:37
MemberSDragon4222-Mar-06 4:37 
GeneralRe: Source-Code Pin
Thomas Stockwell9-Aug-06 8:22
professionalThomas Stockwell9-Aug-06 8:22 
Generalhi Pin
AnasHashki21-Mar-06 23:07
MemberAnasHashki21-Mar-06 23:07 

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

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