在Windows中使用c++对窗口进行截屏的最佳方式是什么?

时间:2021-09-18 15:07:10

What is the best (easiest) way to take a screenshot of an running application with C++ under Windows?

在Windows下使用c++的运行应用程序的屏幕截图最好(最简单)的方法是什么?

3 个解决方案

#1


26  

You have to get the device context of the window (GetWindowDC()) and copy image (BitBlt()) from it. Depending on what else you know about the application you will use different methods to find which window's handle to pass into GetWindowDC().

您必须获得窗口的设备上下文(GetWindowDC())和复制图像(BitBlt())。根据您对应用程序的了解,您将使用不同的方法来查找要传递到GetWindowDC()的窗口句柄。

#2


3  

On the keybd_event function documentation it states that you can use it to take a screenshot and save it to the clipboard. For example:

在keybd_event函数文档中,它声明您可以使用它来获取屏幕截图并将其保存到剪贴板中。例如:

keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_SILENT, 0);

In my version (Visual Studio 2005 help installed on my computer) it states that you can take a screenshot of the whole desktop by setting the second parameter to 0, or a screen shot of just the current application by setting it to 1.

在我的版本(Visual Studio 2005 help安装在我的计算机上)中,它声明您可以通过将第二个参数设置为0来获取整个桌面的屏幕快照,或者通过将当前应用程序设置为1来获取当前应用程序的屏幕快照。

Taking it out of the clipboard buffer is left as an exercise for the reader.

将它从剪贴板缓冲区中取出作为读者的练习。

However I'd think carefully before doing this as it will turf whatever image data was already present in the clipboard.

然而,我在做这之前会仔细考虑,因为它将覆盖剪贴板中已经存在的任何图像数据。

#3


0  

Here is an example code
You can do CaptureAnImage(GetDesktopWindow()); to make a screen capture.

这里有一个示例代码,可以做CaptureAnImage(GetDesktopWindow());做一个屏幕截图。

#1


26  

You have to get the device context of the window (GetWindowDC()) and copy image (BitBlt()) from it. Depending on what else you know about the application you will use different methods to find which window's handle to pass into GetWindowDC().

您必须获得窗口的设备上下文(GetWindowDC())和复制图像(BitBlt())。根据您对应用程序的了解,您将使用不同的方法来查找要传递到GetWindowDC()的窗口句柄。

#2


3  

On the keybd_event function documentation it states that you can use it to take a screenshot and save it to the clipboard. For example:

在keybd_event函数文档中,它声明您可以使用它来获取屏幕截图并将其保存到剪贴板中。例如:

keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_SILENT, 0);

In my version (Visual Studio 2005 help installed on my computer) it states that you can take a screenshot of the whole desktop by setting the second parameter to 0, or a screen shot of just the current application by setting it to 1.

在我的版本(Visual Studio 2005 help安装在我的计算机上)中,它声明您可以通过将第二个参数设置为0来获取整个桌面的屏幕快照,或者通过将当前应用程序设置为1来获取当前应用程序的屏幕快照。

Taking it out of the clipboard buffer is left as an exercise for the reader.

将它从剪贴板缓冲区中取出作为读者的练习。

However I'd think carefully before doing this as it will turf whatever image data was already present in the clipboard.

然而,我在做这之前会仔细考虑,因为它将覆盖剪贴板中已经存在的任何图像数据。

#3


0  

Here is an example code
You can do CaptureAnImage(GetDesktopWindow()); to make a screen capture.

这里有一个示例代码,可以做CaptureAnImage(GetDesktopWindow());做一个屏幕截图。