有没有办法把用户的Windows桌面的截图? [英] Is there a way to take a screenshot of the user's Windows desktop?

查看:126
本文介绍了有没有办法把用户的Windows桌面的截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用提供了桌面的缩小截图用户。

I want to provide the user with a scaled-down screenshot of their desktop in my application.

有没有办法把当前用户的Windows桌面的截图?

我写在C#中,但如果有另一种语言更好的解决方案,我接受它。

I'm writing in C#, but if there's a better solution in another language, I'm open to it.

要澄清一下,我需要在Windows桌面的截图 - 这是壁纸和图标只;没有应用程序或任何的得到了关注的焦点。

To clarify, I need a screenshot of the Windows Desktop - that's the wallpaper and icons only; no applications or anything that's got focus.

推荐答案

您正在寻找图形。 CopyFromScreen 。创建一个大小合适的新位图,并通过该地区的位图的图形对象的屏幕坐标复制。

You're looking for Graphics.CopyFromScreen. Create a new Bitmap of the right size and pass the Bitmap's Graphics object screen coordinates of the region to copy.

还有 描述文章如何以编程方式拍摄快照。

There's also an article describing how to programmatically take snapshots.

响应修改:我误解你了由桌面是什么意思。如果你想利用桌面的图片,你必须:

Response to edit: I misunderstood what you meant by "desktop". If you want to take a picture of the desktop, you'll have to:


  1. 最小化使用Win32API的所有窗口(发送 MIN_ALL 消息)第一

  2. 拍摄快照

  3. 然后撤消最小化所有(发送 MIN_ALL_UNDO 消息)。

  1. Minimize all windows using the Win32API (send a MIN_ALL message) first
  2. Take the snapshot
  3. Then undo the minimize all (send a MIN_ALL_UNDO message).

一个更好的办法来做到这一点将不惊动其他窗口,但对图像直接从桌面窗口中复制。 GetDesktopWindow在USER32 将返回的句柄到桌面。一旦你的窗口句柄,得到它的设备上下文和图像复制到一个新位图。


A better way to do this would be not to disturb the other windows, but to copy the image directly from the desktop window. GetDesktopWindow in User32 will return a handle to the desktop. Once you have the window handle, get it's device context and copy the image to a new Bitmap.

有的在如何将图像从复制$ C $的CProject 一个很好的例子它。寻找样本code有关获取和创建捕获窗口内容部分中的设备上下文。

There's an excellent example on CodeProject of how to copy the image from it. Look for the sample code about getting and creating the device context in the "Capturing the window content" section.

这篇关于有没有办法把用户的Windows桌面的截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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