在C#中隐藏Vista / Win 7上的Start Orb

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1165879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:48:06  来源:igfitidea点击:

Hide Start Orb on Vista / Win 7 in C#

c#windows-7windows-vistataskbar

提问by Waylon Flinn

When hiding the Task Bar on Vista and Windows 7 the Start Button (also known as the Start Orb) doesn't get hidden. I've been looking for a solution to this and I've found one but it seems more complex than necessary. This CodeProject articledescribes (and contains code for) a solution where you enumerate all child windows of all threads in the process that contains the start menu.

在 Vista 和 Windows 7 上隐藏任务栏时,开始按钮(也称为开始球)不会隐藏。我一直在寻找解决方案,我找到了一个,但它似乎比必要的更复杂。这篇CodeProject 文章描述(并包含代码)一个解决方案,您可以在其中枚举包含开始菜单的进程中所有线程的所有子窗口。

Has anyone found a simpler solution?

有没有人找到更简单的解决方案?

Just for reference. The code for hiding the Task Bar (without hiding the Orb) is as follows. First do the necessary Win32 imports and declarations.

仅供参考。隐藏任务栏(不隐藏Orb)的代码如下。首先进行必要的 Win32 导入和声明。

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

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


private const int SW_HIDE = 0;
private const int SW_SHOW = 1;

Then, in a method somewhere, call them with the right arguments

然后,在某处的方法中,使用正确的参数调用它们

IntPtr hwndTaskBar = FindWindow("Shell_TrayWnd", "");
ShowWindow(this.hwndTaskBar, SW_HIDE);

采纳答案by Waylon Flinn

I was able to put together a solution that didn't require all the thread enumeration. Here are the relevant parts.

我能够将不需要所有线程枚举的解决方案放在一起。以下是相关部分。

If you declare FindWindowExas follows

如果你声明FindWindowEx如下

[DllImport("user32.dll")]
private static extern IntPtr FindWindowEx(
       IntPtr parentHwnd,
       IntPtr childAfterHwnd,
       IntPtr className,
       string windowText);

You can then access the window handle for the Start Orb like this:

然后,您可以像这样访问 Start Orb 的窗口句柄:

IntPtr hwndOrb = FindWindowEx(IntPtr.Zero, IntPtr.Zero, (IntPtr)0xC017, null);

and disable the Start Orb like this:

并像这样禁用 Start Orb:

ShowWindow(hwndOrb, SW_HIDE);

The key to this method is that we use the IntPtrtype for the className variable instead of a string in the FindWindowExfunction. This allows us to use the portion of this function that takes an ATOMtype rather than a string. I was able to discern that the particular ATOMto use is at 0xC017from this post: Hide Vista Start Orb

这个方法的关键是我们使用IntPtrclassName 变量的类型而不是FindWindowEx函数中的字符串。这使我们可以使用此函数中采用ATOM类型而不是 的部分string。我能够从这篇文章中看出ATOM要使用的特定内容0xC017Hide Vista Start Orb

Hope this simplified version helps some people.

希望这个简化版能帮到一些人。

UPDATE: I created this new Code Project Pageto document this process.

更新:我创建了这个新的代码项目页面来记录这个过程。