1. wxPrint
Can someone post a simple (non-win32lib) example of printing to a printer?
Also, I saw wxHtmlEasyPrinting in the wxWidgets doc. How can I get this wrapped
for use in wxEuphoria?
2. Re: wxPrint
Brian Clark wrote:
>
>
> Can someone post a simple (non-win32lib) example of printing to a printer?
> Also, I saw wxHtmlEasyPrinting in the wxWidgets doc. How can I get this
> wrapped
> for use in wxEuphoria?
Hi Brian,
Printing under windows is quite involved, it can't be done in a few lines as the
following demo shows.
And this demo does the very basic as it doesn't implement a cancel dialog as it
should.
It doesn't compute the text metrics and doesn't get all the usefull printer
device capacities needed to format printed text proprerly.
But it works.
-- printing demo
include dll.e
include machine.e
constant gdi32 = open_dll("gdi32.dll")
constant comdlg32 = open_dll("comdlg32.dll")
--constant user32 = open_dll("user32.dll")
constant iDeleteDC = define_c_func(gdi32,"DeleteDC",{C_UINT},C_UINT) --
argument = hdc
constant iPrintDlg = define_c_func(comdlg32,"PrintDlgA",{C_POINTER},C_INT) --
argument is pointer PRINTDLG structure
constant iStartDoc = define_c_func(gdi32,"StartDocA",{C_UINT,C_POINTER},C_INT)
-- argument1 is hdc, argument2 is pointer to DOCINFO
constant iStartPage = define_c_func(gdi32,"StartPage",{C_UINT},C_INT) --
argument is printer hdc
constant iEndPage = define_c_func(gdi32,"EndPage",{C_UINT},C_INT) -- argument
is printer hdc
constant iEndDoc = define_c_func(gdi32,"EndDoc",{C_UINT},C_INT) -- argument
is printer hdc
constant iGetDeviceCaps =
define_c_func(gdi32,"GetDeviceCaps",{C_UINT,C_INT},C_INT) -- argument1 is printer
hdc, argument2 one of dev. cap. constant
constant iTextOut =
define_c_func(gdi32,"TextOutA",{C_UINT,C_INT,C_INT,C_POINTER,C_INT},C_INT) --
hdc, x,y, pString, nChar
constant PDLG_SIZE = 66 -- PRINTDLG structure size
constant PD_USEDEVMODECOPIESANDCOLLATE=262144,PD_RETURNDC= 256
constant DOCINFO_SIZE = 20
constant HORZRES =8 , VERTRES = 10, LOGPIXELSY = 90
function GetDeviceCaps(atom hdc, atom Cap)
return c_func(iGetDeviceCaps,{hdc,Cap})
end function
procedure StartDoc(atom hdc, sequence DocTitle)
object fnVal, pDocInfo, pTitle
pTitle = allocate_string(DocTitle)
pDocInfo = allocate(DOCINFO_SIZE)
mem_set(pDocInfo,0,DOCINFO_SIZE)
poke4(pDocInfo,DOCINFO_SIZE)
poke4(pDocInfo+4,pTitle)
fnVal = c_func(iStartDoc,{hdc,pDocInfo})
free(pTitle)
free(pDocInfo)
end procedure
procedure StartPage(atom hdc)
object fnVal
fnVal = c_func(iStartPage,{hdc})
end procedure
procedure EndPage(atom hdc)
object fnVal
fnVal = c_func(iEndPage,{hdc})
end procedure
procedure EndDoc(atom hdc)
object fnVal
fnVal = c_func(iEndDoc,{hdc})
end procedure
procedure TextOut(atom hdc,integer x, integer y, sequence text)
atom fnVal, pText
pText = allocate_string(text)
fnVal = c_func(iTextOut,{hdc,x,y,pText,length(text)})
free(pText)
end procedure
function PrinterSelect() -- this return the display context of printer.
atom fnVal,pPRINTDLG, hPrinterHdc
pPRINTDLG= allocate(PDLG_SIZE)
mem_set(pPRINTDLG,0,PDLG_SIZE)
poke4(pPRINTDLG,PDLG_SIZE)
poke4(pPRINTDLG+20,or_bits(PD_USEDEVMODECOPIESANDCOLLATE,PD_RETURNDC)) --
Flags
fnVal = c_func(iPrintDlg,{pPRINTDLG})
hPrinterHdc = 0
if fnVal then
hPrinterHdc = peek4u(pPRINTDLG+16)--PRINTDLG.hdc
end if
free(pPRINTDLG)
return hPrinterHdc
end function
constant TEXT="The quick brown fox jump over the lazy dog"
object void
integer vppi -- printer pixel per inch vertical
atom hPrnDc
-- 1) let the user select printer
hPrnDc = PrinterSelect()
if hPrnDc then
-- 2) Get printer vertical resolution in pixel per inch.
vppi = GetDeviceCaps(hPrnDc,LOGPIXELSY)
-- 3) open document
StartDoc(hPrnDc,"printing demo")
StartPage(hPrnDc)
-- 4) Begin a new page
StartPage(hPrnDc)
-- 5) send data to printer
for i = 1 to 10 do -- print 10 lines of text 6 lines per inches
TextOut(hPrnDc,10,i*vppi/6,TEXT)
end for
-- 6) end page
EndPage(hPrnDc)
-- 7) Close Document
EndDoc(hPrnDc)
-- 8) release printer DC
void = c_func(iDeleteDC,{hPrnDc})
end if
regards,
Jacques Deschênes
3. Re: wxPrint
Thanks Jacques. Wow! Since the days of VB1.0 it seems sending output to the
printer has always been the hardest part.
jacques deschênes wrote:
>
> Brian Clark wrote:
> >
> >
> > Can someone post a simple (non-win32lib) example of printing to a printer?
> > Also, I saw wxHtmlEasyPrinting in the wxWidgets doc. How can I get this
> > wrapped
> > for use in wxEuphoria?
>
> Hi Brian,
> Printing under windows is quite involved, it can't be done in a few lines as
> the following demo shows.
> And this demo does the very basic as it doesn't implement a cancel dialog as
> it should.
> It doesn't compute the text metrics and doesn't get all the usefull printer
> device capacities needed to format printed text proprerly.
> But it works.
snip
> regards,
> Jacques Deschênes
4. Re: wxPrint
Brian Clark wrote:
>
> Can someone post a simple (non-win32lib) example of printing to a printer?
> Also, I saw wxHtmlEasyPrinting in the wxWidgets doc. How can I get this
> wrapped
> for use in wxEuphoria?
I'll add wxHtmlEasyPrinting to the top of the TODO list. It should make the
next release--looks like a fairly simple class.
Printing is broken in the current version of wxEuphoria. In the next release
(or, if you build from the head of the svn repository) you could do
the following (trivial, hello world print example):
include wxeud.e
function my_print( atom printout, integer page_num, atom dc )
wx_puts( {printout, 10, 10, dc }, "Hello, World" )
return 1
end function
constant
printout = create( wxPrintout, {"Hello World", routine_id( "my_print" )}),
printer = create( wxPrinter, get_print_data( create( wxPrintDialog, {} ) ) )
set_page_info( printout, 1, 1 )
? start_print( printer, 0, printout, 1 )
Matt
5. Re: wxPrint
Matt Lewis wrote:
> I'll add wxHtmlEasyPrinting to the top of the TODO list. It should make the
> next release--looks like a fairly simple class.
>
Thanks Matt
The wxHtmlEasyPrinting widget should make formatting text for the printer,
well...easy. Looking forward to it.
B