Archive for July 14, 2008
How to capture the screenshot of window?
4![]()
We’re familear with PrintScreen and Alt+PrintScreen shortcuts. They are used to take the screenshot of entire desktop or a particular window. Well, Is it possible to take the snapshot of a particular control or a particular window by yourself?
![]()
You can use the api – PrintWindow(). If you provide the window handle, the screenshot of the window will be drawn to the provided device context. See the screenshot application which captures the screenshot of calculator application.

See the code snippet.
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 );
}
![]()
The PrintWindow() is available only from XP onwards. So for getting this compiled, you’ve to add _WIN32_WINNT=0×0501 to preprocessor definitions in project settings.
Also check WM_PRINT message, which is more or less same as PrintWindow().
![]()
Targeted Audience – Beginners.