getting window screenshot windows API

后端 未结 2 1378
感情败类
感情败类 2021-01-03 02:47

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 reco

相关标签:
2条回答
  • 2021-01-03 02:55

    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 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-printwindow )

    0 讨论(0)
  • 2021-01-03 03:08

    I think CImage class will be helpful.

    void CreateImage(HWND hwnd)
    {
        CImage img;
        img.m_hDC = ::GetWindowDC(hwnd);
        img.Save(strFileName);
    }
    
    0 讨论(0)
提交回复
热议问题