I have run into weird problem with print preview with certain printer.
I have tested this with NT 4 (sp6) and Win95 with few different
printer drivers each. It works OK in all cases except in Win95 with HP
Deskjet 930 series printer driver.
Here is simplified code for what I'm doing
// ptrName is valid printer name
For Win95:
hPrinterDC=CreateDC(NULL,ptrName,NULL,NULL);
For NT:
hPrinterDC=CreateDC("WINSPOOL",ptrName,NULL,NULL);
if(bPreview) {
hPreviewDC=CreateCompatibleDC(hPrinterDC);
hBitmap=CreateCompatibleBitmap(hPreviewDC,1050,1485);
SelectObject(hPreviewDC,hBitmap);
PatBlt(hPreviewDC,0,0,1050,1485,WHITENESS);
hDC=hPreviewDC;
// Font is already created in this point, so hFont is valid.Quote:} else {
hDC=hPrinterDC;
}
SelectObject(hDC,hFont);
GetTextExtentPoint32(hDC,"X",1,&size);
// Purpose here is to get height of line
Everything works fine until GetTextExtentPoint32. First it caused
protection fault in printer driver. I updated driver and it doesn't
crash anymore, but values returned in size-structure are insane:
size.cx = 0 , and
size.cy = 32767
I have tried using DrawText with DT_CALCRECT instead of
GetTextExtent.... and it returns correct height, but width is still 0
and I need this information elsewhere.
When printing directly (without preview) to printer everything is
fine.
Is there bug in printer driver or am I doing something wrong ?
tv. Jarno Tyynel?
"Nothing is as certain as uncertain"