|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionI 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 myself. BackgroundHiding the taskbar is very easy, because its window handle can easily been found with a call to the [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 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: [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 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);
}
}
For the 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 CodeI packed everything in a single static class so you don't have to worry about WINAPI. Just include the class // hide the taskbar and startmenu
Taskbar.Hide();
History2008-04-23: Version 1.0 posted.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||