Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6475341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:41:34+00:00 2026-05-25T06:41:34+00:00

How to get screenshot of a window as bitmap object in C++? Supposed that

  • 0

How to get screenshot of a window as bitmap object in C++? Supposed that I already have the window handle. And I want to know also whether it’s possible to get the screenshot of a window when it’s in minimized state?

C++ here means VC++ with all the libraries associated with Windows XP+ (win32).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:41:35+00:00Added an answer on May 25, 2026 at 6:41 am

    you should call the PrintWindow API:

    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 this question: getting window screenshot windows API

    if you are not using MFC, here the pure PrintWindow signature:

    BOOL PrintWindow(
        HWND hwnd,
        HDC hdcBlt,
        UINT nFlags
    );
    

    see MSDN for more details: http://msdn.microsoft.com/en-us/library/dd162869(v=vs.85).aspx

    about how to save it as bitmap asMatteo said depends on the actual framework you are using…

    EDIT:

    here full example in raw C++

    #define _WIN32_WINNT    0x0501        //xp
    #include <windows.h>
    
    int main()
    { 
        RECT rc;
        HWND hwnd = FindWindow(TEXT("Notepad"), NULL);    //the window can't be min
        if (hwnd == NULL)
        {
            cout << "it can't find any 'note' window" << endl;
            return 0;
        }
        GetClientRect(hwnd, &rc);
    
        //create
        HDC hdcScreen = GetDC(NULL);
        HDC hdc = CreateCompatibleDC(hdcScreen);
        HBITMAP hbmp = CreateCompatibleBitmap(hdcScreen, 
            rc.right - rc.left, rc.bottom - rc.top);
        SelectObject(hdc, hbmp);
    
        //Print to memory hdc
        PrintWindow(hwnd, hdc, PW_CLIENTONLY);
    
        //copy to clipboard
        OpenClipboard(NULL);
        EmptyClipboard();
        SetClipboardData(CF_BITMAP, hbmp);
        CloseClipboard();
    
        //release
        DeleteDC(hdc);
        DeleteObject(hbmp);
        ReleaseDC(NULL, hdcScreen);
    
        cout << "success copy to clipboard, please paste it to the 'mspaint'" << endl;
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to take a screenshot of a window, and get
With python 3, I'd like to get a handle to another window (not part
I'm trying to get the screenshot of a given URL as a bitmap image
I have these options enabled, as shown in this screenshot: I also have the
I have a C sharp console application that captures a screenshot of a MS
How to get screenshot of WPF application in VC++? In VC++, I have HWND
I use the function PrintWindow to get the screenshot of a certain window. However,
I get a URL from a user. I need to know: a) is the
I have this code: Window w = // something w.Loaded += // some code
is it possible to create a screenshot of a WPF application as SVG /

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.