C# 在Windows8中隐藏任务栏

C# 在Windows8中隐藏任务栏,c#,C#,到目前为止,我能够使用以下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;

到目前为止,我能够使用以下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);
但当使用Windows8时,此代码仅在主显示器上隐藏任务栏,而不在第二个显示器上,任务栏也可见

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

利用。这允许您传入一个窗口,以便按Z顺序进行搜索

因此:


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

不要隐藏任务栏;这样做是不对的。取而代之的是,只需制作一个全屏窗口,任务栏就足够智能,可以避开你的视线


你可以阅读微软的Raymond Chen对他的解释和评论。

我也有同样的问题

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

2) 在第一个监视器上没有问题,应用程序保持在顶部

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


使用FindWindowEx只能找到一个Shell\u TrayWnd。这是第一个屏幕上的一个,可以隐藏

我完全同意你的观点,但我需要在另一个全屏应用程序前设置一个窗口。每当我的窗体获得焦点时,任务栏就会再次出现。如果在您的窗口获得焦点时出现任务栏,则可能是您没有正确设置全屏窗口。您能告诉我们您是如何创建窗口的吗?“其次,如果您的程序在有机会取消隐藏任务栏之前崩溃了怎么办?任务栏现在永久隐藏,用户必须注销并重新登录才能恢复任务栏。这可不太好。”
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);