News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Scan Message Map

Started by Tight_Coder_Ex, November 22, 2009, 09:19:36 PM

Previous topic - Next topic

Tight_Coder_Ex

I've been away from the forum for awhile as ridiculous things like having to make money "WORK", was interfereing with what I really wanted to do

This is a modfied version of http://www.masm32.com/board/index.php?topic=8222.msg59945#msg59945 which the most significant change in this new version is to eliminate global symbols.  Other than that, the explaination and message table format are the same.

  ScanMap proc

; EBX = Pointer to default procedure if window has been sub/super classed.
; ECX = Number of handlers in map (can be NULL, although not usual).

lodsd ; Get address of default window procedure.
mov ebx, eax ; Save in case window has been sub/super classed
lodsw ; Number of messages in map
cwde ; Sign extend to 32 bits, can be NULL but not usually the case

.if eax ; Does map have defninitions
mov ecx, eax ; Move into counter register

; Cycle through each of the application defined handlers until a match is found,
; otherwise just automatically drop into default message processing.

@@: lodsw ; Get message number from map
mov edx, eax ; Copy it so next instruction doesn't destroy
lodsd ; Pointer to application defined handler

.if dx == [esp + 8] ; When match if found, execute handler
lea esi, [esp + 4] ; ESI points to API parameters
call eax ; Call handler
jnc @F ; Do default processing if no carry

xor eax, eax ; Set default return condition
ret 16 ; Clean-up stack and return.
.endif

loopnz @B ; Keep comparing until ECX = Zero.
.endif

@@: ; Either there wasn't a need to handle this event or the handler requires default processing

.if !ebx
jmp DefWindowProc ; Do default processing for this window
.endif

; Processing of a subclassed window requires address of default code so it will
; be placed on stack at this point.

xchg [esp], ebx ; Exchange default processing address
push ebx ; with return and push on stack again
jmp CallWindowProc             ; Do default processing for this window

  ScanMap endp