tags:

views:

59

answers:

1
HDC hdcScreen = GetDC(NULL);
HDC hdcWindow = GetDC(mWin);
HDC hdcMem = CreateCompatibleDC(hdcScreen);
if (!hdcScreen || !hdcWindow || !hdcMem){
 MessageBox(NULL, "could not locate hdc's", "Viewer", MB_ICONERROR);
}

if (!StretchBlt(hdcMem, 0, 0, 300, 300, hdcScreen, 0, 0, 300, 300, SRCCOPY)){
 MessageBox(NULL, "stretchblt failed", "Viewer", MB_ICONERROR);
}
else if (!BitBlt(hdcWindow, 0, 0, 300, 300, hdcMem, 0, 0, SRCCOPY)){
 // error
 MessageBox(NULL, "stretchblt failed", "Viewer", MB_ICONERROR);
}

ReleaseDC(NULL, hdcScreen);
ReleaseDC(mWin, hdcWindow);
ReleaseDC(mWin, hdcMem);

A single call to StretchBlt from Screen to Window works fine, but the above does not. Any helpful tips?

[Edit] No errors are triggered, so everything seems to work fine, however the window associated with mWin is blank.

+3  A: 

You need to create a bitmap and select it into the memory DC using SelectObject.

interjay
That worked!HBITMAP hBit = CreateCompatibleBitmap(hdcWindow, 300, 300); \SelectObject(hdcMem, hBit); \..DeleteObject(hBit);
Default
Yes. Fix your cleanup code too, ReleaseDC(mWin, hdcMem) is wrong. Use DeleteDC(). And you have to restore the old bitmap for hdcMem before deleting it.
Hans Passant