bvCreateDcForStretchBlt
This helper function creates a device context for bitmap stretching.
BESTVIEWAPI(HDC) bvCreateDcForStretchBlt();
Return value: a handle of device context.
Notes:
This function is used to fix a strange bug which happens sometimes with
printer's device context. Let us imagine a situation when we want to draw a
bitmap on the printer using StretchBlt() function:
HDC dc; // printer's device context, has been initialized somewhere
int ires(0);
HDC dc2=::CreateCompatibleDC(dc);
HBITMAP hOldBitmap=(HBITMAP) ::SelectObject(dc2,m_hBitmap);
ires=::StretchBlt(dc,x,y,w,h,dc2,0,0,BitmapDesc.bmWidth,BitmapDesc.bmHeight,SRCCOPY);
::SelectObject(dc2,hOldBitmap);
::DeleteDC(dc2);
The idea is clear, this is the standart way to stretch bitmaps in MS
Windows. But the problem is that, on some printers, this code does
not work. ires is OK but there is no bitmap on the paper.
Hovewer, if we change the code in the next way:
HDC dc; // printer's device context, has been initialized somewhere
int ires(0);
HDC _dc2=::CreateDC(_T("DISPLAY"),0,0,0);
HDC dc2=::CreateCompatibleDC(_dc2);
::DeleteDC(_dc2);
HBITMAP hOldBitmap=(HBITMAP) ::SelectObject(dc2,m_hBitmap);
ires=::StretchBlt(dc,x,y,w,h,dc2,0,0,BitmapDesc.bmWidth,BitmapDesc.bmHeight,SRCCOPY);
::SelectObject(dc2,hOldBitmap);
::DeleteDC(dc2);
it works very well. Here the display HDC is used as temporary. So, to not to
write such code every time this function was written. Below is the source code
of the bvCreateDcForStretchBlt() function:
BESTVIEWAPI(HDC) bvCreateDcForStretchBlt()
{
HDC _dc=CreateDC(_T("DISPLAY"),0,0,0);
HDC dc=CreateCompatibleDC(_dc);
DeleteDC(_dc);
return dc;
}