programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: Pirnting Line drawings

From: Anil Rodrigues <arodrix_at_weld.com>
Date: Fri, 3 Nov 2006 13:50:33 -0500

Thanks Mike;

I'll try your method as soon as I get a chance. My words work but
I don't know what I'm not cleaning up. Printer selection is not
essential but would be nice, and I'm trying to have SF objects sink
in - haven't yet. My rectangle ( below) is screwed up since the
extents change each time; it should be OK in your code,
I won't have to correct it I think.
 "drsh" draws shape.
------------------------
 0 value pdc \ value for printer device context
 : sipm pdc MM_ISOTROPIC SetMapMode drop ;
 : prescl pdc
         dup xm 200 max ym 200 max 0 setwindowextex drop
         dup x+ x- + 2/ y+ y- + 2/ 0 setwindoworgex drop
         dup cxp 2/ cyp 2/ negate 0 setviewportextex drop
         dup cxp 2/ cyp 2/ 0 setviewportorgex drop
   drop ;

 : fpr1
 pd.struct PrintDlg drop
 pd.struct 16 + @ to pdc \ get dc
 ;

 : fprn
   pdc 0= if fpr1 then
 pdc mydocinfo StartDoc drop \ StartDoc is a known proc in swiftforth

     pdc HORZRES GetDeviceCaps to cxp
     pdc VERTRES GetDeviceCaps to cyp

     pdc StartPage drop
     pdc hpen0 SelectObject drop

   pdc 0 dup to xo 0 dup to yo 0 MoveToEx drop
   pdc 0 cyp 1- lineto drop
   pdc cxp 1- cyp 1- lineto drop
   pdc cxp 1- 0 lineto drop
   pdc 0 0 lineto drop

  sipm prescl
  pdc drsh drop
     pdc EndPage drop
  pdc EndDoc drop
\ pdc DeleteDC drop
  ;

-----Original Message-----
From: Mike Ghan [mailto:MikeGhan_at_logix-controls.com]
Sent: Friday, November 03, 2006 12:44 PM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Pirnting Line drawings

Hi Anil,

Printing is a bit tricky. I see a few problem areas in your example.
First, the structure pd.struct must be initialized every time its used.
This is what is preventing subsequent prints. Second, the structure
mydocinfo should contain a *pointer* to the text string, not the string
itself. Lastly, you'll need to cleanup with DeleteDC (commented out
in your example).

The flag PD_RETURNDEFAULT tells PrintDlg to simply use the default
printer. Handling printer selection takes a bit more work - there are
examples in Preview.F.

SwiftForth object classes really do simplify dealing with Windows
structures. Try the following example using objects.

----------------------------------

0 VALUE pdc

PRINTING +ORDER \ Expose print words from Preview.F

DOCINFO BUILDS MY-DI

: START-OF-DOC pdc MY-DI ADDR StartDoc 0> NOT IOR_PRT_BADSTARTDOC
?THROW ;
: START-OF-PAGE pdc StartPage 0> NOT IOR_PRT_BADSTARTPAGE ?THROW ;
: END-OF-PAGE pdc EndPage 0> NOT IOR_PRT_BADENDPAGE ?THROW ;
: END-OF-DOC pdc EndDoc 0> NOT IOR_PRT_BADENDDOC ?THROW ;

: MY-DEFAULT-PRINTER DEFAULT-PRINTER pd DC @ TO pdc ;

: SET-DOC-NAME ( zName -- ) \ Name Print Job
   DOCINFO SIZEOF MY-DI Size !
   ( zNname ) MY-DI DocName !
   0 MY-DI Output ! 0 MY-DI Datatype ! 0 MY-DI Type ! ;

: TRY ( -- )
   MY-DEFAULT-PRINTER
   Z" Test Document" SET-DOC-NAME
   START-OF-DOC
   START-OF-PAGE ( We must manage our paging )
   ( Now we render our output )
   pdc 50 50 2000 3000 Rectangle drop
   pdc 100 100 S" hello printer " TextOut drop
   pdc 200 200 S" page ONE " TextOut drop
   pdc 1000 1000 LineTo drop
   END-OF-PAGE
   END-OF-DOC
   pdc DeleteDC DROP ( Delete Printer DC ) ;

PRINTING -ORDER

HTH,
Mike

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and
bug reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Fri Nov 03 2006 - 10:51:11 PST

This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:41 PST