Hi all, mucho newbie here

I thought a jump table for WM messages would be an easier template to code the handlers. Please offer your opinion and suggestions. This has surely been done or just maybe just not worth it but I gott tired of the little .if .endif fluff. I just started working with windows so still learning. also I don't know why some of my code didn't work (commented out) if anyone can explain the error thanks.

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

jmp @F
jmptbl dd WM_DESTROY, offset DoDestroy
dd WM_CHAR, offset DoChar
dd WM_PAINT, offset DoPaint
dd 0
mov eax, offset jmptbl
mov ecx, uMsg

; I had to put in all the dword ptr's to make it work, don't know why
.while dword ptr [eax] != 0
;.if dword ptr [eax] == uMsg doesn't work , suppose you can't cmp
; ref to ref
; which is what the parameter would be
.if dword ptr [eax] == ecx
jmp dword ptr [eax +4]
add eax, 8
;fall through
invoke DefWindowProc,hWnd,uMsg,wParam,lParam

xor eax,eax

invoke PostQuitMessage,NULL
jmp cont
push wParam
pop char
invoke InvalidateRect, hWnd,NULL,TRUE
jmp cont
invoke BeginPaint,hWnd, ADDR ps
mov hdc,eax
invoke TextOut,hdc,0,0,ADDR char,1
invoke EndPaint,hWnd, ADDR ps
jmp cont

; following is safety net of my coding ha ha
jmp cont

WndProc endp
Posted on 2002-12-29 20:03:02 by RockyJ
in your 'while' loop -

if the Umsg is something other than WM_DESTROY, WM_CHAR, or WM_PAINT ..eg WM_CREATE
the loop remains active and eax keeps increasing etc...(i think) ...

possibly (since you're only checking for 3 Umsgs) you would
need to add something like
(after add eax,8 )
.break if eax ==offset jmptable+24

or something
Posted on 2002-12-29 21:29:02 by argus
Argus, when it reaches end of jump table == 0
If there is a WM message == to 0 I am in trouble, never have checked,:eek:

jmptbl dd WM_DESTROY, offset DoDestroy
dd 0

.while dword ptr [eax] != 0

when it reaches ==0 it will fall thru to the defproc after while loop
Posted on 2002-12-29 22:25:29 by RockyJ

yes, i took another look and it should work

or , is that what you were saying ? i.e. it DOES work

and i'm looking for mistakes where there are none - lol

and yes, you would think that the default value for would be a dd, and that you
would only need to specify byteptr and wordptr if and as they were needed

your idea does make the WndProc thing neater and more readable...:)
Posted on 2002-12-29 23:30:22 by argus

;.if dword ptr [eax] == uMsg doesn't work , suppose you can't cmp
; ref to ref
; which is what the parameter would be

You're right. Just do something like:

mov edx,uMsg
.if dword ptr [eax]==edx

In fact you can do the mov outside the loop to make it a bit faster.
Posted on 2002-12-30 07:56:01 by Qweerdy