Re: Printing using Win32Lib
- Posted by dcole May 25, 2011
- 2375 views
Hello lpuster,
This code works with Windows 7. I got it from one of the demos.
I don't know about special charaters.
Hope this helps.
Don Cole
include win32lib.ew integer junk, linecount, charsPerLine, linesPerPage sequence fontSize, printerSize, text, lineOfText global constant Window1 = create(Window,"Printer Test",0,10,10,300,210,0) global integer PrWin PrWin=Window1 constant MenuP = create(Menu,"&Printer",PrWin,0,0,0,0,0), info= create(MenuItem,"Get Info", MenuP,0,0,0,0,0), PNow = create(MenuItem,"&A demo page !",MenuP,0,0,0,0,0) --=include printer2.ew --^^^^^^^^^^^^^^^--the window and controls -- a long text line procedure get_info(integer a, integer b, sequence p) -- 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 setFont(Printer,"Courier New",16,Normal) 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' --setText(FONT,"Curier New") --setText(FONT_SIZE,"16") --setText(FONT_STYLE,"Normal") --setText(PRINTER_WIDTH,printerSize[1]) --setText(PRINTER_HEIGHT,printerSize[2]) --setText(PRT_CHRW,fontSize[1]) --setText(PRT_CHRH,fontSize[2]) --setText(PRT_CHR_PER,charsPerLine) --setText(PRT_LINES_PER,linesPerPage) end if --setEnable(PRINT_BTN,w32False) --o--penWindow(PREVIEW,Normal) end procedure setHandler(info,w32HClick,routine_id("get_info")) procedure print_now(integer a,integer b,sequence p) -- closeWindow(PREVIEW) -- start up the document if startDoc( "My Print Job" ) then junk = startPage() -- top of page linecount = 0 ----------------------------------put your printing here------------------ for x= 1 to 45 do setPenPos(Printer,0,linecount*fontSize[2]) wPuts( Printer,sprintf("%d",x) ) -- 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 for ------------------------------------------------------------------------------- -- 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,w32HClick,{routine_id("get_info"),routine_id("print_now")}) --setHandler(PNow,w32HClick,routine_id("print_now")) --onClick[PNow] = routine_id("print_now") WinMain(PrWin,Normal)