![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

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
> -----Original Message-----
> From: sftalk-bounce_at_forth.com
> [mailto:sftalk-bounce_at_forth.com] On Behalf Of Anil Rodrigues
> Sent: Friday, November 03, 2006 8:44 AM
> To: sftalk_at_forth.com
> Subject: [sftalk] Pirnting Line drawings
>
> I am trying to print shapes composed of lines and arcs, using
> the same commands used to show them on the screen. As a
> starting point I have the code below modified from SFTalk archives.
>
> The problem is "try" only prints once, then doesn't work again.
> Defining a word from "try" without the first 2 lines to get
> pdc works - so the question is in that case what is being
> left floating that I have to close? Also I would expect try
> to open a Print Dialog Box, but it goes straight to the
> printer and prints.
>
> Any suggestions or comments welcome,
>
> Thanks and Cheers!
> Anil
> -------------------------------------------------------------------
> \ >From marc_hawley_at_email.msn.com Fri Jan 1 21:36:10 1999 \ (edited)
>
> create pd.struct \ this is NON-relocatable data
> 66 , \ size in bytes
> NULL , \ owner
> NULL , \ hDevmode
> NULL , \ hDevnames
> NULL , \ hDC - offset 16
> PD_RETURNDC
> PD_RETURNDEFAULT OR , \ flag, get default printer DC
> 0 c, 0 c, \ from page - how else to compile 16?
> 0 c, 0 c, \ to page
> 0 c, 0 c, \ min
> 0 c, 0 c, \ max
> 0 c, 0 c, \ copies
> NULL , \ hInstance
> NULL , \ custdata
> NULL , \ printhook
> NULL , \ setup hook
> NULL , \ prtempllate
> NULL , \ setteplate
> NULL , \ h
> NULL , \ h
>
>
> \ PrintDlg is a known proc, takes one parameter - addr of structure
>
> 3 Import: LineTo \ dc x y -- int
> 5 import: Rectangle
>
> : testpr pd.struct PrintDlg drop ;
>
> create mydocinfo \ NON-relocatable data
> 20 , \ size in bytes
> z" TEST DOCUMENT" , \ name of document
> NULL , \ send to device, not file
> NULL , \ type of data?
> 0 , \ do not use banding
>
> 0 value pdc \ value for printer device context
>
> : try ( -- )
> pd.struct PrintDlg drop
> pd.struct 16 + @ to pdc \ get dc
>
> pdc mydocinfo StartDoc drop \ StartDoc is a known proc in swiftforth
> pdc StartPage drop
> 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
> pdc EndPage drop
> pdc EndDoc drop
>
> \ pdc ( DeleteDC) ( ReleaseDC) ( ?)
> ;
>
> \\
----------------------------------------------------------------------
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 - 09:45:00 PST
This archive was generated by hypermail 2.2.0 : Wed Nov 19 2008 - 03:04:28 PST