获取窗口截图窗口API [英] getting window screenshot windows API

查看:752
本文介绍了获取窗口截图窗口API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图制作一个程序,在现有的图形用户界面之上工作,以对其进行注释并提供额外的计算和统计信息。我想用图像识别来做这件事,因为我已经在使用Matlab和类似的东西在大学里学到了相当多的东西。我可以得到一个窗口的句柄,我想要执行图像识别,但我不知道如何将该句柄转换为该窗口的图像及其所有可见的子窗口。我想我正在寻找类似截图功能的东西,但只限于一个窗口。



我该如何去做这件事?我想我会需要像.bmp这样的东西来搞砸。此外,它必须足够高效,以至于我可以一秒钟拨几次电话,而不会让我的电脑停下来。



希望这不是一个明显的问题,我在google中输入了一些东西,但没有得到任何相关的信息。 一种简单的方法是使用 PrintWindow API(基本上是一个自动的Alt + Print)。以下示例使用计算器的屏幕截图,但您只需更换句柄。

  void CScreenShotDlg :: OnPaint( )
{
//设备上下文绘制
CPaintDC dc(this);

//获取计算器应用程序的窗口句柄。
HWND hWnd = :: FindWindow(0,_T(Calculator));

//截屏。
PrintWindow(hWnd,
dc.GetSafeHdc(),
0);

(见 http://weseetips.com/2008/07/14/how-to-capture-the-screenshot -of-window /


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. I want to do this using image recognition, as I have learned a fair amount about this in University using Matlab and similar things. 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. Also, it would have to be efficient enough that I could call it several times a second without my PC grinding to a halt.

Hopefully this isn't an obvious question, I typed some things into google but didn't get anything related.

解决方案

One simple way is using the PrintWindow API (which is an automated Alt + Print basically). 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 http://weseetips.com/2008/07/14/how-to-capture-the-screenshot-of-window/ )

这篇关于获取窗口截图窗口API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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