Printer driver problem
The code below works OK on all the printers it has been tested on
except my new Brother 1250 laser printer. The problem is that
the printer does not 'accept' the generated font, and insists on
printing out in a default Courier 12pt font. I am at a complete
loss as to how to correct this - Brother have been very helpful
over other printing problems, but not this one (though I cannot
blame them!!). I see from Win32Help that PrintDLg is no longer a
preferred function, but would rather have PageSetupDlg - but in
this case, I cannot see how to send a required font to the
printer. I cannot use ESC codes, as this must work for all
printers that run the program, and therefore the correcions must
be in this code.
Help!
Iain Johnstone
Extract of code:-
openDefaultPrinter
openPrinter pPrinterName, hPrinter, pdefs
Printer_hDC = CreateDC(lpDriverName, pPrinterName, BYVAL %Null,BYVAL %Null)
PrnWidth = GetDeviceCaps(Printer_hDC, %PHYSICALWIDTH)
PrnHeight = GetDeviceCaps(Printer_hDC, %PHYSICALHEIGHT)
NoPrnWidth = GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETX)
NoPrnHeight = GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETY)
r.nLeft=NoPrnWidth '50
r.nTop = NoPrnHeight '50
r.nRight =PrnHeight-NoPrnHeight 'landscape
r.nBottom =PrnWidth-NoPrnWidth '3000
IF ISTRUE openPrinter(BYCOPY pPrinterName, hPrt, BYVAL %NULL) THEN
dwNeeded = DocumentProperties(hDlg, hPrt, BYCOPY pPrinterName, BYVAL %NULL, BYVAL %NULL, 0)
pDevMode = SPACE$(dwNeeded)
devPtr = STRPTR(pDevMode)
dwRet = DocumentProperties(hDlg, hPrt, BYCOPY pPrinterName, BYVAL devPtr, BYVAL %NULL, %DM_OUT_BUFFER)
IF dWret <> %IDOK THEN
pDevMode = ""
closePrinter hPrt
ELSE
DocumentProperties hDlg, hPrt, BYCOPY pPrinterName, BYVAL devPtr, BYVAL %NULL, %DM_OUT_BUFFER
@devPtr.dmOrientation = %DMORIENT_LANDSCAPE
END IF
DocumentProperties hDlg, hPrt, BYCOPY pPrinterName, BYVAL devPtr, BYVAL devPtr, %DM_OUT_BUFFER OR %DM_IN_BUFFER
ClosePrinter hPrt
END IF
' Setup the print common dialog
prdInfo.lStructSize = LEN(prdInfo)
prdInfo.hwndOwner = hDlg
prdInfo.hDevMode = devPtr
prdInfo.hDevNames = %NULL
prdInfo.nFromPage = 1
'prdInfo.nToPage = 0
prdInfo.nMinPage = 0
prdInfo.nMaxPage = 0
prdInfo.nCopies = 0
prdInfo.hInstance = hInst
prdInfo.Flags = %PD_NOPAGENUMS OR %PD_RETURNDC OR %PD_PRINTSETUP
prdInfo.lpfnSetupHook = %NULL
prdInfo.lpPrintSetupTemplateName = %NULL
prdInfo.lpfnPrintHook = %NULL
prdInfo.lpPrintTemplateName = %NULL
'- Fill dInfostructure
zstring="Masterdrain - Printing "
dInfo.cbSize = LEN(dInfo)
dInfo.lpszDocName = VARPTR(zString)
dInfo.lpszOutput = %NULL
IF PrintDlg (prdInfo) THEN
SetCursor LoadCursor( %NULL, BYVAL %IDC_WAIT )
'Set default font for printer
Font="Courier New":PointSize=9
CyPixels = GetDeviceCaps (prdInfo.hDC,%LOGPIXELSY)
hFont= MakeFont (Font, PointSize,CyPixels) 'hfont is always >0
SelectObject prdInfo.hDc, hFont 'this returns a number >0 if tested
StartDoc prdInfo.hDC, dInfo
StartPage prdInfo.hDC
DrawTextEx prdInfo.hDC, PrintString1, -1, r, %DT_LEFT OR %DT_WORDBREAK,BYVAL %NULL
EndPage prdInfo.hDC
etc,etc........................
------------------
The code below works OK on all the printers it has been tested on
except my new Brother 1250 laser printer. The problem is that
the printer does not 'accept' the generated font, and insists on
printing out in a default Courier 12pt font. I am at a complete
loss as to how to correct this - Brother have been very helpful
over other printing problems, but not this one (though I cannot
blame them!!). I see from Win32Help that PrintDLg is no longer a
preferred function, but would rather have PageSetupDlg - but in
this case, I cannot see how to send a required font to the
printer. I cannot use ESC codes, as this must work for all
printers that run the program, and therefore the correcions must
be in this code.
Help!
Iain Johnstone
Extract of code:-
openDefaultPrinter
openPrinter pPrinterName, hPrinter, pdefs
Printer_hDC = CreateDC(lpDriverName, pPrinterName, BYVAL %Null,BYVAL %Null)
PrnWidth = GetDeviceCaps(Printer_hDC, %PHYSICALWIDTH)
PrnHeight = GetDeviceCaps(Printer_hDC, %PHYSICALHEIGHT)
NoPrnWidth = GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETX)
NoPrnHeight = GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETY)
r.nLeft=NoPrnWidth '50
r.nTop = NoPrnHeight '50
r.nRight =PrnHeight-NoPrnHeight 'landscape
r.nBottom =PrnWidth-NoPrnWidth '3000
IF ISTRUE openPrinter(BYCOPY pPrinterName, hPrt, BYVAL %NULL) THEN
dwNeeded = DocumentProperties(hDlg, hPrt, BYCOPY pPrinterName, BYVAL %NULL, BYVAL %NULL, 0)
pDevMode = SPACE$(dwNeeded)
devPtr = STRPTR(pDevMode)
dwRet = DocumentProperties(hDlg, hPrt, BYCOPY pPrinterName, BYVAL devPtr, BYVAL %NULL, %DM_OUT_BUFFER)
IF dWret <> %IDOK THEN
pDevMode = ""
closePrinter hPrt
ELSE
DocumentProperties hDlg, hPrt, BYCOPY pPrinterName, BYVAL devPtr, BYVAL %NULL, %DM_OUT_BUFFER
@devPtr.dmOrientation = %DMORIENT_LANDSCAPE
END IF
DocumentProperties hDlg, hPrt, BYCOPY pPrinterName, BYVAL devPtr, BYVAL devPtr, %DM_OUT_BUFFER OR %DM_IN_BUFFER
ClosePrinter hPrt
END IF
' Setup the print common dialog
prdInfo.lStructSize = LEN(prdInfo)
prdInfo.hwndOwner = hDlg
prdInfo.hDevMode = devPtr
prdInfo.hDevNames = %NULL
prdInfo.nFromPage = 1
'prdInfo.nToPage = 0
prdInfo.nMinPage = 0
prdInfo.nMaxPage = 0
prdInfo.nCopies = 0
prdInfo.hInstance = hInst
prdInfo.Flags = %PD_NOPAGENUMS OR %PD_RETURNDC OR %PD_PRINTSETUP
prdInfo.lpfnSetupHook = %NULL
prdInfo.lpPrintSetupTemplateName = %NULL
prdInfo.lpfnPrintHook = %NULL
prdInfo.lpPrintTemplateName = %NULL
'- Fill dInfostructure
zstring="Masterdrain - Printing "
dInfo.cbSize = LEN(dInfo)
dInfo.lpszDocName = VARPTR(zString)
dInfo.lpszOutput = %NULL
IF PrintDlg (prdInfo) THEN
SetCursor LoadCursor( %NULL, BYVAL %IDC_WAIT )
'Set default font for printer
Font="Courier New":PointSize=9
CyPixels = GetDeviceCaps (prdInfo.hDC,%LOGPIXELSY)
hFont= MakeFont (Font, PointSize,CyPixels) 'hfont is always >0
SelectObject prdInfo.hDc, hFont 'this returns a number >0 if tested
StartDoc prdInfo.hDC, dInfo
StartPage prdInfo.hDC
DrawTextEx prdInfo.hDC, PrintString1, -1, r, %DT_LEFT OR %DT_WORDBREAK,BYVAL %NULL
EndPage prdInfo.hDC
etc,etc........................
------------------
Comment