Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / Win32

Hiding the Taskbar and Startmenu (start orb) in Windows Vista and Windows 7

Rate me:
Please Sign up or sign in to vote.
4.90/5 (32 votes)
25 Nov 2011CPOL2 min read 209.7K   7.5K   53   48
How to hide the taskbar and startmenu (start orb) under Windows Vista

Introduction

I recently needed to hide the Windows taskbar and startmenu. All the code that I found on the net for this purpose did not work on Windows Vista, so I decided to write some by myself. The solution I have found works well on Windows XP, Windows Vista and Windows 7, both 32- and 64-bit.

Background

Hiding the taskbar is very easy, because its window handle can easily been found with a call to the FindWindow WINAPI function:

C#
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter,
    string className,  string windowTitle);

IntPtr taskBarWnd = FindWindow("Shell_TrayWnd", null);

Once we know the window handle, we can hide the window using the WINAPI function ShowWindow. If you do this, the taskbar is hidden, but the "Start" button still remains visible. Under Windows XP (and before) this was also easy, because the "Start" button was a child window of the taskbar and its window handle can be found with a call to FindWindowEx:

C#
IntPtr startWnd = FindWindowEx(taskBarWnd, IntPtr.Zero, "Button", "Start");

However, this changed with Windows Vista: If you look closely, you will see that the Vista start orb is overlapping the taskbar a little bit. The start orb is not a child window of the taskbar anymore, but a window of its own. To find the handle of this window, I proceed as follows:

First, I get the id of the process that owns the taskbar window:

C#
[DllImport("user32.dll")]
static extern uint GetWindowThreadProcessId(IntPtr hwnd, out int lpdwProcessId);

int procId;
GetWindowThreadProcessId(taskBarWnd, out procId);

Then I enumerate all threads of this process by using managed code. For each thread, I enumerate its windows by using the WINAPI function EnumThreadWindows:

C#
Process p = Process.GetProcessById(procId);
if (p != null)
{
    // enumerate all threads of that process...
    foreach (ProcessThread t in p.Threads)
    {
        EnumThreadWindows(t.Id, MyEnumThreadWindowsProc, IntPtr.Zero);
    }
}

The EnumThreadWindows function lets Windows call my callback function MyEnumThreadWindowsProc for each window of the given thread. Within the callback function, I check whether the caption of each window is "Start" (which is true only for the start menu window):

C#
private static bool MyEnumThreadWindowsProc(IntPtr hWnd, IntPtr lParam)
{
    StringBuilder buffer = new StringBuilder(256);
    if (GetWindowText(hWnd, buffer, buffer.Capacity) > 0)
    {
        if (buffer.ToString() == VistaStartMenuCaption)
        {
            vistaStartMenuWnd = hWnd;
            return false;
        }
    }
    return true;
}

Using the Code

I packed everything in a single static class so you don't have to worry about WINAPI. Just include the class Taskbar in your application and call the static method Hide or Show. That's all, really! Of course this works on Windows XP, Vista and Windows 7!

C#
// hide the taskbar and startmenu
Taskbar.Hide();

History

  • 2008-04-23: Version 1.0 posted
  • 2008-07-16: Version 1.1 posted, sources updated so they should work also on non-English versions of Vista
  • 2011-11-24: Version 1.2 posted, added an alternate way to find a window handle, solution updated to VS2010

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Sevitec Informatik AG
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerRe: How to make this code work for .net 1.1 version Pin
Simon B.4-Sep-08 4:26
Simon B.4-Sep-08 4:26 
QuestionAnd how about Windows in other languages? Pin
Cleyton Messias1-Jul-08 7:10
Cleyton Messias1-Jul-08 7:10 
AnswerRe: And how about Windows in other languages? Pin
Simon B.3-Jul-08 4:45
Simon B.3-Jul-08 4:45 
GeneralRe: And how about Windows in other languages? Pin
Cleyton Messias3-Jul-08 6:43
Cleyton Messias3-Jul-08 6:43 
GeneralRe: And how about Windows in other languages? Pin
Simon B.16-Jul-08 9:37
Simon B.16-Jul-08 9:37 
GeneralRe: And how about Windows in other languages? Pin
Waylon Flinn27-Jul-09 4:55
Waylon Flinn27-Jul-09 4:55 
QuestionHow can i maximee the form? Pin
merlin.AT2-Jun-08 3:59
merlin.AT2-Jun-08 3:59 
AnswerRe: How can i maximee the form? Pin
Simon B.4-Jun-08 8:26
Simon B.4-Jun-08 8:26 
GeneralJust in time Pin
Kavan Shaban25-Apr-08 15:51
Kavan Shaban25-Apr-08 15:51 
GeneralRe: Just in time Pin
SteveKing27-Apr-08 19:28
SteveKing27-Apr-08 19:28 
GeneralRe: Just in time Pin
Member 435831630-Apr-08 2:15
Member 435831630-Apr-08 2:15 
AnswerRe: Hiding the start button only Pin
Simon B.1-May-08 9:23
Simon B.1-May-08 9:23 
GeneralRe: Hiding the start button only Pin
Member 118949888-Aug-15 1:57
Member 118949888-Aug-15 1:57 

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.