如何以编程方式隐藏桌面图标?
如何使用 C# 以编程方式显示/隐藏桌面图标?
我正在尝试创建一个使用小部件的替代桌面,并且我需要隐藏旧图标。
How can I show/hide the desktop icons programmatically, using C#?
I'm trying to create an alternative desktop, which uses widgets, and I need to hide the old icons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用 Windows API 来执行此操作。以下是 C# 示例代码,用于切换桌面图标。
这会向 Progman 的 SHELLDLL_DefView 子窗口发送一条消息,告诉它切换其唯一子窗口“FolderView”的可见性(通过添加或删除 WS_VISIBLE 样式)。 “FolderView”是包含图标的实际窗口。
要测试图标是否可见,您可以使用 GetWindowInfo 函数查询 WS_VISIBLE 样式,如下所示:
这是一个调用上述代码的函数,如果窗口可见则返回 true,否则返回 false。
Windows API 代码以及有关窗口样式的更多信息可以在此处找到:http: //www.pinvoke.net/default.aspx/user32/GetWindowInfo.html
You can do this using the Windows API. Here is sample code in C# that will toggle desktop icons.
This sends a message to the SHELLDLL_DefView child window of Progman, which tells it to toggle visibility (by adding or removing the WS_VISIBLE style) of it's only child, "FolderView". "FolderView" is the actual window that contains the icons.
To test to see if icons are visible or not, you can query for the WS_VISIBLE style by using the GetWindowInfo function, shown below:
Here is a function that calls the above code and returns true if the window is visible, false if not.
The windows API code along with more information about the window styles can be found here: http://www.pinvoke.net/default.aspx/user32/GetWindowInfo.html
尽管当我尝试 Ondrej Balas 的答案时,这个问题已经很老了,但我发现这个解决方案的一个问题是它不起作用如果使用 ToggleDesktop 命令显示桌面(如果启用了壁纸旋转)。
在这两种情况下,SHELLDLL_DefView 窗口(ToggleDesktopIcons 函数中的toggleDesktopCommand 的接收者)不是“程序管理器”窗口的子窗口,而是“WorkerW”窗口的子窗口。(请参阅 WinApi - 如何获取SHELLDLL_DefView 和 Windows 桌面 ListView 句柄
基于这些内容并以 Ondrej Balas 的早期answer 将 ToggleDesktopIcons 函数更改为:
并添加 GetDesktopSHELLDLL_DefView 函数:
现在,无论桌面切换或壁纸旋转,ToggleDesktopIcons 都应该始终有效 作为参考,
这是我的切换桌面函数,它导致了原始 ToggleDesktopIcons 函数的问题
响应 James M,此函数返回当前状态:
Even though this is quite old when I tried Ondrej Balas's answer, one problem I found with this solution is that it does not work if the ToggleDesktop command is used to show the desktop ( also if wallpaper rotation is enabled ).
In both of these cases the SHELLDLL_DefView window, which is the recipient of the toggleDesktopCommand in the ToggleDesktopIcons function, is not a child of the "Program manager" window but of a 'WorkerW" window. (see WinApi - How to obtain SHELLDLL_DefView and Windows Desktop ListView Handle.
Based on those and building upon Ondrej Balas's earlier answer change the ToggleDesktopIcons function to be :
And add a GetDesktopSHELLDLL_DefView function:
Now regardless of the desktop toggle or wallpaper rotation the ToggleDesktopIcons should always work.
For reference this is my toggle desktop function which caused the issue with the original ToggleDesktopIcons function
In response to James M, this function returns the current state:
另一种方法是创建一个单独的桌面并显示它。它不会有图标。
应用程序在单独的桌面上自行运行
A different approach is to create a separate desktop and show it instead. It will not have icons.
Application running itself on a separate desktop
您可以在 RegEdit 中执行此操作
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced
将 HideIcons 更改为 1
使用此处所述的Registry 类。
http://msdn.microsoft.com/en-us/library /microsoft.win32.registry.aspx
You can do this in RegEdit
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced
change HideIcons to 1
Use the Registry class as described here.
http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx
您可以创建全屏视图应用程序并将其设为最顶层的窗口。
然后使您的应用程序随 Windows 一起启动。
You can create a full screen view application and make it the top most window.
Then make your application to be start up with windows.
你的处理方式是错误的。你真正想做的是更换外壳。 Windows 提供了此功能,因此您应该充分利用它。编写自己的 shell 来替换 explorer。
You are going about this the wrong way. What you are really trying to do is to replace the shell. Windows provides for this so you should just take advantage of it. Write your own shell to replace explorer.
好话题。在不实际创建不同桌面的情况下,将正在运行的应用程序同时最小化会在视觉上令人愉悦。
Nice topic. Without actually creating a different desktop it would be visually pleasant to have the running applications minimized in the same swoop.