通过C#代码显示桌面 [英] Displaying Desktop through c# code

查看:184
本文介绍了通过C#代码显示桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体的面板.我想在面板内显示桌面.谁能告诉我怎么做.
预先谢谢您

I have a panel in a windows form. I want to display the desktop inside the panel. Can anybody please tell me how to do it.
thank you in advance

推荐答案

,您可以使用 Environment.GetFolderPath方法 [ ^ ],并将参数传递为Environment.SpecialFolder.Desktop.这为您提供了台式机的路径.

这样,您可以在桌面上获取文件和文件夹,并将其显示在面板中.
you can use Environment.GetFolderPath Method[^] and pass the argument as Environment.SpecialFolder.Desktop. That gives you the path for desktop.

With that you can get the files and folders on the desktop and display it in the panel.


除了Vivek的正确解决方案:

还有更多.

1)将Environment.GetFolderPathEnvironment.SpecialFolder.Desktop结合使用以访问桌面目录,请参见 http://msdn .microsoft.com/en-us/library/14tx8hby.aspx [ ^ ].

2)使用System.IO.Directory.GetFiles获取所需所有文件的完整路径名.小心:这里有问题,解决方法在这里解释:
Directory.Get.Files搜索模式问题 [ ^ ].

3)在面板上填充一些您要设计的控件,以表示桌面上的文件;可能您需要使每个控件都可单击才能执行实际桌面上通常执行的链接操作.

4)要实现上一项,您将需要访问* .LNK文件,这些文件通常存储在桌面中.您将需要P/Invoke来执行此操作;在此处查看代码示例:
http://stackoverflow.com/questions/139010/how-to-resolve- a-lnk-in-c [ ^ ].

5)您的应用程序将需要响应桌面上的更改,因为用户可以添加,修改或删除某些文件.要处理这些更改,您需要在软件中触发一些事件.这不是很琐碎.为此,请使用类System.IO.FileSystemWatcher,请参见 http://msdn.microsoft. com/en-us/library/system.io.filesystemwatcher.aspx [ ^ ].

就是这样,它看起来像.如果您在执行所有这些操作时遇到任何问题,请告诉我.如果您愿意,我也想知道您的最终目标和此应用程序的目的.为什么要做真正的桌面已经在做的事情?

祝你好运,
-SA
In addition to correct solution by Vivek:

There are more to it.

1) Use Environment.GetFolderPath with Environment.SpecialFolder.Desktop to get access to a desktop directory, see http://msdn.microsoft.com/en-us/library/14tx8hby.aspx[^].

2) Use System.IO.Directory.GetFiles to get the full path names all the files you need. Be careful: there is a problem here, the resolution is explained here:
Directory.Get.Files search pattern problem[^].

3) Populate your panel with some controls you want to devise to represent a file on a desktop; probably you need to have each control clickable to do the actions a link on the real desktop usually does.

4) To implement the previous item, you will need to get access to *.LNK files which are most typically stored in the desktop. You will need P/Invoke to do that; see the code sample here:
http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c[^].

5) Your application will need to respond to changes on the desktop as the user can add, modify or remove some files. To handle those changes, you need some events triggering in your software. This is not very trivial. For this purpose, use the class System.IO.FileSystemWatcher, see http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^].

That''s it, it looks like. Please let me know if you have any problems implementing all this. If you do, I would also like to know your ultimate goals and the purpose of this application. Why doing what the real desktop is already doing?

Good luck,
—SA


不确定这是否适用于桌面,但可能获取桌面的句柄并调用SetParent函数-请参见 ^ ]演示托管Windows/应用程序.
Not sure if this will work with the Desktop, but perhaps getting the desktop''s handle and calling SetParent function - see this article[^] for a demonstration of hosting windows/apps.


这篇关于通过C#代码显示桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆