11/25/2011

Screen capture and save program/ C++ source code


Created Date : 2011.11
Language :C++
Tool : Visual Studio 2008
Library & Utilized : CImage
Reference : Internet
etc. : -



I made this program to help my friend.
This progrma is screen capture program.
At first, we do whole screen capture and set region of screen to capture.
Then start capture and image saving in real-time.
The image file is saved in your program directory.
The file name of the saved image is like that "Time.jpg(EX: 11223242.jpg, 11223243.jpg...)"




The program is made based on below capture program.

#include 
void Capture() 
{ 

   
    int nx =0, ny = 0;
    CImage capImage;
    CWnd *pDesktopWnd = GetDesktopWindow();
    HDC hDC = NULL; 
    if(!pDesktopWnd) 
        return; 
    CWindowDC DeskTopDC(pDesktopWnd); 
    nx = GetSystemMetrics(SM_CXSCREEN);
    ny = GetSystemMetrics(SM_CYSCREEN); 
    if(!capImage.Create(nx, ny, 32))
        return;
    hDC = capImage.GetDC();
    BitBlt(hDC, 0,0, nx, ny, DeskTopDC.m_hDC, 0, 0, SRCCOPY); 
    capImage.Save(_T("test.jpg"), Gdiplus::ImageFormatJPEG); 
    capImage.ReleaseDC();

}


I am hard to make file name of capture image because the progrma requires UNICODE type character.

So I solved this problem as below code.

    int T = time(NULL);
    TCHAR str[100];
    wsprintf(str,_T("%d.jpg"),T);
    ImageTemp.Save(str, Gdiplus::ImageFormatJPEG);     
    ImageTemp.ReleaseDC();

source code