아래 함수를 만들어주고 ScreenSave(CWnd*m_wnd,CString fileName)으로 호출을 하면 파일명_날짜시간으로 저장된다.

ScreenSave(this, 경로명)으로 하면된다.

void ScreenSave(CWnd*m_wnd,CString fileName)
{
	CWnd* pWndDesktop = m_wnd->GetDesktopWindow();
	CWindowDC ScrDC(pWndDesktop);
	CClientDC dc(m_wnd);
	CRect Rect;
	CImage Image;

	m_wnd->GetClientRect(&Rect);
	m_wnd->GetWindowRect(&Rect);
	int sx = Rect.left;
	int sy = Rect.top;
	int cx = Rect.Width();
	int cy = Rect.Height();

	Image.Create(cx, cy, ScrDC.GetDeviceCaps(BITSPIXEL));
	CDC* pDC = CDC::FromHandle(Image.GetDC());
	pDC->BitBlt(0, 0, cx, cy, &ScrDC, sx, sy, SRCCOPY);
	Image.ReleaseDC();
	CTime time = CTime::GetCurrentTime();
	CString str;
	str.Format("%s_%s.jpg", fileName, time.Format("%Y%m%d_%H%M%S"));	//파일 생성날짜시간
	Image.Save(str, Gdiplus::ImageFormatJPEG);

+ Recent posts