Win32 + assembler programmers may be interested to know that I have now enhanced GoAsm's automatic stack frame system by adding a feature will allows you to declare local data dynamically. This allows you to declare only the local data which is actually needed when dealing with a particular message within a window procedure. Bearing in mind a window procedure can be recursive this may result in some stack memory saving.

This also works for message-table type minimised window procedures, so for example, the window procedure itself needs to be no larger than this:-



WndProc FRAME hwnd,uMsg,wParam,lParam
MOV EAX,[uMsg]
MOV ECX,SIZEOF MESSAGES/8
MOV EDX,OFFSET MESSAGES
:
DEC ECX
JS >.notfound
CMP [EDX+ECX*8],EAX ;see if its the correct message
JNZ < ;no
CALL [EDX+ECX*8+4] ;call the correct procedure for the message
JNC >.exit
.notfound
INVOKE DefWindowProcA,[hwnd],[uMsg],[wParam],[lParam]
.exit
RET
ENDF

Then somewhere in the data or const section would be the following table for the messages (in practice there would be a lot more messages than this):-



MESSAGES DD 1h, CREATE ;the message value then the code address
DD 2h, DESTROY
DD 0Fh, PAINT
NextLabel:

And then in the code section (and below WndProc) you would have the code for these messages, for example:-



CREATE:
USEDATA WndProc ;use the stack data in the window procedure frame
USES EBX,EDI,ESI ;preserve the registers for Windows
LOCALS LocalData ;establish required local data area
MOV EAX,[hwnd] ;get window handle sent as a parameter
;
; code to execute on the WM_CREATE message
;
XOR EAX,EAX ;return nc and eax=0 to continue creating the window
RET ;restore the registers and then RET
ENDU ;stop all automated action and access to data

You can view GoAsm's full help file on-line at GoDevTool.com or download GoAsm free using this link.
Posted on 2002-08-05 06:07:40 by jorgon