I am using GDI+ to take window snapshot, the code is:
CComBSTR bstrfname (fname);
HDC hdc = CreateCompatibleDC (hDC);
HBITMAP hbmp = CreateCompatibleBitmap (hDC, CFG_WIDTH, CFG_HEIGHT);
HBITMAP hbmp0 = (HBITMAP)SelectObject (hdc, hbmp);
BitBlt (hdc, 0, 0, CFG_WIDTH, CFG_HEIGHT, hDC, 0, 0, SRCCOPY);
Gdiplus::Bitmap *bmp = new Gdiplus::Bitmap (hbmp, NULL);
CLSID encoderClsid; GetEncoderClsid (L"image/png", &encoderClsid);
bmp->Save (bstrfname, &encoderClsid, NULL);
delete bmp;
SelectObject (hdc, hbmp0);
DeleteObject (hbmp);
DeleteDC (hdc);
where hDC is set before with:
hWnd=CreateWindowEx(...); hDC=GetDC(hWnd);
this works perfectly for small windows, but once I try windows bigger than screen.
i.e. taskbar is getting saved too. what gives?
This is normal, a screen-shot like this gives you exactly what you are looking at on your monitor. Including the taskbar. You will need to restrict the area you capture to the bounds of the window you want to capture. Use GetWindowRect() and adjust the size of the bitmap and the arguments you pass to BitBlt() accordingly.
PrintWindow can only work if the target window implements the WM_PRINT and WM_PRINTCLIENT message. Easy to implement but often overlooked.