
Display bitmaps in Print Preview and printing bitmaps.
I'm trying to get BitBlt to draw a bitmap in the OnDraw function so it show
up on the print preview and be printed. The flowing code works in the
View::Paint() to display the bitmap on the screen but not in the
View::OnDraw to be printed. Any help would be appreciated.
CClientDC dc(this); // device context for painting
HBITMAP hbitmap =
::LoadBitmap(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_MYBMP));
// Create a memory DC
HDC hMemDC = :: CreateCompatibleDC(NULL);
// Select the bitmap in the memory dc.
SelectObject(hMemDC,hbitmap);
// Copy the memory dc into the screen dc
int bb = ::BitBlt(dc.m_hDC, //destination
20, //RECTAB[4]
20,
150,
175,
hMemDC, // Source
0,
0,
SRCCOPY);
// Delete the memory DC and the bitmap
::DeleteDC(hMemDC);
::DeleteObject(hbitmap);