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

You want to avoid any lengthy operations that are part of your Window
procedure (callback). A lengthy operation would cause your program to
appear to be hung, a user could not resize, move or close the window.
A few scenarios which could cause a lengthy operation:
1) Waiting for an event (i.e. a character from a serial port). Best to
create a worker thread with FORK> (see FORK.F). The thread could post
a message to your main window whenever a new character was received.
Your main window would receive the message just as any Windows
generated event (such as WM_LBUTTONDOWN mouse click).
WM_APP 1+ CONSTANT UM_NEW-CHAR ( Our message Id - WM_APP or higher)
0 VALUE HWND-MY-MAIN ( main window handle, set when main window is
created)
: POST-NEW-CHAR ( char -- )
HWND-MY-MAIN UM_NEW-CHAR ROT ( char ) 0 PostMessage DROP ;
: SERIAL-THREAD
FORK> OPEN-MY-PORT
BEGIN GET-MY-SERIAL-CHAR POST-NEW-CHAR AGAIN ;
2) Processing large amounts of data (i.e. large file
processing/conversion). We could start a worker thread like the
example above, posting a message when finished. Or we could process
the data in small short pieces and use PAUSE (see WINPAUSE in
Tasking.F) to dispatch Windows messages. Either way, assuming this
was initiated from a menu selection, we must first disable the menu
selection so the user could not invoke this routine a *second* time -
imagine the mess.
: PROCESS-DATA
DISABLE-MENU-SELECTION
#RECORDS 0
DO PROCESS-A-RECORD PAUSE LOOP
ENABLE-MENU-SELECTION ;
3) Invoking a lengthy operation via an external API call (i.e. large
database query). Best to start a worker thread and post a message
when the call returns.
Hope this helps,
Mike
-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com]On
Behalf
Of Schmitt Louis Jean-Pierre
Sent: Thursday, January 17, 2002 5:38 AM
To: sftalk_at_forth.com
Subject: [sftalk] Callback Behavior
Hello all
I do not know if I understood the operation of the callbacks well
Here what I believed to understand: =20
A callback behaves like an interruption, summons it of it is the same
idea
as that of the interruptions on a processor. Thus in light if I acted
on
the keyboard or mouse WINDOW detects this, an interruption of name
causes
programs and comes to carry out the callback which is in my window
activates at this time. Once the callback carried out, WINDOW
relinquishes
control in my program to me. The question that I installation is to
know
if this also functions if in my program I am in a loop, c.a.d the loop
is
stopped, the callback carried out then return in my loop Or in my
loop do
I have to go to read the messages of WINDOW =20
All my thanks by advance for the answers. =20
Louis Jean-Pierre
----------------------------------------------------------------------
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!
Search the archives! Visit http://www.forth.com/search for details.
Received on Thu Jan 17 2002 - 09:15:04 PST
This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:21 PST