Click to See Complete Forum and Search --> : BitBlting on a printer hdc


GrahamRounce
August 2nd, 2005, 09:06 AM
Hi - I've been a few days trying to debug this problem, and have made it show up "to order" in the following code, which looks like it can't be wrong to me, but.... (I get the printer hdc from PrintDlg):

if ( (GetDeviceCaps(hDC,RASTERCAPS) & RC_BITBLT) == RC_BITBLT ) {
MessageBox(NULL, "BitBlt supported", textString, MB_OK);

TextOut( hDC, 75, 150, "FROMHERE", 8);
if (!BitBlt( hDC, 0, 0, 121, 52, hDC, 75, 150, SRCCOPY)) {
sprintf(debBuf, "BitBlt failed. Last error=%d", GetLastError());
MessageBox(NULL, debBuf, textString, MB_OK);
} else {
MessageBox(NULL, "BitBlt was OK", textString, MB_OK);
}
}

It should copy the "FROMHERE" to the top left corner of the page, but I get the "BitBlt failed" message box - but with a Last Error of zero!

(This does work though:
TextOut(hDC, 0, 0, "FROMHERE", 8);
but I need to do the BitBlting, and StretchBlting, too, if I can get that far!)

Thanks for any help,

Graham

olivthill
August 2nd, 2005, 01:01 PM
My hypotheses are:

- The printer might allow bitblting from an external DC to the printer's DC, but not from the printer's DC to itself.
- The printer might not allow bitblting anything at the 0,0 location because of its margins.
- The printer's DC is not big enough for the width and heigth you gave. Sometimes, the printer's logical units are not what you expect, and you might have to call GetMapMode and SetMapMode.

GrahamRounce
August 2nd, 2005, 02:02 PM
The first one looks possible! I didn't know there were separate enables for to and from the printer DC. Maybe I can print and BitBlt to it, but not BitBlt from it. How can I check that?
Thanks v much,

Roger Allen
August 3rd, 2005, 08:09 AM
Actually its probably due to the printer DC not supporting BitBlt.

In MFC you see this where it works for print preview (A screen DC support BitBlt) and not for the rendered output (the printer DC does not support bitBlt).

If you write your code to make use of StretchDIBits() you should find that this function works for all DCs.

GrahamRounce
August 3rd, 2005, 11:50 AM
But according to GetDeviceCaps, BitBlt IS supported! I can TextOut to the printer DC, or I can make a temporary memory DC, TextOut into it, then BitBlt its contents into the printer DC and it all works fine, but it seems I can't BitBlt FROM the printer DC to the temporary one.... Can the printer DC be only "one way", as far as BitBlt is comcerned?
Thanks,