Hello All:
I'm writing to find out if anyone has been able to tell a printer
to print more than one line. I know, it sounds insain, but the
code below works great, except for one minor problem. It refuses
to wrap text when it won't fit on the line, and it prints $CRLF as
2 box-like things instead of going to a new line as it should. Any
ideas? I should mention that I save the printer handle in
LastPrint so when I call the code again, it can use the previous
handle to access the printer. Also, would one of you programming
geniuses mind telling me if the below code is compatible with Windows NT?
Thanks!
-----CODE-----
#compile exe
#include "win32api.inc"
%NOFILEDLG=1
#INCLUDE "COMDLG32.INC"
DECLARE FUNCTION FontMaker (fh&, fw&) AS LONG
GLOBAL LastPrint AS LONG, NewContents AS ASCIIZ*35000
Function pbMain
NewContents="This is a test print to see if the printer will wrap text when it needs to." & $CRLF
NewContents=NewContents & "What's more, it doesn't seem to recognize $CRLF's, either."
Call PrintFile
End Function
FUNCTION PrintFile() AS LONG
LOCAL hPrnDC AS LONG, hOrigFont AS LONG, hdc AS LONG, flags AS LONG,_
hFont AS LONG, di AS DOCINFO, lpSize AS SIZEL, Dud as Long, hWnd&
Dud=0
IF LastPrint=0 THEN
flags = %PD_RETURNDC OR %PD_RETURNDEFAULT
Dud=PrinterDialog(hWnd,flags,hPrnDC,0,0,0,0,0)
LastPrint=hPrnDC
ELSE
hPrnDC=LastPrint
Dud=1
END IF
IF Dud THEN
Dud=16*5
hFont=FontMaker(Dud, Dud)
hOrigFont = SelectObject (hPrnDC, hFont)
GetTextExtentPoint32 hPrnDC, NewContents, 11, lpSize
IF StartDoc(hPrnDC, di) > 0 THEN
IF StartPage(hPrnDC) > 0 THEN
hOrigFont = SelectObject(hPrnDC, hFont)
TextOut hPrnDC, 20, 100, NewContents, LEN(NewContents)
IF EndPage(hPrnDC) > 0 THEN
EndDoc hPrnDC
FUNCTION=1
ELSE
FUNCTION=-3
END IF
ELSE
FUNCTION=-2
END IF
ELSE
FUNCTION=-1
END IF
'DeleteObject SelectObject(hPrnDC, hOrigFont)
'DeleteDC hPrnDC
ELSE
FUNCTION=0
END IF
END FUNCTION
FUNCTION FontMaker(fh&, fw&) AS LONG
DIM Font AS logfont
Font.lffacename="TIMES NEW ROMAN"
Font.lfheight=fh&
Font.lfwidth=fw&
Font.lfitalic=0
Font.lfunderline=0
Font.lfstrikeout=0
Font.lfweight=500
FUNCTION=createfontindirect(Font)
END FUNCTION
Thanks again! Danny.
------------------
[This message has been edited by Danny Faris (edited October 12, 2000).]
I'm writing to find out if anyone has been able to tell a printer
to print more than one line. I know, it sounds insain, but the
code below works great, except for one minor problem. It refuses
to wrap text when it won't fit on the line, and it prints $CRLF as
2 box-like things instead of going to a new line as it should. Any
ideas? I should mention that I save the printer handle in
LastPrint so when I call the code again, it can use the previous
handle to access the printer. Also, would one of you programming
geniuses mind telling me if the below code is compatible with Windows NT?
Thanks!
-----CODE-----
#compile exe
#include "win32api.inc"
%NOFILEDLG=1
#INCLUDE "COMDLG32.INC"
DECLARE FUNCTION FontMaker (fh&, fw&) AS LONG
GLOBAL LastPrint AS LONG, NewContents AS ASCIIZ*35000
Function pbMain
NewContents="This is a test print to see if the printer will wrap text when it needs to." & $CRLF
NewContents=NewContents & "What's more, it doesn't seem to recognize $CRLF's, either."
Call PrintFile
End Function
FUNCTION PrintFile() AS LONG
LOCAL hPrnDC AS LONG, hOrigFont AS LONG, hdc AS LONG, flags AS LONG,_
hFont AS LONG, di AS DOCINFO, lpSize AS SIZEL, Dud as Long, hWnd&
Dud=0
IF LastPrint=0 THEN
flags = %PD_RETURNDC OR %PD_RETURNDEFAULT
Dud=PrinterDialog(hWnd,flags,hPrnDC,0,0,0,0,0)
LastPrint=hPrnDC
ELSE
hPrnDC=LastPrint
Dud=1
END IF
IF Dud THEN
Dud=16*5
hFont=FontMaker(Dud, Dud)
hOrigFont = SelectObject (hPrnDC, hFont)
GetTextExtentPoint32 hPrnDC, NewContents, 11, lpSize
IF StartDoc(hPrnDC, di) > 0 THEN
IF StartPage(hPrnDC) > 0 THEN
hOrigFont = SelectObject(hPrnDC, hFont)
TextOut hPrnDC, 20, 100, NewContents, LEN(NewContents)
IF EndPage(hPrnDC) > 0 THEN
EndDoc hPrnDC
FUNCTION=1
ELSE
FUNCTION=-3
END IF
ELSE
FUNCTION=-2
END IF
ELSE
FUNCTION=-1
END IF
'DeleteObject SelectObject(hPrnDC, hOrigFont)
'DeleteDC hPrnDC
ELSE
FUNCTION=0
END IF
END FUNCTION
FUNCTION FontMaker(fh&, fw&) AS LONG
DIM Font AS logfont
Font.lffacename="TIMES NEW ROMAN"
Font.lfheight=fh&
Font.lfwidth=fw&
Font.lfitalic=0
Font.lfunderline=0
Font.lfstrikeout=0
Font.lfweight=500
FUNCTION=createfontindirect(Font)
END FUNCTION
Thanks again! Danny.
------------------
[This message has been edited by Danny Faris (edited October 12, 2000).]
Comment