[英]getting window screenshot windows API
I am trying to make a program to work on top of an existing GUI to annotate it and provide extra calculations and statistical information. 我正在尝试使程序在现有GUI上工作以对其进行注释并提供额外的计算和统计信息。 I want to do this using image recognition, as I have learned a fair amount about this in University using Matlab and similar things.
我想使用图像识别来做到这一点,因为我在大学里使用Matlab和类似的东西学到了相当多的东西。 I can get a handle to the window I want to perform image recognition on, but I don't know how to turn that handle into an image of that window, and all its visible child windows.
我可以获得我想要执行图像识别的窗口的句柄,但我不知道如何将该句柄转换为该窗口的图像及其所有可见的子窗口。 I suppose I am looking for something like the screenshot function, but restricted to a single window.
我想我正在寻找像截图功能,但仅限于一个窗口。
How would I go about doing this? 我该怎么做呢? I suppose I'd need something like a .bmp to mess about with.
我想我需要像.bmp这样的东西搞砸了。 Also, it would have to be efficient enough that I could call it several times a second without my PC grinding to a halt.
此外,它必须足够高效,以至于我可以每秒多次调用它而不会让我的PC停止运转。
Hopefully this isn't an obvious question, I typed some things into google but didn't get anything related. 希望这不是一个明显的问题,我在google中键入了一些内容,但没有得到任何相关内容。
One simple way is using the PrintWindow
API (which is an automated Alt + Print basically). 一种简单的方法是使用
PrintWindow
API(基本上是自动Alt + Print)。 The following example takes a screenshot of the calculator, but you would just have to replace the handles. 以下示例获取计算器的屏幕截图,但您只需更换手柄即可。
void CScreenShotDlg::OnPaint()
{
// device context for painting
CPaintDC dc(this);
// Get the window handle of calculator application.
HWND hWnd = ::FindWindow( 0, _T( "Calculator" ));
// Take screenshot.
PrintWindow( hWnd,
dc.GetSafeHdc(),
0 );
}
(see https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-printwindow ) (参见https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-printwindow )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.