How can I save the current display to a file? (or screen capture?)

DirectX doesn't provide any default functions to save a screenshot. You can press the "PrintScreen" key after exiting from the application and open "MSpaint", and then select the "Paste" option. That will copy the clipboard into paint. However the problem is that, for each screenshot we have to run the application once. Here is a small solution that will copy the Images from Clipboard when we press a specific key and save it as a sequence starting from ScrnShot0.bmp. "CapScrn.h" uses the windows GDI to copy the current image in clipboard and save it as a 24-bit Bitmap. You can change the bitmap format if you wish :). Just include "CapScrn.h" to your Win32 project and call SaveScreenShot (m_HWnd, Width, Height) where m_HWnd is the handle to the window you wished to capture; Width & Height specifies how much of the clipboard image you wished to save.

E.g. this will pick a FullScreenShot of your current Desktop

if (IsKeyDown (VK_F9))
	   SaveScreenShot (NULL/* this will pass the handle of current desktop window */, 	
			GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN));


FAQ Menu

 
Printer friendly version of the FAQ-DIRECTX-Save-Display-to-File-Or-Screen-Capture page


Sponsored links

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Six Sigma Certification
100% Online-Six Sigma Certificate from Villanova - Find Out More Now.
SSH and SFTP support for .NET
Add complete SSH and SFTP support to your .NET framework application
3 Months Free - ASP.NET Web Hosting
3 Months Free & No Setup Fees on ASP.NET 3.5/2.0 Hosting on Windows 2008/2003 Servers ? Click Here!

Advertisement



Free Magazine

Free Magazines
eWeek The essential technology information source for builders of e-business.... subscribe now

Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.