#include <windows.h>
#include <atlimage.h>
const int SCREENW = GetSystemMetrics(SM_CXSCREEN);
const int SCREENH = GetSystemMetrics(SM_CYSCREEN);
int main()
{
HWND hdesktopwnd = GetDesktopWindow();
HDC hdesktopdc = GetDC(hdesktopwnd);//CreateDC("DISPLAY",NULL,NULL,NULL);
HDC hmemdc = CreateCompatibleDC(hdesktopdc);
HBITMAP hmembmp = CreateCompatibleBitmap(hdesktopdc, SCREENW, SCREENH);
SelectObject(hmemdc, hmembmp);
BitBlt(hmemdc, 0, 0, SCREENW, SCREENH, hdesktopdc, 0, 0, SRCCOPY);
CImage img;
img.Attach(hmembmp);
img.Save("result.jpg");
ReleaseDC(hdesktopwnd, hdesktopdc);
DeleteObject(hmembmp);
DeleteDC(hmemdc);
return 0;
}