I devised this algorithm to facilitate runtime modification of event handlers in windows procedure. It also illuminates the busyness of excessive conditionals and jumps. ScanMap also deals with sub/super classed windows and post default processing.
MMapdd0; Pointer to subclass procedure
dd (MainWnd - MMap - 8) / 8; Number of handlers in map
ddWM_COMMAND, CWndCmd; Event # & Procedure pointer combos
Entry point to window procedure
MainWndProc: movesi, MMap
Code to handle qualifying events
ScanMap: lodsd; Load pointer to subclass procedure if applicable
xchgebx, eax; Move it into EBX
lodsd; Load number of handlers in map
xchgecx, eax; Move it into ECX
@@: lodsd; Load corresponding handlers message number
cmpax, [esp + 8] ; Is it same as kernel message
lodsd; Load pointer to procedure
jz@Hd1; If it's the same, then handle message
loopnz@B; Keep going until end of map
@@: orebx, ebx; Is there a subclass procedure
jmp [DefWindowProc] ; Do default processing
jmp [CallWindowProc] @Hd1: leaesi, [esp + 4] ; ESI points to hwnd, msg, wParam, lParam
movedx, eax; So EAX is NULL at the beginning of all handlers
calledx; Execute handler
jnc@B; Branch if default handling required.
xoreax, eax; Handled messages return zero
ret16; Waste parameters
This may look a bit bizarre, but it does work, primarily because kernel code looks after cleaning up stack.
The handler simply looks like this and the only thing ScanMap needs is CF cleared if post default processing is required.
call [PostQuitMessage] stc; Don't require default processing
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum