在Windows 8中隐藏任务栏

到目前为止,我能够使用以下C#代码隐藏Windows任务栏:

[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 const int SW_HIDE = 0; private const int SW_SHOW = 1; ... int hwnd = FindWindow("Shell_TrayWnd", ""); ShowWindow(hwnd, SW_SHOW); 

但是在使用Windows 8时,此代码仅隐藏主监视器上的任务栏,而不是第二个,任务栏也可见。

如何才能在我的窗口显示的屏幕上隐藏任务栏?

利用FindWindowEx 。 这允许您传入一个窗口以便在Z顺序中搜索。

人机工程学:

 DllImport("user32.dll")] private static extern int FindWindowEx(int parent, int afterWindow, string className, string windowText); // Start with the first child, then continue with windows of the same class after it int hWnd = 0; while (hWnd = FindWindowEx(0, hWnd, "Shell_TrayWnd", "")) ShowWindow(hWnd, SW_SHOW); 

如果只想在特定屏幕上隐藏任务栏,请使用GetWindowRect并检查窗口所在屏幕的界限,并仅在当前屏幕上的窗口上调用ShowWindow。

不要隐藏任务栏; 做这样的事情是错误的。 相反,只需创建一个全屏窗口,任务栏足够聪明,可以让您自己走开。

您可以在他的博客上阅读微软的Raymond Chen的一个很好的解释和评论。

我遇到了同样的问题。

1)在多个监视器上运行应用程序

2)在第一台显示器没有问题,应用程序保持在最顶层

3)但是如果单击第二个窗口,则会出现任务栏,反之亦然

使用FindWindowEx,只找到一个Shell_TrayWnd。 它是第一个屏幕中的一个,可以隐藏