         title   ToolTemplate

         .586
         .model flat, stdcall
         option casemap:none   ; Case sensitive

            include  \MASM32V1\PROGRAMS\AsmEdit\include\Windows.inc
            include  \MASM32V1\PROGRAMS\AsmEdit\include\user32.inc
            include  \MASM32V1\PROGRAMS\AsmEdit\include\kernel32.inc
            include  \MASM32V1\PROGRAMS\AsmEdit\include\gdi32.inc
            include  \MASM32V1\PROGRAMS\AsmEdit\include\comctl32.inc
            include  \MASM32V1\PROGRAMS\AsmEdit\include\comdlg32.inc

   include  \MASM32V1\PROGRAMS\AsmEdit\include\DSPMACRO.asm

         includelib  \MASM32V1\PROGRAMS\AsmEdit\lib\user32.lib
         includelib  \MASM32V1\PROGRAMS\AsmEdit\lib\kernel32.lib
         includelib  \MASM32V1\PROGRAMS\AsmEdit\lib\gdi32.lib
         includelib  \MASM32V1\PROGRAMS\AsmEdit\lib\comctl32.lib
         includelib  \MASM32V1\PROGRAMS\AsmEdit\lib\comdlg32.lib

;===================================================
; PROTO, MACRO, and Data section
;===================================================
WinMain         PROTO  :DWORD, :DWORD, :DWORD, :DWORD
RichEditProc    PROTO  :DWORD, :DWORD, :DWORD, :DWORD
;Insert between
;++++ Proto & Macros ++++++++++++++++++++++++++++++++++++++++++++++++++
ChgBmpColor      PROTO :DWORD

;---------- [Toolbar structure macros] ----------
TBSep    MACRO hTool
           mov     tbb.iBitmap, 0
           mov     tbb.idCommand, 0
           mov     tbb.fsState, TBSTATE_ENABLED
           mov     tbb.fsStyle, TBSTYLE_SEP
        INVOKE     SendMessage, hTool, TB_ADDBUTTONS, 1, addr tbb
          ENDM

TBButt   MACRO hTool, BmpID, CmdID, Text
           mov     tbb.iBitmap, BmpID    ; Button image number
           mov     tbb.idCommand, CmdID  ; Command ID number
           mov     tbb.fsState, TBSTATE_ENABLED
           mov     tbb.fsStyle, TBSTYLE_BUTTON
           mov     tbb.dwData, 0
           mov     tbb.iString, Text
        INVOKE     SendMessage, hTool, TB_ADDBUTTONS, 1, addr tbb
          ENDM
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.const
;Insert between
;++++ Constants +++++++++++++++++++++++++++++++++++++++++++++++++++++++
IDM_NEW            equ 1001
IDM_OPEN           equ 1002
IDM_SAVE           equ 1003
IDM_CUT            equ 1004
IDM_COPY           equ 1005
IDM_PASTE          equ 1006
IDM_DELETE         equ 1007
IDM_FIND           equ 1008
IDM_FINDNEXT       equ 1009
IDM_FINDPREV       equ 1010
IDM_REPLACE        equ 1011
IDM_EXIT           equ 1012
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IDM_SELALL         equ 2009

.data
RichEdit       db  'RichEdit20A',0
RichEdDLL      db  'RICHED20.DLL',0
FontNameCN     db  'Courier New',0
PopupMenu      db  'PopupMenu',0
FontHeight     dd  -12
FontW          dd  400
StatClass      db  'msctls_statusbar32',0
szPart1        db  'Part 1',0
szPart3        db  'Part 3',0
ToolClass      db  'ToolbarWindow32',0
ClassName      db  'ToolTemplate',0
AppName        db  'ToolTemplate',0
MenuName       db  'MainMenu',0
szNull         db  0

;Insert between
;++++ .data +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TextC01        db  'New',0
TextC02        db  'Open',0
TextC03        db  'Save',0
TextC04        db  'Save All',0
TextC05        db  'Cut',0
TextC06        db  'Copy',0
TextC07        db  'Paste',0
TextC08        db  'Delete',0
TextC09        db  'Undo',0
TextC10        db  'Redo',0
TextC11        db  'Find',0
TextC12        db  'FindN',0
TextC13        db  'FindP',0
TextC14        db  'Rep',0
TextC15        db  'MultiI',0
TextC16        db  'Exit',0
szTextC        dd  TextC01,TextC02,TextC03,TextC04,TextC05,TextC06,
                   TextC07,TextC08,TextC09,TextC10,TextC11,TextC12,
                   TextC13,TextC14,TextC15,TextC16

szSpace        db  ' ',0
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

szError1       db  'The RICHED20.DLL was not found!',0
.data?
hInst          dd  ?
CommandLine    dd  ?
MainExit       dd  ?
hWnd           dd  ?
hREdDll        dd  ?
hREdit         dd  ?
hSMenu         dd  ?
lpRichEdit     dd  ?
hFont          dd  ?
FontName       db  64  dup(?)
hWndStat       dd  ?
sbParts        dd  4   dup(?)
MenuCnt        dd  ?

;Insert between
;++++ .data? ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hWndTool       dd  ?
hImageList     dd  ?

LeftOn         dd  ?
TopOn          dd  ?
RightOn        dd  ?
BottomOn       dd  ?
TBLeft         dd  ?
TBTop          dd  ?
TBWth          dd  ?
TBHgt          dd  ?

SavID          dd  ?
szTextA        db  32  dup(?)

tbi            TBBUTTONINFO <>
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;---------- [Structures] ----------

.code

;===================================================
; Program initialization section
;===================================================
start:
      INVOKE     GetModuleHandle, NULL
         mov     hInst, eax
      INVOKE     GetCommandLine
         mov     CommandLine, eax

        call     InitCommonControls
      INVOKE     LoadLibrary, addr RichEdDLL ; Load the Riched20.dll
         mov     hREdDll, eax
      .if !eax
         INVOKE     MessageBox, NULL, addr szError1, addr AppName, MB_OK or MB_ICONERROR
            jmp     NoGo
      .endif

      INVOKE     WinMain, hInst ,NULL, CommandLine, SW_SHOWDEFAULT
         mov     MainExit, eax
      INVOKE     FreeLibrary, hREdDll

NoGo:
      INVOKE     ExitProcess, MainExit

;===================================================
; WinMain procedure
;===================================================
WinMain proc  uses ebx  hinst:DWORD, hPrevInst, CmdLine, CmdShow
LOCAL    wc:WNDCLASSEX
LOCAL    msg:MSG

         mov     wc.cbSize, sizeof WNDCLASSEX
         mov     wc.style, CS_HREDRAW or CS_VREDRAW
         mov     wc.lpfnWndProc, offset WndProc
         mov     wc.cbClsExtra, NULL
         mov     wc.cbWndExtra, NULL
        push     hInst
         pop     wc.hInstance
         mov     wc.hbrBackground, COLOR_BTNFACE+1
         mov     wc.lpszMenuName, offset MenuName
         mov     wc.lpszClassName, offset ClassName
      INVOKE     LoadIcon, NULL, IDI_APPLICATION
         mov     wc.hIcon, eax
         mov     wc.hIconSm, eax
      INVOKE     LoadCursor, NULL, IDC_ARROW
         mov     wc.hCursor, eax
      INVOKE     RegisterClassEx, addr wc

;---------- [Center the window] ----------
      INVOKE     GetSystemMetrics, SM_CXSCREEN
         sub     eax, 350
         shr     eax, 1
        push     eax
      INVOKE     GetSystemMetrics, SM_CYSCREEN
         sub     eax, 300
         shr     eax, 1
         pop     ebx

;---------- [Create the Main Window] ----------
      INVOKE     CreateWindowEx, WS_EX_CLIENTEDGE, addr ClassName,\
                 addr AppName, WS_OVERLAPPEDWINDOW,\
                 ebx, eax, 350, 300, NULL, NULL, hInst, NULL
         mov     hWnd, eax

      INVOKE     ShowWindow, hWnd, SW_SHOWNORMAL
      INVOKE     UpdateWindow, hWnd

;---------- [Message loop] ----------
      .while TRUE
         INVOKE     GetMessage, addr msg, NULL, 0, 0
            .break .if (!eax)
            INVOKE     TranslateMessage, addr msg
            INVOKE     DispatchMessage, addr msg
      .endw
         mov     eax, msg.wParam
         ret
WinMain endp

;===================================================
; WinProc procedure
;===================================================
WndProc proc  uses ebx  hwnd:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    lf:LOGFONT
LOCAL    charF:CHARFORMAT2

;Insert between
;++++ Locals ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LOCAL    tbb:TBBUTTON
LOCAL    tbab:TBADDBITMAP
LOCAL    bSize:DWORD, hTbBmp, ID, Cnt, Len, Incr, xPos, yPos, WWth, WHgt
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LOCAL    szBuff[64]:BYTE
;---------- [Create the Control(s) and one time stuff] ----------
      .if wMsg == WM_CREATE

;---------- [Create the status bar window] ----------
         INVOKE     CreateWindowEx, 0, addr StatClass, 0,\
                    WS_CHILD or WS_BORDER or WS_VISIBLE or SBS_SIZEGRIP,\
                    0, 0, 0, 0, hwnd, 0, hInst, 0  
         .if !eax
;Do message
               jmp     Ret0
         .endif
            mov     hWndStat, eax

;Insert between
;++++ Toolbar code ++++++++++++++++++++++++++++++++++++++++++++++++++++
;---------- [Create the Toolbar Window] ----------
         INVOKE     CreateWindowEx, 0, addr ToolClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or CCS_TOP or \
                    CCS_NORESIZE or CCS_ADJUSTABLE or TBSTYLE_BUTTON or TBSTYLE_TOOLTIPS or \
                    TBSTYLE_FLAT,\
                    0, -2, 1200, 26, hwnd, 0, hInst, 0
            mov     hWndTool, eax

;---------- [Create the ImageList] ----------
         INVOKE     ImageList_Create, 16, 16, ILC_COLOR32, 16, 0
            mov     hImageList, eax

;---------- [Load The Bitmaps] ----------
            mov     ID, 701           ; Bitmap ID
            mov     Cnt, 16
         .while (Cnt)
            INVOKE     LoadImage, hInst, ID, IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR
            INVOKE     ChgBmpColor, eax
               mov     hTbBmp, eax
            INVOKE     ImageList_Add, hImageList, hTbBmp, NULL
            INVOKE     DeleteObject, hTbBmp
               inc     ID
               dec     Cnt
         .endw

         INVOKE     SendMessage, hWndTool, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
         INVOKE     SendMessage, hWndTool, TB_SETIMAGELIST, 0, hImageList

;---------- [Size the Bitmap and Button] ----------
            mov     ecx, 16  ; loword = bitmap Width
            mov     eax, 16  ; hiword = bitmap Height
            shl     eax, 16
            mov     ax, cx
            mov     bSize, eax
         INVOKE     SendMessage, hWndTool, TB_SETBITMAPSIZE, 0, bSize
            mov     ecx, 23  ; loword = button Width
            mov     eax, 22  ; hiword = button Height
            shl     ecx, 16
            mov     cx, ax
         INVOKE     SendMessage, hWndTool, TB_SETBUTTONSIZE, 0, ecx

;---------- [Create the Toolbar structures] ----------
         TBButt     hWndTool, 0,IDM_NEW,0
         TBButt     hWndTool, 1,IDM_OPEN,0
         TBButt     hWndTool, 2,IDM_SAVE,0
          TBSep     hWndTool
         TBButt     hWndTool, 4,IDM_CUT,0
         TBButt     hWndTool, 5,IDM_COPY,0
         TBButt     hWndTool, 6,IDM_PASTE,0
         TBButt     hWndTool, 7,IDM_DELETE,0
          TBSep     hWndTool
         TBButt     hWndTool, 10,IDM_FIND,0
         TBButt     hWndTool, 11,IDM_FINDNEXT,0
         TBButt     hWndTool, 12,IDM_FINDPREV,0
         TBButt     hWndTool, 13,IDM_REPLACE,0
          TBSep     hWndTool
         TBButt     hWndTool, 15,IDM_EXIT,0
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;---------- [Create the Edit Window] ----------
         INVOKE     CreateWindowEx, NULL, addr RichEdit, NULL,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or ES_MULTILINE or\
                    ES_NOHIDESEL or ES_SAVESEL or ES_SELECTIONBAR or\
                    WS_HSCROLL or ES_AUTOHSCROLL or\
                    WS_VSCROLL or ES_AUTOVSCROLL,\
                    0, 0, 0, 0, hwnd, 4444, hInst, NULL
         .if !eax
;Do message
               jmp     Ret0
         .endif
            mov     hREdit, eax

         INVOKE     SendMessage, hREdit, EM_EXLIMITTEXT, 0, 4000000
         INVOKE     SetFocus, hREdit

;---------- [Control window subclassed] ----------
         INVOKE     SetWindowLong, hREdit, GWL_WNDPROC, RichEditProc
            mov     lpRichEdit, eax

         INVOKE     LoadMenu, hInst, addr PopupMenu   
         INVOKE     GetSubMenu, eax, 0
            mov     hSMenu, eax

;---------- [Get the character format] ----------
            mov     charF.cbSize, sizeof charF
         INVOKE     SendMessage, hREdit, EM_GETCHARFORMAT, TRUE, addr charF
            mov     eax, FontW
            mov     charF.wWeight, ax   
         INVOKE     lstrcpy, addr FontName, addr FontNameCN

         INVOKE     RtlZeroMemory, addr lf, sizeof lf
         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontName
           push     FontHeight
            pop     lf.lfHeight
            xor     eax, eax
            mov     ax, charF.wWeight
            mov     lf.lfWeight, eax
            mov     al, charF.bCharSet
            mov     lf.lfCharSet, al
            mov     al, charF.bPitchAndFamily
            mov     lf.lfPitchAndFamily, al
         INVOKE     CreateFontIndirect, ADDR lf
            mov     hFont, eax
         INVOKE     SendMessage, hREdit, WM_SETFONT, hFont, TRUE

         INVOKE     GetMenu, hwnd              ; Get the handle to the main menu
         INVOKE     GetSubMenu, eax, 0         ; Get handle to 1st sub menu
         INVOKE     GetMenuItemCount, eax      ; Get count of items in the sub menu
            mov     MenuCnt, eax               ; Menu count for ProcessMRUFiles

;Insert between
;++++ Set variables +++++++++++++++++++++++++++++++++++++++++++++++++++
;---------- [Set various values] ----------
            mov     LeftOn, 0
            mov     TopOn, 1
            mov     RightOn, 0
            mov     BottomOn, 0
            mov     TBLeft, -1
            mov     TBTop, -2
            mov     TBWth, 469
            mov     TBHgt, 26

            mov     tbi.cbSize, sizeof tbi
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;---------- [Move and Size the Control(s)] ----------
      .elseif wMsg == WM_SIZE

;++++ Sizing code +++++++++++++++++++++++++++++++++++++++++++++++++++++
;---------- [AutoSize the Toolbar Control] ----------
         INVOKE     SendMessage, hWndTool, TB_AUTOSIZE, 0, 0

;---------- [Size the Edit Toolbar Controls] ----------
            xor     eax, eax             ; Zero out toolbar height
         .if hWndTool
            INVOKE     GetClientRect, hWnd, addr rect ; Rectangle of main window
               mov     eax, rect.right
               mov     WWth, eax
            .if TopOn || BottomOn
                  inc     eax
                  mov     TBWth, eax
            .endif
               mov     eax, rect.bottom
               mov     WHgt, eax
            INVOKE     GetWindowRect, hWndTool, addr rect ; Rectangle of toolbar
               mov     eax, rect.bottom
               sub     eax, rect.top
               mov     TBHgt, eax
            .if LeftOn || RightOn
                  mov     eax, WHgt
                  mov     TBHgt, eax
                  xor     eax, eax
            .endif
         .endif
           push     eax                  ; Save height of toolbar

            xor     eax, eax             ; Zero out statusbar height
         .if hWndStat
            INVOKE     GetWindowRect, hWndStat, addr rect ; Rectangle of statusbar
               mov     eax, rect.bottom
               sub     eax, rect.top     ; eax = height of statusbar
         .endif

            pop     edx                  ; edx = height of toolbar
         .if BottomOn
               and     edx, 0
         .endif
            mov     ebx, lParam          ; Width of new client area
            and     ebx, 0ffffh          ; ebx = width
            mov     ecx, lParam
            shr     ecx, 16              ; Height of new client area
            sub     ecx, eax             ; Edit window - height of statusbar
            sub     ecx, edx             ; Edit window - height of toolbar
         .if edx                         ; If toolbar
               sub     edx, 2            ; For border
               add     ecx, 2            ; For border
         .endif
         .if eax                         ; If statusbar
               add     ecx, 2            ; For border
         .endif

            and     xPos, 0
         .if LeftOn
               mov     eax, TBWth
               mov     xPos, eax
               sub     ebx, TBWth
               mov     TBHgt, ecx
         .endif
         .if RightOn
               mov     xPos, 0
               sub     ebx, TBWth
               mov     TBHgt, ecx
               mov     TBLeft, ebx
         .endif
         .if BottomOn
               sub     ecx, TBHgt
               add     ecx, 20      ; Statusbar height
               mov     TBTop, ecx
         .endif
         INVOKE     MoveWindow, hREdit, xPos, edx, ebx, ecx, TRUE
         INVOKE     MoveWindow, hWndTool, TBLeft, TBTop, TBWth, TBHgt, TRUE
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

      .elseif wMsg == WM_NOTIFY
            mov     ebx, lParam          ; Get pointer to NMHDR
            mov     eax, (NMHDR ptr [ebx]).code
         .if eax == TTN_NEEDTEXT
               mov     eax, (NMHDR ptr [ebx]).idFrom ; Resource id
               mov     ebx, eax
            INVOKE     LoadString, hInst, ebx, addr szBuff, lengthof szBuff
               mov     ebx, lParam                   ; Get the buffer addr
               lea     eax, szBuff
               mov     (TOOLTIPTEXT ptr [ebx]).lpszText, eax
               jmp     Ret0
         .endif

;Insert between
;++++ Customize Toolbar code ++++++++++++++++++++++++++++++++++++++++++
;---------- [Customize the Toolbar] ----------
         .if eax == TBN_BEGINADJUST
               mov     eax, TRUE
               ret

; Add to Windows.inc Comctl32.dll version 5.80 or later- Removes the help button
         .elseif eax == TBN_FIRST-23 ;TBN_INITCUSTOMIZE
               mov     eax, 1        ;TBNRF_HIDEHELP
               ret

         .elseif eax == TBN_QUERYINSERT
               mov     eax, TRUE
               ret

         .elseif eax == TBN_QUERYDELETE
               mov     eax, TRUE
               ret

         .elseif eax == TBN_GETBUTTONINFO
               mov     eax, [ebx.TBNOTIFY].iItem ; Item num
            .if eax < 17                    ; Num of images
                 push     ebx
                 push     eax
                  mov     Incr, eax
               INVOKE     SendMessage, hWndTool, TB_BUTTONCOUNT, 0, 0

;---------- [Find matching bitmap ID] ----------
                  and     ID, 0
                  and     Len, 0
                  mov     Cnt, eax
               .while (Cnt)
                  INVOKE     SendMessage, hWndTool, TB_GETBUTTON, ID, addr tbb
                     mov     eax, Incr
                  .if eax == tbb.iBitmap && tbb.fsStyle != TBSTYLE_SEP
                        mov     edx, tbb.idCommand
                     .break
                  .endif
                  .if tbb.fsStyle != TBSTYLE_SEP
                        inc     Len
                  .endif
                     inc     ID
                     dec     Cnt
               .endw
               .if !Cnt
                     xor     edx, edx
                     xor     esi, esi
               .endif
                  pop     eax
                  pop     ebx
               .if !edx                    ; No matching ID
                  mov     edx, eax
                     inc     edx
                     add     edx, 6900
               .endif

                  mov     [ebx.TBNOTIFY.tbButton].iBitmap, eax
                  mov     [ebx.TBNOTIFY.tbButton].idCommand, edx
                  mov     [ebx.TBNOTIFY.tbButton].fsState, TBSTATE_ENABLED
                  mov     [ebx.TBNOTIFY.tbButton].fsStyle, TBSTYLE_BUTTON
                  mov     [ebx.TBNOTIFY.tbButton].dwData, 0

                  lea     ecx, szSpace
                  xor     esi, esi
               .if eax < 16                ; Number of predefined names
                  pushad
                  INVOKE     lstrcpy, addr szTextA, szTextC[eax*4]
                   popad
                     lea     esi, szTextA
               .endif

               .if esi
                     mov     ecx, esi
                  pushad
                     mov     tbi.dwMask, TBIF_TEXT
                     mov     tbi.pszText, ecx
                     mov     SavID, edx    ; Save the command ID for TBN_TOOLBARCHANGE
                  INVOKE     SendMessage, hWndTool, TB_SETBUTTONINFO, edx, addr tbi
                   popad
               .endif
                  mov     [ebx.TBNOTIFY].cchText, 32
                  mov     [ebx.TBNOTIFY].pszText, ecx
                  mov     eax, TRUE
                  ret
            .else
                  mov     eax, FALSE
                  ret
            .endif

         .elseif eax == TBN_TOOLBARCHANGE
               lea     ecx, szTextA
               mov     tbi.dwMask, TBIF_TEXT
               mov     tbi.pszText, ecx
            INVOKE     SendMessage, hWndTool, TB_SETBUTTONINFO, SavID, addr tbi
               mov     eax, FALSE
               ret
         .endif
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

         jmp     DefWin

;---------- [System and user commands] ----------
      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
           cwde                          ; Only low word contains command
         .if eax == IDM_NEW
            INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, offset szNull
            INVOKE     SendMessage, hREdit, EM_SETMODIFY, FALSE, 0
            INVOKE     SetFocus, hREdit

         .elseif eax == IDM_OPEN

         .elseif eax == IDM_SAVE

         .elseif eax == IDM_EXIT
            INVOKE     SendMessage, hwnd, WM_CLOSE, 0 ,0

         .elseif eax == IDM_CUT
            INVOKE     SendMessage, hREdit, WM_CUT, 0 ,0

         .elseif eax == IDM_COPY
            INVOKE     SendMessage, hREdit, WM_COPY, 0 ,0

         .elseif eax == IDM_PASTE
            INVOKE     SendMessage, hREdit, WM_PASTE, 0 ,0

         .elseif eax == IDM_DELETE
            INVOKE     SendMessage, hREdit, WM_CLEAR, 0 ,0

         .elseif eax == IDM_SELALL
            INVOKE     SendMessage, hREdit, EM_SETSEL, 0, -1

         .elseif eax == IDM_FIND

         .elseif eax == IDM_FINDNEXT

         .elseif eax == IDM_FINDPREV

         .elseif eax == IDM_REPLACE

         .endif

      .elseif wMsg == WM_CLOSE
         INVOKE     DestroyWindow, hwnd

      .elseif wMsg == WM_DESTROY
;Insert between
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         INVOKE     ImageList_Destroy, hImageList
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         INVOKE     PostQuitMessage, NULL

      .else

DefWin:
         INVOKE     DefWindowProc, hwnd, wMsg, wParam, lParam
            ret
      .endif

Ret0:
         xor    eax, eax
         ret
WndProc endp

;===================================================
; SubClass the Edit control procedure
;===================================================
RichEditProc PROC hwnd:DWORD, wmsg, wparam, lparam
LOCAL    rect:RECT

      .if wmsg == WM_RBUTTONDOWN
            jmp     PopUp
      .endif
         jmp     ThatsAll

PopUp:
      INVOKE     GetWindowRect, hWnd, addr rect
         mov     ecx, lparam        ; x/y pos of window
         mov     ebx, ecx
         and     ebx, 0000ffffh     ; ebx = LOWORD(lparam) = x pos
         shr     ecx, 16            ; ecx = HIWORD(lparam) = y pos
         add     ebx, rect.left
         add     ecx, rect.top
         add     ebx, 10 
         add     ecx, 70
      INVOKE     TrackPopupMenu, hSMenu, TPM_LEFTALIGN or TPM_LEFTBUTTON,\
                 ebx, ecx, 0, hWnd, addr rect
        jmp      ThatsAll

ThatsAll:
      INVOKE     CallWindowProc, lpRichEdit, hwnd, wmsg, wparam, lparam

         ret
RichEditProc ENDP

;Insert between
;++++ ChgBmpColor PROC ++++++++++++++++++++++++++++++++++++++++++++++++
;===================================================
; ChgBmpColor procedure
;===================================================
ChgBmpColor PROC hBitmap:DWORD
LOCAL    mDC:DWORD, hBrush, hOldBmp, Fill, hOldBrush
      INVOKE     CreateCompatibleDC, NULL
         mov     mDC, eax
      INVOKE     SelectObject, mDC, hBitmap
         mov     hOldBmp, eax
      INVOKE     GetSysColor, COLOR_BTNFACE
      INVOKE     CreateSolidBrush, eax
         mov     hBrush, eax
      INVOKE     SelectObject, mDC, hBrush
         mov     hOldBrush, eax
         mov     Fill, 00c0c0c0h
      INVOKE     ExtFloodFill, mDC, 0, 0, Fill, FLOODFILLSURFACE
      INVOKE     ExtFloodFill, mDC, 0, 15, Fill, FLOODFILLSURFACE
      INVOKE     ExtFloodFill, mDC, 15, 0, Fill, FLOODFILLSURFACE
      INVOKE     ExtFloodFill, mDC, 15, 15, Fill, FLOODFILLSURFACE
      INVOKE     SelectObject, mDC, hOldBrush
      INVOKE     DeleteObject, hBrush
      INVOKE     SelectObject, mDC, hBitmap
        push     eax
      INVOKE     DeleteDC, mDC
         pop     eax
         ret
ChgBmpColor ENDP
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

end start