Re: Printing using Win32Lib
- Posted by dcole May 27, 2011
- 2304 views
Selgor said...
Selgor here Don...... Which Demo did you get "it" .. the proggie from ?? Read You to-morrow.
Cheers, Selgor.
Hello Signor,
I found it in an old folder in the archives called euWinTutor.
I don't see it there anymore. This is probably because it uses onClick (no longer used).
It must be changed setHandler as I did in my last post in this thread.
There are 2 files pr123.exw,
-- pr123.exw by Wolf. include win32lib.ew include printws.ew without warning -- create the window and menu. constant MenuWin = create(Window,"Print Demo",0,Default,Default,340,130,0), PopupFile = create(Menu,"&File",MenuWin,0,0,0,0,0), MenuPrint = create(MenuItem,"&Print",PopupFile,0,0,0,0,0), MenuSep1 = create(MenuItem,"-",PopupFile,0,0,0,0,0), MenuExit = create(MenuItem,"E&xit",PopupFile,0,0,0,0,0), PopupHelp = create(Menu,"&Help",MenuWin,0,0,0,0,0), MenuAbout = create(MenuItem,"&About",PopupHelp,0,0,0,0,0), Dummy = create(Menu," -prints 3 pages thru FILE,PRINT-",MenuWin,0,0,0,0,0) setFont( MenuWin,"Courier New",10,1) procedure onMenu_MenuAbout() integer result result = message_box("Win32Lib Print Demo, prints itself !", "HELLO !",#2000) end procedure onClick[MenuAbout] = routine_id("onMenu_MenuAbout") integer Handle object line procedure print_stuff(sequence a) --a is filename atom myphdc, i, j, charheight, width, hor, ver sequence mypr, textinfo, string1 mypr=DefaultPrinterName() myphdc=GetPrinterDC(mypr) textinfo=GetTextMetrics(myphdc) charheight=textinfo[1]+1 --character height+1, <this is optional --using textinfo[1] only, allows characters to "touch" --might be useful for DOS'like graphics width=textinfo[2] --character width hor=GetDeviceCaps(myphdc,8) --page width ver=GetDeviceCaps(myphdc,10) --page length setPenPos(MenuWin,0,1) string1= " character height = " & sprintf("%d",textinfo[1]) & " + 1 extra" wPuts(MenuWin,string1) setPenPos(MenuWin,0,18) string1= " character width = " & sprintf("%d",width) wPuts(MenuWin,string1) setPenPos(MenuWin,0,36) string1= " total page height = " & sprintf("%d",ver) wPuts(MenuWin,string1) setPenPos(MenuWin,0,54) string1= " total page width = " & sprintf("%d",hor) wPuts(MenuWin,string1) i=StartDoc(myphdc, a ) --a bit of fooling around... i=StartPage(myphdc) pTextOut(myphdc,150,70,"An Example") pTextOut(myphdc,400,140,"of placing stuff") pTextOut(myphdc,20*width,400,"wherever") pTextOut(myphdc,28*width,408," you want..") pTextOut(myphdc,10*width,400+4*charheight,"within the page extents.") pTextOut(myphdc,floor(hor/2-(8*width)),floor(ver/2-(charheight/2)), "near the middle.") pTextOut(myphdc,50,floor(ver-(8*charheight)),"end of page one.") i=EndPage(myphdc) --end of fooling... i=StartPage(myphdc) Handle=open( a ,"r") j=charheight*4 --some empty space while 1 do line=gets(Handle) if atom(line) then exit end if line=line[1..(length(line)-1)] --remove line feed. --max. char. per line ?? --so do parsing here, using "hor/width=maxx" --or the end of your line will "disappear" if j > ver-charheight*8 then --close to bottom? i=EndPage(myphdc) i=StartPage(myphdc) --next page j=charheight*4 --reset line count end if --careful here, I think this only likes integers. pTextOut(myphdc,0,j,line ) j=j+charheight --increment line count end while close(Handle) i=EndPage(myphdc) --eject page i=EndDoc(myphdc) --and close DeleteDC(myphdc) end procedure procedure onMenu_MenuExit() closeWindow(MenuWin) end procedure onClick[MenuExit] = routine_id("onMenu_MenuExit") procedure onMenu_MenuPrint() print_stuff("pr123.exw") --if it ain't there,CRASH. end procedure onClick[MenuPrint] = routine_id("onMenu_MenuPrint") WinMain(MenuWin,Normal) ----
and pr234.exw
include win32lib.ew integer junk, linecount, charsPerLine, linesPerPage, halfx, halfy sequence fontSize, printerSize, text, lineOfText constant PrWin = create(Window,"Another Win32lib 'print'",0,10,10,300,210,0), MenuP = create(Menu,"&Print",PrWin,0,0,0,0,0), PNow = create(MenuItem,"&A demo page !",MenuP,0,0,0,0,0) -- a long text line text = "I have been working on this tutorial since October of 1998, " & "starting with Win32lib version 0.15c, " & "and even though David added some 'wrappers' to Win32lib.ew for " & "printing " & "quite some time ago, " & "( in version 0.43e, Oct./99 ), it has taken me this long to finally " & "get around to using *his* functions " & "in a tutorial example !" procedure get_info() -- open the printer dialog -- then, IF the user has selected a printer... if length(getPrinter()) > 0 then -- pick a big fixed width font setFont( Printer, "Courier New", 24, Normal ) -- get the font metrics fontSize = getFontSize( Printer ) -- get the size of a printer page printerSize = getCtlSize( Printer ) -- how many characters can fit on a line? charsPerLine = floor(printerSize[1]/fontSize[1]) -- how many lines can fit on a page? linesPerPage = floor(printerSize[2]/fontSize[2]) -- report all the printer's 'metrics' setPenPos(PrWin,10,10) wPuts(PrWin,"...using the \"Courier New\", size 24 font.") setPenPos(PrWin,10,30) wPuts(PrWin,"character width = " & sprintf("%d",fontSize[1])) setPenPos(PrWin,10,50) wPuts(PrWin,"character height = " & sprintf("%d",fontSize[2])) setPenPos(PrWin,10,70) wPuts(PrWin,"characters per line = " & sprintf("%d",charsPerLine)) setPenPos(PrWin,10,90) wPuts(PrWin,"lines per page = " & sprintf("%d",linesPerPage)) setPenPos(PrWin,10,120) wPuts(PrWin,"page 'pixel' width = " & sprintf("%d",printerSize[1])) setPenPos(PrWin,10,140) wPuts(PrWin,"page 'pixel' height = " & sprintf("%d",printerSize[2])) end if end procedure procedure print_now() get_info() -- start up the document if startDoc( "My Print Job" ) then junk = startPage() -- top of page linecount = 0 -- print until long text line is empty while length( text ) do -- get a line of text if length( text ) < charsPerLine then -- get remaining text lineOfText = text text = "" else -- get one 'printer line' of text lineOfText = text[1..charsPerLine] -- remove from remaining text text = text[charsPerLine+1..length(text)] -- is first character of line a space ? if equal(lineOfText[1], ' ') then lineOfText = lineOfText[2..length(lineOfText)] if length(text) > 0 then lineOfText = lineOfText & text[1] end if if length(text) > 1 then text = text[2..length(text)] end if end if end if -- position text on page setPenPos( Printer, 0, linecount*fontSize[2] ) -- write the text wPuts( Printer,lineOfText ) -- move down one line linecount += 1 -- at bottom of page? if linecount > linesPerPage then -- print page if not endPage() then exit end if -- start a new page if not startPage() then exit end if -- reset counter linecount = 0 end if end while -- shucks, we know we haven't printed a full page yet... -- so let's throw in some graphics, OK ? -- draw a fat line half-way down the page. halfy = floor(printerSize[2] / 2) setPenWidth(Printer,5) drawLine(Printer,0,halfy,printerSize[1],halfy) -- draw a fat line at the bottom of the page. setPenWidth(Printer,5) drawLine(Printer,0,printerSize[2]-5,printerSize[1],printerSize[2]-10) -- then draw a circle of size 50, at 20 by 20 below the top line. setPenWidth( Printer,1 ) drawEllipse( Printer, True, -- fill the circle 20, halfy + 25, -- start x,y 20 + 50, halfy + 25 + 50 ) -- end x,y -- then add a line of smaller text after the circle. setFont( Printer, "Courier New", 16, Bold ) setPenPos( Printer, 100, halfy + 25 ) wPuts( Printer, "This makes a BIG point !" ) -- then add a big empty circle with a '400' diameter. halfx = floor(printerSize[1] / 2) setPenWidth( Printer, 4 ) drawEllipse( Printer, False, -- don't fill the circle. halfx - 200, halfy + 100, -- start x,y halfx + 200, halfy + 100 + 400 ) -- end x,y -- with a check-mark near the center. setPenWidth( Printer, 8 ) drawLine( Printer, halfx-50, halfy+300, halfx, halfy+405 ) setPenWidth( Printer, 12 ) drawArc( Printer, False, halfx, halfy+405-600, halfx+600, halfy+405+600, halfx+200, halfy-100, halfx, halfy+400) -- then, finally, send the page to the printer junk=endPage() -- so, this ends our 'shucks' graphics demonstration. end if -- end of document if endDoc() then -- release the printer releasePrinter() end if end procedure setHandler(PNow onClick[PNow] = routine_id("print_now")--this has to e changed here as I did in my last post that sent WinMain(PrWin,Normal)
They won't work with out some work.
Don Cole