HWND hwnd = ::GetDesktopWindow();
HDC hDC = ::GetDC(hwnd);
RECT rect;
::GetClientRect(hwnd, &rect);
HDC hdcMem = ::CreateCompatibleDC(hDC);
HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, rect.right, rect.bottom);
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hdcMem, hBitmap);
::BitBlt(hdcMem, 0, 0, rect.right, rect.bottom, hDC, 0, 0, SRCCOPY);
CImage img;
img.Attach(hBitmap);
img.Save(L"D:/output.bmp");
img.Detach();
::SelectObject(hdcMem, hOldBitmap);
::DeleteObject(hBitmap);
::DeleteDC(hdcMem);
::DeleteDC(hDC);