隐藏/显示任务栏

  /// <summary>
        /// Retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
        /// </summary>
        /// <param name="lpClassName">The class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.
///If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.
///If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.</param>
        /// <param name="lpWindowName">The window name (the window's title). If this parameter is NULL, all window names match.</param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        /// <summary>
        /// Sets the specified window's show state.
        /// </summary>
        /// <param name="hwnd">A handle to the window.</param>
        /// <param name="nCmdShow">Controls how the window is to be shown. This parameter is ignored the first time an application calls ShowWindow, if the program that launched the application provides a STARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained by the WinMain function in its nCmdShow parameter. In subsequent calls, this parameter can be one of the following values.</param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
       
        private const int SW_HIDE = 0;
        private const int SW_RESTORE = 9;
        private void btnHide_Click(object sender, EventArgs e)
        {
            ShowWindow(FindWindow("Shell_TrayWnd", null), SW_HIDE); 
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            ShowWindow(FindWindow("Shell_TrayWnd", null), SW_RESTORE);
        }
原文地址:https://www.cnblogs.com/wjshan0808/p/4233973.html