Windows任务栏API

    技术2022-05-20  56

    使用Windows API 显示和隐藏 Windows 的任务栏的方法,windows 的任务栏,其实是一个窗口(window),只要找到这个窗口的句柄,显示和隐藏就轻而易举了,任务栏是个没有标题的窗口,但知道它的类名是 Shell_TrayWnd,所以,可以用 FindWindow 或 FindWindowEx 去查找它的句柄,而显示和隐藏窗口,使用的是 ShowWindow: * 引入Windows API 的声明 [DllImport("User32.dll", EntryPoint="FindWindow", CharSet=CharSet.Auto)] public static extern  int FindWindow(String className, String captionName); [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)] static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)] static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow); * 显示/隐藏任务栏窗口 //IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null); IntPtr trayHwnd = FindWindow("Shell_TrayWnd", null); if (trayHwnd != IntPtr.Zero)     {         ShowWindow(trayHwnd, 0);   } 上面的代码中, ShowWindow 的第二参数, 1表示显示, 0表示隐藏


    最新回复(0)