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

Re: Callback in a Class

From: Rick VanNorman <rick_at_neverslow.com>
Date: Sat, 31 Mar 2001 00:09:38 -0800

Mike,

Sigh.
The problem with implementing a callback is that the interface between
windows and SwiftForth (or any program for that matter) is complex.
Look at the definition of CB: if you don't believe me.

Note also that the concept of a class for dealing with things like the
print-abort callback is almost not viable because the whole idea of
classes is to abstract things that are done many times. Only one
print job is likely to be in operation at one time, the api only allows
one callback such as that per thread, etc.

If I was implementing it, I would abstract by pulling the variable and
the callback and the callback proc all out of the class, and happily
reference them from the class.

(Note also your line of code

> ['] AbrtProc 2 CB: ABORTPROC <<<<<<<< THIS DIES!!!

['] is a *compiler* word, not an interpreter word. It has no defined
interpreter behavior or semantics per ans. Should have used just ' )

I can write a callback routine for the class. But I don't think it
is worth the effort, nor do I think there is any tangible payback
to it.

Question: where is the variable ABORT-PRINT? set?

Regards,
Rick

My code would probably look like this:

Function: SetAbortProc ( hDCprt abortProc -- res )

VARIABLE ABORT-PRINT?

\ Classic Printer Abort Procedure
: AbrtProc ( hDCprt error -- flag ) \ True = Continue
   2DROP ( hDC error )
   BEGIN WINMSG 0 0 0 PM_REMOVE PeekMessage
   WHILE WINMSG TranslateMessage DROP
          WINMSG DispatchMessage DROP
   REPEAT ABORT-PRINT? @ NOT ;

' AbrtProc 2 CB: ABORTPROC

CLASS PRT-FOO

   PRINTDIALOG BUILDS prtdlg

   : SET-ABORT-PROC
      prtdlg DC @ ABORTPROC :: SetAbortProc DROP ;

   : DEFAULT-PRINTER ( -- )
      0 prtdlg DevMode ! 0 prtdlg DevNames !
      PD_RETURNDC PD_RETURNDEFAULT OR prtdlg Flags !
      PRINTDIALOG SIZEOF prtdlg StructSize !
      prtdlg ADDR :: PrintDlg 0= IOR_PRT_NODEFPRINTER ?THROW ;

   : CONSTRUCT ( -- )
     DEFAULT-PRINTER
     SET-ABORT-PROC
     ( Actual Printing )
     ;

END-CLASS
R

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Received on Sat Mar 31 2001 - 00:10:52 PST

This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 03:04:18 PST