Playing Peek-a-boo with Windows Taskbar and Covering the Entire Screen
July 22. 2009
0 Comments
- Posted in:
- Windows Form
I’m liking StackOverflow more and more. Sort of addicted to it now. You can really learn so much from answering other people questions and just browsing topics that interests you.
For example, today I learnt how to actually hide the Windows Taskbar using PInvoke and very easy way to cover the entire screen with your Windows Form application.
The following code can be used to hide and show the taskbar (supposedly work on Vista. Tested on Win7):
public static class TaskBarHelper { [DllImport("user32.dll")] private static extern IntPtr FindWindow(string className, string windowText); [DllImport("user32.dll")] private static extern int ShowWindow(IntPtr hwnd, int command); [DllImport("user32.dll")] private static extern IntPtr FindWindowEx(IntPtr parentHwnd, IntPtr childAfterHwnd, IntPtr className, string windowText); private const int SW_HIDE = 0; private const int SW_SHOW = 1; public static void HideTaskBar() { HideWindow(GetTaskBarWindowHandle()); HideWindow(GetOrbWindowHandle()); } public static void ShowTaskBar() { ShowWindow(GetTaskBarWindowHandle()); ShowWindow(GetOrbWindowHandle()); } private static void HideWindow(IntPtr hwnd) { ShowWindow(hwnd, SW_HIDE); } private static void ShowWindow(IntPtr hwnd) { ShowWindow(hwnd, SW_SHOW); } private static IntPtr GetTaskBarWindowHandle() { return FindWindow("Shell_TrayWnd", ""); } private static IntPtr GetOrbWindowHandle() { return FindWindowEx(IntPtr.Zero, IntPtr.Zero, (IntPtr) 0xC017, "Start"); } }
And to cover the entire screen with your application (Full Screen mode) you can use the following:
public static class FormHelper { public static void ShowFullScreen(Form form) { form.FormBorderStyle = FormBorderStyle.None; form.WindowState = FormWindowState.Maximized; } }