Download WINDOWS ASSEMBLY LANGUAGE & SYSTEMS PROGRAMMING

Transcript
Program Design 165
One callback There is nothing new about the message loop. Remember how
Windows calls GETMESSAGE to get a message from the
for all
application’
s queue, then calls DISPATCHMESSAGE() to send it
windows
on to the callback function. Because each window has its own
callback function, we have to design the program so that the
message will end up at the correct callback - except that in this
program there is a trick. There is only one callback function,
called exportwndproc().
It is a common practise with Windows programming to reuse one
set of code with different data for each window.
Most Windows programs can have multiple instances, that is,
multiple copies running simultaneously without conflict, even
though they use the same code. Each time you double-click on the
application’s icon, a new data/stack/heap segment is loaded, but
the original code segment is used. This practical functionality is
enabled in the .DEF file by specifying the data as MULTIPLE (see
page 177).
The same principle can be applied to multiple windows within the
one instance.
Callback
One callback,
but each
window is a
separate
object
Now this is interesting. Despite the fact that a program can create
as many simultaneous windows as it wants, there is only one
callback function, exportwndproc(). Exportwndproc() determines
which window has sent the message, which is easy enough,
because its handle, hwnd, is passed to the callback, then it gets the
address of the corresponding window object, which it loads into
SI.
This is conceptually quite simple. Any activity related to the
active window on the screen will result in Windows sending a
message. The callback can use the same code for all windows,
except for overrides - all it needs to know is the address of the
object (the data and pointers) for that window . . .
exportwndproc
PUBLIC
exportwndproc PROC WINDOWS PASCAL FAR \
@@hwnd:WORD,@@message:WORD,\
@@wparam:WORD,@@lparam:DWORD
LOCAL dummy:WOR6:5
; . . . .
;Make() controls this flag.
cmp pwindowflag,O
jne normalwndproc
call DEFWINDOWPROC PASCAL, @@hwnd,@@message, \
@@wparam, O@lparam