flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > Alternate windows procedure

Author
Thread Post new topic Reply to topic
TightCoderEx



Joined: 14 Feb 2013
Posts: 52
Location: Alberta
Alternate windows procedure
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.


Code:
  MMap          dd       0                              ; Pointer to subclass procedure
                dd      (MainWnd - MMap - 8) / 8        ; Number of handlers in map
                dd      WM_COMMANDCWndCmd             ; Event # & Procedure pointer combos
                dd      WM_DESTROYMDest

Entry point to window procedure

Code:
  MainWndProc:
        mov     esiMMap
        jmp     ScanMap

Code to handle qualifying events

Code:
  ScanMap:

        lodsd                           ; Load pointer to subclass procedure if applicable
        xchg    ebxeax                ; Move it into EBX
        lodsd                           ; Load number of handlers in map
        xchg    ecxeax                ; Move it into ECX

    @@lodsd                           ; Load corresponding handlers message number
        cmp      ax, [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

    @@or      ebxebx                ; Is there a subclass procedure
        jnz     @Sub
        jmp     [DefWindowProc]         ; Do default processing

  @Subpop     eax
        push    ebx
        push    eax
        jmp     [CallWindowProc]

  @Hd1lea     esi, [esp + 4]          ; ESI points to hwnd, msg, wParam, lParam
        mov     edxeax                ; So EAX is NULL at the beginning of all handlers
        xor     eaxeax
        call    edx                     ; Execute handler
        jnc     @B                      ; Branch if default handling required.

        xor     eaxeax                ; Handled messages return zero
        ret     16                      ; 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.

Code:
  MDest:

        push    0
        call    [PostQuitMessage]
        stc                             ; Don't require default processing
        ret

Post 29 Sep 2015, 00:04
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.