1. [Win32Lib] stretchBlt a virtual window to Printer?

I have a number of "grids" with subsequent data drawn onto a virtual window, (for scrolling purposes), and I want to print the same grid/data.

I'd thought originally to "generalize" my display routine to encompass writing either to virtual window/screen or to printer, but it occurred to me that since I'd already written to a virtual window, maybe I could just stretchBlt that to the printer. (Watching page lengths so the grids don't get partly printed on two different pages, of course.)

Is that approach doable? If so, any hints toward accomplishing that would be appreciated! smile

And from somewhere I vaguely remember some necessity to deal in some way with a difference in size between screen pixels and print pixels. How would I do that?

Dan

new topic     » topic index » view message » categorize

2. Re: [Win32Lib] stretchBlt a virtual window to Printer?

Dan,

I wrote a module a while back to print lines and boxes and you-name-it. The point is that it gets the printer parameters and uses them to allow me to print in absolute units (mm, cm, inches) without worrying about the printer characteristics. The module is called GrPrint.ew in the contribs, and may well contain some of the information you need. I have done a few additions since then but th eone in contribs contains what you are after. As far as stretchBlt() is concerned, that is fine as long as you know how many pixels to the inch in x & y directions. At least, it is fine from a pixmap and I assume the screen can count as that. I used it to print to a PDF but it failed, so I now stretchBlt to a pixmap and the print that to PDF. Hope this is of some use...

Andy

new topic     » goto parent     » topic index » view message » categorize

3. Re: [Win32Lib] stretchBlt a virtual window to Printer?

Nevermind? I think I got it to work just fine, though I haven't taken care of making sure only as much is sent to a page as will fit.

I'm amazed at how I can sometimes get things to work without really understanding what I'm doing! smile

(Or is that just appear to work? Waiting now for hidden infestation of bugs to manifest.)

Dan

new topic     » goto parent     » topic index » view message » categorize

4. Re: [Win32Lib] stretchBlt a virtual window to Printer?

AndyDrummond said...

Dan,

I wrote a module a while back to print lines and boxes and you-name-it. The point is that it gets the printer parameters and uses them to allow me to print in absolute units (mm, cm, inches) without worrying about the printer characteristics. The module is called GrPrint.ew in the contribs, and may well contain some of the information you need. I have done a few additions since then but th eone in contribs contains what you are after. As far as stretchBlt() is concerned, that is fine as long as you know how many pixels to the inch in x & y directions. At least, it is fine from a pixmap and I assume the screen can count as that. I used it to print to a PDF but it failed, so I now stretchBlt to a pixmap and the print that to PDF. Hope this is of some use...

Andy

Andy,

I'll take a look at your GrPrint.ew (it's possible I already have it somewhere, too), but as far as I can see right now, stretchBlt has worked FINE, without apparently needing to know pixels per inch etc. One thing I had to do to make it work was to be careful exactly where I put my call to the print routine, as it apparently needed the VirtScrn to be fully drawn, which makes sense, but what didn't make too much sense (but worked), was to put my call AFTER and NOT before some SCROLL bar adjustment statements. Somehow that's what made sure VirtScrn was finished, I guess/think. Weird.

Here's approx. what I did, much/most lifted from one demo or another:

function InitPrinter() 
    sequence lRect 
    sequence lPrinterDef 
    atom lAspectX 
    atom lAspectY 
    atom lResX 
    atom lResY 
 
 
    lPrinterDef =  
        getPrintChoice(1, w32or_all({PD_NOSELECTION,PD_NOPAGENUMS}), 0) 
    if length(lPrinterDef) = 0 then 
        return {} 
    end if 
 
    lAspectX = w32Func(xGetDeviceCaps, {lPrinterDef[4], HORZSIZE}) 
    lAspectY = w32Func(xGetDeviceCaps, {lPrinterDef[4], VERTSIZE}) 
    lResX = w32Func(xGetDeviceCaps, {lPrinterDef[4], HORZRES}) 
    lResY = w32Func(xGetDeviceCaps, {lPrinterDef[4], VERTRES}) 
    lRect = getClientRect(Printer) -- gets size of printer 
 
	return {lRect, lAspectX, lAspectY, lResX, lResY} 
end function 
 
 
---------------------------------------------------------------------- 
procedure PrintVirtScrn() -- this should take the VirtScrn & print it? 
 sequence result 
 sequence printerInfo 
 sequence virtSize 
 
 
   printerInfo = InitPrinter()   
   --{lRect, lAspectX, lAspectY, lResX, lResY} 
   if length(printerInfo) = 0 then 
      return 
   end if 
 
   virtSize = getClientRect(VirtScrn) 
 
--PRINTER STUFF (printerInfo[1]) 
--{ left, top, width, height, bottom, right } 
--{0,0,2976,3876,2975,3875} 
 
  -- start a new document 
     VOID = startDoc( "This is the Document title, in TitleBar") 
 
 
  -- start a new page 
     VOID = startPage() 
 
------************************************** 
--yPosAfterEACHbox -- need to use this to make new page(s) when necessary 
-- probably need a loop, a test for if too long to fit page, and an EXIT 
------************************************** 
 
 
--stretchBlt ( dst, dstX, dstY, dstWide, dstHigh, 
--             src, srcX, srcY, srcWide, srcHigh, rop ) 
 
--  dst: Image destination             Printer 
-- dstX: X position in destination     1 
-- dstY: Y position in destination     1 
-- dstWide: Width of resulting image   printerInfo[1][3] 
-- dstHigh: Height of resulting image  printerInfo[1][4] 
-- src: Image source                      VirtScrn 
-- srcX: X position in source             1 
-- srcY: Y position in source             1 
-- srcWide: Width of image to copy        virtSize[3] 
-- srcHigh: Height of image to copy       virtSize[4] 
-- rop: Raster opeartion (ROP) code to apply  SrcCopy 
--      SrcCopy : dest = source 
 
-- and the following, now, is all it takes to print my virtual screen!   
   stretchBlt ( Printer, 1, 1, printerInfo[1][3], printerInfo[1][4], 
             VirtScrn, 1, 1, virtSize[3], virtSize[4], SrcCopy ) 
 
  -- close the page 
  VOID = endPage() 
 
  -- close the document 
     VOID = endDoc() 
 
  -- release the printer 
  releasePrinter() 
end procedure 
new topic     » goto parent     » topic index » view message » categorize

5. Re: [Win32Lib] stretchBlt a virtual window to Printer?

DanM said...

I'll take a look at your GrPrint.ew (it's possible I already have it somewhere, too), but as far as I can see right now, stretchBlt has worked FINE, without apparently needing to know pixels per inch etc. One thing I had to do to make it work was to be careful exactly where I put my call to the print routine, as it apparently needed the VirtScrn to be fully drawn, which makes sense, but what didn't make too much sense (but worked), was to put my call AFTER and NOT before some SCROLL bar adjustment statements. Somehow that's what made sure VirtScrn was finished, I guess/think. Weird.

MSDN is your friend (no kidding!):

"The title bar, menu bar, window menu, minimize and maximize buttons, sizing border, and scroll bars are referred to collectively as the window's nonclient area. The system manages most aspects of the nonclient area; the application manages the appearance and behavior of its client area."

getClientRect() returns what Windows thinks is the client area of the window, minus statusbar and top horizontal toolbar. Since scrollbars that originate from the window style belong to the nonclient area, and since the client area is the non nonclient area, it makes sense that scrollbar positions be known for the returned client area to be accurate.

Note that, if you ceated your window with explicit scrollbar child controls, they probably will be considered as child controls and not as part of the nonclient area. I'd strongly suggest you to compare the observed behaviours with either use cases.

Window is not your friend.

CChris

new topic     » goto parent     » topic index » view message » categorize

6. Re: [Win32Lib] stretchBlt a virtual window to Printer?

Chris,

I think I understand, thanks! (had to look twice at "non nonclient" smile )

Bottom line is I stumbled into making it work, except for proper pagination (ie, not breaking grids on page breaks), which I'll work on tonight, shouldn't be hard.

Thanks again for the explanation!

Dan

new topic     » goto parent     » topic index » view message » categorize

7. Re: [Win32Lib] stretchBlt a virtual window to Printer?

DanM said...

I'll take a look at your GrPrint.ew (it's possible I already have it somewhere, too), but as far as I can see right now, stretchBlt has worked FINE, without apparently needing to know pixels per inch etc.

Andy,

Turns out I do already have your GrPrint.ew, and that I will need to know the proportional difference between print/vid pixels, in order to make sure I can prevent grids from being broken on page breaks. I left "bread crumbs" as I drew the grids on VirtScrn, indicating where each grid ended, in screen pixels. I'll see if your .ew makes easy reference to using that proportional difference to figure if a grid will be blt'd beyond print page length, but if anyone can easily describe how, that'd be ok too! smile

Dan

new topic     » goto parent     » topic index » view message » categorize

8. Re: [Win32Lib] stretchBlt a virtual window to Printer?

Dan,

I have to say I have forgotten a lot of the stuff I did in GrPrint, but with a lot of help from people like Derek Parnell I found how to get the number of pixels to the inch in the X & Y directions, and the size of the client area of one page of the printer. Therefore I could convert X & Y distances in inches etc to pixels, and also fit things to the page. But you seem to have that largely done anyway. I use GrPrint to print size-critical key-tops and so on, on any printer - very useful.

Good luck

Andy

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu