Thursday, July 15, 2010

Hide Taskbar

If we want to fade the taskbar in or out (most people probably want to hide it), we need the WinAPI.
To get the window handle (the identifier of a window) of the taskbar, we need the function FindWindow(). More to this function and why we here cannot use the .Net class System.Diagnostics.Process, you can read in the previous post.
But with FindWindow(), we can "grab" the taskbar and manipulate it. For showing or hiding it, we need the API function ShowWindow().
It expects 2 parameters: First an integer, which is the windows handle, and second another integer, which describes the desired action. All possible values can be looked up here.
We need the values 0 to hide a window and 1 to show it again, more examples are 3 (maximize) and 6 (minimize).
The following sample application hides the taskbar when loading the form (System.Runtime.InteropServices has to be included via using for the DLL import):

        [DllImport("user32.dll")]
        private static extern int FindWindow(string className, string windowText);

        [DllImport("user32.dll")]
        private static extern int ShowWindow(int hwnd, int command);

        private void Form1_Load(object sender, EventArgs e)
        {
            int TaskbarWindowHandle = FindWindow("Shell_TrayWnd""");
            ShowWindow(TaskbarWindowHandle, 0);
        }

No comments:

Post a Comment