User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 397,698 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,514 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser:
Feb 10th, 2005
Views: 1,806
I prefer to use this method as it doesn't clutter a windows procedure with dozens of conditionals and it address my primary objective of coding as tight as possible [28 bytes]. If you think my method can be improved upon in size and/or speed please post your solution.

Note: I have not tested this algorithym yet
asm Syntax
  1. ; *** MESSAGE HANDLER ***
  2.  
  3. ; This procedure determines if application has a handler for a particular event. All windows
  4. ; procedures are passed to this subroutine except those that have been sub or super classed.
  5.  
  6. ; ENTRY: ESI = Pointer to message map
  7. ; ECX = Number of sets in map.
  8.  
  9. ; Each set consists of a 16 bit ID and 32 bit pointer to proceedure.
  10.  
  11. ; LEAVE: EAX = 0 if application handled event, or result of DefWindowProc is not.
  12. ; ____________________________________________________________________________________________
  13.  
  14. ; ESP + 0 = Return address in kernel module
  15. ; ESP + 4 = hWnd, this windows 32 bit handle
  16. ; ESP + 8 = Msg, Message ID passed by OS.
  17. ; ESP + 12 = wParam
  18. ; ESP + 16 = lParam
  19.  
  20. MsgHandler mov edx, [esp + 8] ; Get message ID 0 - 1024 or user defined.
  21.  
  22. ; In the unlikely event a null map is passed to this routine, this method of
  23. ; testing ECX first will prevent a fatal crash.
  24.  
  25. .NextMsg and ecx, ecx ; Are we at the end yet
  26. jz .Default ; ZR = 1, If we are to do default proceesing.
  27.  
  28. dec ecx ; Decrement counter
  29. lodsw ; Get 16 bit ID from message map
  30. cmp ax, dx ; Is there a match
  31. lodsd ; Load pointer
  32. jnz .NextMsg
  33.  
  34. ; At this point we've found a match and as many events need wParam & lParam,
  35. ; I'm going to establish a pointer to those in EBX. hWnd can be simply addressed
  36. ; by EBX - 8 or lParam by EBX + 4.
  37.  
  38. lea ebx, [esp + 12] ; EBX points to wParam
  39. call eax ; Execute event
  40. jnc .Default ; CY = 0, if event requires default proc.
  41. xor eax, eax ; Handled must return 0
  42. ret 16 ; Stack needs to be re-aligned.
  43.  
  44. ; As hWnd, Msg, wParam & lParam are already on the stack I use this method
  45. ; as a trace into kernel showed OS handles this appropriately and there is no
  46. ; point pushing onto stack what is already there. I've tested this on 98/ME/XP.
  47.  
  48. .Default pop ebx
  49. call _DefWindowProcA@16
  50. jmp ebx
  51.  
  52. ; You'll notice at this point we don't need RET 16 as the call to DefWindowProc has already
  53. ; done that for us.
  54.  
  55.  
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 1:27 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC