home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / LordLucifer / win32asm / files / win32asm.exe / Win32ASM / Win32Proto / W32PMain.asm < prev    next >
Encoding:
Assembly Source File  |  1997-11-10  |  3.7 KB  |  117 lines

  1.     Page 60,190
  2.     TITLE W32PMain - Windows 95 prototype - MainProc module.
  3.  
  4.                 .586
  5.                 .MODEL FLAT,STDCALL
  6.  
  7.                 .NOLISTMACRO
  8.                 .NOLIST
  9.  
  10. UniCode         = 0
  11.  
  12.                 INCLUDE INSTR32.MAC
  13.                 INCLUDE WIN32INC.EQU
  14.  
  15.                 INCLUDE USER32.EQU
  16.                 INCLUDE WIN32RES.EQU
  17.                 INCLUDE WIN32.MAC
  18.  
  19.                 INCLUDE W32PROTO.EQU
  20.  
  21.                 .LIST
  22.  
  23.  
  24.                 .CODE
  25.  
  26. WinProc         PROTO
  27.  
  28.                 PAGE
  29. ; ==================================================================
  30. ; Data section.
  31. ; ==================================================================
  32.  
  33.  
  34.  
  35.  
  36. ;===================================================================
  37. ; WndProc
  38. ;===================================================================
  39.  
  40. ; The core of the Winproc is reduced to an absolute minimum, kinda
  41. ; unorthodox but carefully thought of and shouldn't be changed:
  42.  
  43. ; - It doesn't save any register nor creates a stackframe upon entry.
  44. ;   Each of the message processing proc is responsible for doing so.
  45. ;   As a result, the WndProc code can't alter any register either (but EAX).
  46. ;   The benefits of this are:
  47. ;   - Everything looks like if the message processing code got called
  48. ;     directly from the Windows code, minimizing overhead. The overhead
  49. ;     in the WinProc message dispatcher is absolutely minimal, too.
  50. ;   - Each message processor is a proc, that can be implemented in
  51. ;     any external module, can declares its own local parms, save the
  52. ;     registers it needs to, etc...
  53. ;   - The structure of the win program becomes more apparent and clearer
  54. ;     to follow
  55. ;   The only drawback is that the entry/exit code is duplicated in each
  56. ;   message processing proc. Not necessarily duplicated tho, since each
  57. ;   message processor might have its own specific requirements.
  58. ;   This brings a slight code size penalty, but no speed penalty (the
  59. ;   entry/exit sequence is executed once per message anyway).
  60. ; - It doesn't call DefWindowProc, but jumps to it, passing the parm and
  61. ;   return address it got from its caller.
  62. ;   This saves some overhead, and provides tail recursion elimination:
  63. ;   This way, when DefWinProc calls the WinProc (which occurs quite often),
  64. ;   we don't nest the stack yet another level.
  65.  
  66.  
  67. ; ==========================================================================
  68. ; WinProc main dispatcher.
  69. ; ==========================================================================
  70.  
  71.  
  72.     .CODE
  73.  
  74. WinProc PROC PUBLIC                     ;No entry sequence generated here!
  75.     MOV EAX,ESPwMsg                     ;Get wMsg parm, and dispatch it.
  76.  
  77.     CALLBACK WinProc
  78.     MESSAGE WM_MOUSEMOVE
  79.     MESSAGE WM_PAINT
  80.     MESSAGE WM_SIZE
  81.     MESSAGE WM_CREATE
  82.     MESSAGE WM_DESTROY
  83.     MESSAGE WM_NOTIFY
  84.     MESSAGE WM_TIMER
  85.     MESSAGE WM_RBUTTONDOWN
  86.     MESSAGE WM_LBUTTONDOWN
  87.     MESSAGE WM_MENUSELECT
  88.     MSGCHAIN WM_COMMAND,WinProcCMD
  89.     CALLBACKDEFAULT DefWindowProc
  90.  
  91. WinProc ENDP
  92.  
  93.  
  94.  
  95. ; ==========================================================================
  96. ; WinProc Command dispatcher.
  97. ; ==========================================================================
  98.  
  99. WinProcCMD PROC PUBLIC
  100.     XOR EAX,EAX                         ;Prepare for DWORD extension,
  101.     MOV AX,WORD PTR ESPwParam           ;get wParam in EAX.
  102.  
  103.     CALLBACK WinProcCMD
  104.     MESSAGE ID_FILE_EXIT
  105.     MESSAGE ID_FILE_OPEN
  106.     MESSAGE ID_FILE_SAVE
  107.     MESSAGE ID_FILE_SAVEAS
  108.     MESSAGE ID_FILE_PRINT
  109.     MESSAGE ID_OPTIONS_TITLE
  110.     MESSAGE ID_HELP_ABOUT
  111.     MESSAGE ID_HELP_CONTENT
  112.     CALLBACKDEFAULT DefWindowProc
  113.  
  114. WinProcCMD ENDP
  115.  
  116.     END
  117.