            .586
            .model flat, stdcall
            option casemap:none

            include    \masm32V1\include\windows.inc
            include    \MASM32V1\include\Buttons.inc
            include    \masm32V1\include\user32.inc
            include    \masm32V1\include\GDI32.inc
            include    \masm32V1\include\kernel32.inc
            include    \masm32V1\include\comdlg32.inc
            include    \masm32V1\include\COMCTL32.inc

;            include  \MASM32V1\include\DSPMACRO.asm

            includelib \masm32V1\lib\user32.lib
            includelib \masm32V1\lib\GDI32.lib
            includelib \masm32V1\lib\kernel32.lib
            includelib \masm32V1\lib\comdlg32.lib
            includelib \masm32V1\lib\COMCTL32.lib

.const

IDM_EXIT   equ 1

.data
ClassName   db  'Buttons',0
AppName     db  'Buttons',0

EditClass   db  'RichEdit20A',0
RichEdDLL   db  'RICHED20.DLL',0

ToolClass   db  'ToolbarWindow32',0
ButtClass   db  'BUTTON',0
StatClass   db  'STATIC',0
MenuName    db  'TestPgm',0
szStyleB1   db  'Style B1',0
szStyleB5   db  'Style B5',0
szStyleB6   db  'B6',0
szStyleB7   db  'B7',0
szStyleB8   db  ' Style B8  ',0
szStyleB10  db  'B10',0
szStyleB12  db  'Style B12',0
szStyleB13  db  'Style B13',0
szStyleB14  db  'Style B14',0
szStyleB15  db  'B15',0
szStyleB16  db  'Style B16',0
szStyleB17  db  'Style B17',0
szStyleB18  db  'Style B18',0
szStyleB19  db  'Style B19',0
szStyleB20  db  'Style B20',0
FontNameS   db  'Challenge Extra Bold',0 ;'MS Sans Serif',0
szMsg       db  'Do you really want to get out of here?', 0
PathName    db  'Buttons.rtf',0
szOut       db  10 dup(0)
szCaption   db  30 dup(0)
szControl   db  ' - Control Button',0
szToolbar   db  ' - Toolbar Button',0
szHotSpot   db  ' - HotSpot Button',0
szStyle     db  'Style B0 ',0

hInst       dd  0
CommandLine dd  0
hWnd        dd  0
hWndStat    dd  0
hWndTooL08  dd  0
hWndTooL09  dd  0
hWndTooL10  dd  0
hWndTooL11  dd  0
hWndTooL13  dd  0
hWndTooL19  dd  0
hWndEdit    dd  0
hFile       dd  0 
hFontB      dd  0
hFontT      dd  0
hImageList  dd  0
hTB01       dd  0
hButt1      dd  0
hButt2      dd  0
hButt3      dd  0
hButt4      dd  0
hButt5      dd  0
hButt6      dd  0
hButt7      dd  0
hButtP      dd  0
hButtE      dd  0
hButt12     dd  0
hButt13     dd  0
hButt15     dd  0
hButt18     dd  0
hBR         dd  0
hDC         dd  0
hMemDC      dd  0

; **** Do not add to or change the sequence in the following group ****
hBitMap     dd  0 
hStyleB2U   dd  0
hStyleB2O   dd  0
hStyleB2D   dd  0
hStyleB3U   dd  0
hStyleB3O   dd  0
hStyleB3D   dd  0
hStyleB9U   dd  0
hStyleB9O   dd  0
hStyleB9D   dd  0
hStyleB11U  dd  0
hStyleB11O  dd  0
hStyleB11D  dd  0
hStyleB4U   dd  0
hStyleB4O   dd  0
hStyleB4D   dd  0
hStyleBPU   dd  0
hStyleBPO   dd  0
hStyleBEU   dd  0
hStyleBEO   dd  0
hStyleB10U  dd  0
hStyleBMU   dd  0
hRgn        dd  0
hRgn4       dd  0
hRgn5       dd  0
hRgn6       dd  0
hRgnE       dd  0
; *****************

SubBmp      dd  0
SubTool     dd  0
Butt1D      dd  0
Butt2D      dd  0
Butt3D      dd  0
Butt4D      dd  0
Butt5D      dd  0
Butt6D      dd  0
ButtPD      dd  0
ButtED      dd  0
Butt09D     dd  0
Butt11D     dd  0
Butt12D     dd  0
Butt13D     dd  0
Butt15D     dd  0
Butt18D     dd  0
Butt19D     dd  0

bArray      dd  0, 0, 0, 0

Butt14      dd  160, 122, 235, 147, 0, 0
Butt16      dd  313, 122, 399, 147, 0, 0
Butt17      dd  414, 122, 500, 147, 0, 0
Butt20      dd  341, 155, 510, 175, 0, 0

First3      dd  1
Style       dd  0
Cnt         dd  0
Done        dd  0
Done13      dd  0
HotSpot     dd  0

Test4       dd  0
Down        dd  0
Down13      dd  0

WinMain          PROTO :DWORD,:DWORD,:DWORD,:DWORD
CreateWindowButt PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
CreateWindowTool PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
SetBmpColor      PROTO :DWORD
CopyBitMap       PROTO :DWORD, :DWORD, :DWORD, :DWORD
ButtonType4      PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
ControlButt      PROTO :DWORD, :DWORD, :DWORD, :DWORD
ToolbarButt      PROTO :DWORD, :DWORD, :DWORD, :DWORD
FillRegion       PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
ButtColor        PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
CreateHotButt    PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
CreateRect       PROTO :DWORD, :DWORD

DIS         DRAWITEMSTRUCT       <?>
lf          LOGFONT              <?>
rect        RECT                 <?>
;icc         INITCOMMONCONTROLSEX <?>
tbb         TBBUTTON     <?>
EditS       EDITSTREAM   <?>

.code
start:
      INVOKE     GetModuleHandle, NULL
         mov     hInst, eax
      INVOKE     GetCommandLine
         mov     CommandLine, eax
        call     InitCommonControls          ; Initialize the common ctrl lib
      INVOKE     LoadLibrary, addr RichEdDLL ; Load the RichEd20.dll

;         mov     icc.dwSize, sizeof INITCOMMONCONTROLSEX
;         mov     icc.dwICC, ICC_WIN95_CLASSES
;      invoke     InitCommonControlsEx, addr icc

      INVOKE     WinMain, hInst, NULL, CommandLine, SW_SHOWDEFAULT
      INVOKE     ExitProcess, eax

;========================================================================================
; Initialize the WndClass structure and register our class, creates the main Window, etc.
;========================================================================================
WinMain proc   hinst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
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
      INVOKE     LoadBitmap, hInst, 9000
         mov     hBitMap, eax
      INVOKE     CreatePatternBrush, eax
	  mov     wc.hbrBackground, eax
         mov     wc.lpszMenuName, 0 ;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

;---------- [Create The Main Window] ----------
         mov     rect.right, 525
         mov     rect.bottom, 450
      INVOKE     GetSystemMetrics, SM_CXSCREEN
         sub     eax, rect.right
         shr     eax, 1
        push     eax 
      INVOKE     GetSystemMetrics, SM_CYSCREEN
         sub     eax, rect.bottom
         shr     eax,1
         pop     ebx
      INVOKE     CreateWindowEx, WS_EX_CLIENTEDGE or WS_EX_TOPMOST,\
                 addr ClassName, addr AppName, WS_OVERLAPPEDWINDOW or WS_BORDER or WS_CLIPCHILDREN,\
                 ebx, eax, rect.right, rect.bottom, NULL, NULL, hInst, NULL
         mov     hWnd, eax

;---------- [Show the window and go into message dispatch loop] ----------
      INVOKE     ShowWindow, hWnd,SW_SHOWNORMAL
      INVOKE     UpdateWindow, hWnd
      .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

;========================================================================
; Main window procedure
;========================================================================
WndProc proc uses ebx hwnd:HWND, wmsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL     wF:DWORD, wT, xPos, yPos

      .if wmsg == WM_CREATE

;---------- [Create The Fonts] ----------
         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontNameS
            mov     lf.lfHeight, -18
            mov     lf.lfWidth, 0
            mov     lf.lfWeight, 600
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontB, eax

         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontNameS
            mov     lf.lfHeight, -22
            mov     lf.lfWidth, 0
            mov     lf.lfWeight, 400
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontT, eax

;---------- [Create The Control Buttons] ----------
         INVOKE     CreateWindowEx, 0, addr ButtClass, addr szStyleB7,
                    WS_CHILD or WS_VISIBLE,
                    485, 60, 24, 22, hwnd, 50, hInst, NULL
            mov     hButt7, eax

            mov     Style, WS_CHILD or WS_VISIBLE
         INVOKE     CreateWindowButt, 0, Style, 3, 10, 80, 26, hwnd, 51, addr hButt1

             or     Style, BS_BITMAP
         INVOKE     CreateWindowButt, 0, Style, 94, 10, 113, 26, hwnd, 52, addr hButt2

; Note must include WS_CLIPCHILDREN for regions to work
            mov     Style, WS_CHILD or WS_VISIBLE or WS_CLIPCHILDREN or BS_OWNERDRAW
         INVOKE     CreateWindowButt, 0, Style, 217, 10, 113, 26, hwnd, 53, addr hButt3

         INVOKE     CreateWindowButt, 0, Style, 341, 18, 161, 53, hwnd, 54, addr hButt4
         INVOKE     CreateEllipticRgn, 2, 2, 159, 51
            mov     hRgn4, eax
         INVOKE     SetWindowRgn, hButt4, hRgn4, TRUE

         INVOKE     CreateWindowButt, 0, Style, 3, 48, 80, 26, hwnd, 55, addr hButt5
         INVOKE     CreateRoundRectRgn, 0, 0, 80, 26, 31, 31
            mov     hRgn5, eax
         INVOKE     SetWindowRgn, hButt5, hRgn5, TRUE

         INVOKE     CreateWindowButt, 0, Style, 95, 42, 40, 37, hwnd, 56, addr hButt6
         INVOKE     CreateRoundRectRgn, 0, 0, 40, 37, 38, 35
            mov     hRgn6, eax
         INVOKE     SetWindowRgn, hButt6, hRgn6, TRUE
         INVOKE     CreateRoundRectRgn, 0, 0, 40, 37, 38, 35
            mov     hRgn, eax
         INVOKE     SetWindowRgn, hWnd, hRgn, TRUE  ; NOTE!  hWnd  **NOT hwnd** 

         INVOKE     CreateWindowButt, 0, Style, 148, 46, 85, 29, hwnd, 57, addr hButtP

         INVOKE     CreateWindowButt, 0, Style, 244, 38, 91, 45, hwnd, 58, addr hButtE
         INVOKE     CreateEllipticRgn, 2, 2, 89, 43
            mov     hRgnE, eax
         INVOKE     SetWindowRgn, hButtE, hRgnE, TRUE

         INVOKE     CreateWindowButt, WS_EX_TRANSPARENT, Style, 3, 122, 75, 25, hwnd, 63, addr hButt12

         INVOKE     CreateWindowButt, 0, Style, 254, 122, 36, 26, hwnd, 65, addr hButt15

         INVOKE     CreateWindowButt, 0, Style, 3, 155, 169, 20, hwnd, 66, addr hButt18

;---------- [Load The Bitmaps] ----------
            mov     wF, 9001           ; From addr
            lea     ebx, hStyleB2U
            mov     wT, ebx            ; To addr
            mov     Cnt, 21
         .while (Cnt)
            .if Cnt > 9
               INVOKE     LoadImage, hInst, wF, IMAGE_BITMAP, 113, 26, LR_DEFAULTCOLOR
            .elseif Cnt > 6
               INVOKE     LoadImage, hInst, wF, IMAGE_BITMAP, 161, 53, LR_DEFAULTCOLOR
            .elseif Cnt > 4
               INVOKE     LoadImage, hInst, wF, IMAGE_BITMAP, 85, 29, LR_DEFAULTCOLOR
            .elseif Cnt > 2
               INVOKE     LoadImage, hInst, wF, IMAGE_BITMAP, 91, 45, LR_DEFAULTCOLOR
            .elseif Cnt > 1
               INVOKE     LoadImage, hInst, wF, IMAGE_BITMAP, 25, 26, LR_DEFAULTCOLOR
            .else
               INVOKE     LoadImage, hInst, wF, IMAGE_BITMAP, 36, 26, LR_DEFAULTCOLOR
            .endif
               mov     ebx, wT
               mov     [ebx], eax
               inc     wF
               dec     Cnt
               add     wT, 4
         .endw

         INVOKE     SendMessage, hButt2, BM_SETIMAGE, IMAGE_BITMAP, hStyleB2U


;---------- [Create The Toolbar Buttons] ----------
            mov     Style, WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS or CCS_NOPARENTALIGN or\
                    CCS_NORESIZE or TBSTYLE_LIST or TBSTYLE_FLAT or CCS_NODIVIDER

         INVOKE     CreateWindowTool, Style, 4, 85, 95, 32, hwnd, 81, addr hWndTooL08
         INVOKE     SendMessage, hWndTooL08, WM_SETFONT, hFontT, 1
         INVOKE     SendMessage, hWndTooL08, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
            mov     eax, 00100000h
         INVOKE     SendMessage, hWndTooL08, TB_SETBITMAPSIZE, 0, eax
         INVOKE     SendMessage, hWndTooL08, TB_ADDSTRING, 0, addr szStyleB8
         TBButt     hWndTooL08, 0, 59, eax


         INVOKE     CreateWindowTool, Style, 120, 85, 128, 32, hwnd, 82, addr hWndTooL09
         INVOKE     SetWindowLong, hWndTooL09, GWL_WNDPROC, ToolbarButt
            mov     SubTool, eax
         INVOKE     ImageList_Create, 113, 26, ILC_COLOR32, 3, 0
            mov     hImageList, eax
         INVOKE     ImageList_Add, hImageList, hStyleB9U, NULL
         INVOKE     ImageList_Add, hImageList, hStyleB9O, NULL
         INVOKE     ImageList_Add, hImageList, hStyleB9D, NULL
         INVOKE     SendMessage, hWndTooL09, TB_SETIMAGELIST, 0, hImageList
         INVOKE     SendMessage, hWndTooL09, WM_SETFONT, hFontT, 1
         INVOKE     SendMessage, hWndTooL09, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
            mov     eax, 001a0071h
         INVOKE     SendMessage, hWndTooL09, TB_SETBITMAPSIZE, 0, eax
            mov     eax, 001a0071h
         INVOKE     SendMessage, hWndTooL09, TB_SETBUTTONSIZE, 0, eax
         TBButt     hWndTooL09, 0, 60, 0


         INVOKE     CreateWindowTool, Style, 275, 85, 75, 32, hwnd, 83, addr hWndTooL10
         INVOKE     ImageList_Create, 25, 26, ILC_COLOR32, 1, 0
            mov     hImageList, eax
         INVOKE     ImageList_Add, hImageList, hStyleB10U, NULL
         INVOKE     SendMessage, hWndTooL10, TB_SETIMAGELIST, 0, hImageList
         INVOKE     SendMessage, hWndTooL10, WM_SETFONT, hFontT, 1
         INVOKE     SendMessage, hWndTooL10, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
            mov     eax, 001a0020h
         INVOKE     SendMessage, hWndTooL10, TB_SETBITMAPSIZE, 0, eax
            mov     eax, 001c007ch
         INVOKE     SendMessage, hWndTooL10, TB_SETBUTTONSIZE, 0, eax
         INVOKE     SendMessage, hWndTooL10, TB_ADDSTRING, 0, addr szStyleB10
         TBButt     hWndTooL10, 0, 61, 0


         INVOKE     CreateWindowTool, Style, 374, 84, 113, 26, hwnd, 84, addr hWndTooL11
         INVOKE     SetWindowLong, hWndTooL11, GWL_WNDPROC, ToolbarButt
            mov     SubTool, eax
         INVOKE     SendMessage, hWndTooL11, WM_SETFONT, hFontT, 1
         INVOKE     SendMessage, hWndTooL11, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
;            mov     eax, 00140056h ; * 00140056h = 86 x 20  --  14h x 56h = 20 x 86
;         INVOKE     SendMessage, hWndTooL11, TB_SETBITMAPSIZE, 0, eax
            mov     eax, 001a0071h ; * 001a0071h = 113 x 26  --  1ah x 71h = 26 x 113
         INVOKE     SendMessage, hWndTooL11, TB_SETBUTTONSIZE, 0, eax
         TBButt     hWndTooL11, 0, 62, 0


         INVOKE     CreateWindowTool, Style, 81, 122, 75, 25, hwnd, 85, addr hWndTooL13
         INVOKE     SetWindowLong, hWndTooL13, GWL_WNDPROC, ToolbarButt
            mov     SubTool, eax
         INVOKE     SendMessage, hWndTooL13, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
            mov     eax, 0019004bh
         INVOKE     SendMessage, hWndTooL13, TB_SETBUTTONSIZE, 0, eax
         TBButt     hWndTooL13, 0, 64, 0


         INVOKE     CreateWindowTool, Style, 172, 155, 169, 20, hwnd, 86, addr hWndTooL19 ;172
         INVOKE     SetWindowLong, hWndTooL19, GWL_WNDPROC, ToolbarButt
            mov     SubTool, eax
         INVOKE     SendMessage, hWndTooL19, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
            mov     eax, 001400abh
         INVOKE     SendMessage, hWndTooL19, TB_SETBUTTONSIZE, 0, eax
         TBButt     hWndTooL19, 0, 67, 0

;---------- [Create The Edit Window] ----------
         INVOKE     CreateWindowEx, WS_EX_CLIENTEDGE, addr EditClass, NULL,\
                    WS_CHILD or WS_VISIBLE or ES_LEFT or ES_MULTILINE or\
                    ES_AUTOVSCROLL or WS_VSCROLL or ES_READONLY,\
                    0, 0, 0, 0, hwnd, 32, hInst, NULL
            mov     hWndEdit, eax
         INVOKE     SetFocus, hWndEdit
           call     ReadEM

      .elseif wmsg == WM_SIZE
            mov     eax, lParam
            mov     edx, eax
            shr     edx, 16
            and     eax, 0ffffh
            sub     edx, 182 ;155
         INVOKE     MoveWindow, hWndEdit, 0, 182, eax, edx, TRUE
         INVOKE     GetClientRect, hWndEdit, addr rect
            mov     rect.left, 10
         INVOKE     SendMessage, hWndEdit, EM_SETRECT, 0, addr rect

;---------- [Display The Initial HotSpot Buttons] ----------
            mov     Butt14+16, 0 ; +16 = Button state flag e.g. Off, Over, or Down
            mov     Butt16+16, 0 ; to stop unnessary painting
            mov     Butt17+16, 0
            mov     Butt20+16, 0
         INVOKE     SendMessage, hWnd, WM_MOUSEMOVE, 0, 0

;---------- [HotSpot Buttons] ----------
      .elseif wmsg == WM_PAINT
            mov     Butt14+16, 1
         INVOKE     ButtonType4,  addr Butt14, 0, 0, 0, hFontB, 0, 00005000h, addr szStyleB14, 0, 0, 1
            mov     Butt16+16, 1
         INVOKE     CreateHotButt, addr Butt16, 0, 0000ff00h, addr szStyleB16, 0, 0, 4
            mov     Butt17+16, 1
         INVOKE     CreateHotButt, addr Butt17, 0, 0000ff00h, addr szStyleB17, 0, 0, 4
            mov     Butt20+16, 1
         INVOKE     ButtonType4,  addr Butt20, 0, 0, 0, hFontB, 00ff0000h, 00ffffffh, addr szStyleB20, 0, 1, 1
            jmp     DefWin

      .elseif wmsg == WM_NOTIFY
            mov     ebx, lParam    ; Get pointer to NMHDR
            mov     eax, (NMHDR ptr [ebx]).code
           push     eax

; This could be used for some Toolbar button functions
;         .if eax == NM_CUSTOMDRAW
;               mov     eax, (NMHDR ptr [ebx]).idFrom ;resource id
;.
;.
;         .endif

;---------- [ToolBar Tips] ----------
            pop     eax
            cmp     eax, TTN_NEEDTEXT
            jne     Ret0
            mov     eax, (NMHDR ptr [ebx]).idFrom ; Resource id

; This could be used for some BS_OWNERDRAW button functions
; I use the WM_PAINT MESSAGE in the Button subclass instead.
 
;      .elseif wmsg == WM_DRAWITEM ;&& First3
;            and     First3, 0
;            mov     ebx, lParam    ; Get pointer to DRAWITEMSTRUCT
;            mov     eax, (DRAWITEMSTRUCT ptr [ebx]).CtlID
;            mov     eax, (DRAWITEMSTRUCT ptr [ebx]).itemAction
;            mov     eax, (DRAWITEMSTRUCT ptr [ebx]).itemState
;            mov     eax, (DRAWITEMSTRUCT ptr [ebx]).hwndItem
;         INVOKE     CopyBitMap, hButt3, hStyleB3U, 113, 26
;            mov     eax, 1
;            ret

      .elseif wmsg == WM_MOUSEMOVE || wmsg == WM_NCMOUSEMOVE

         INVOKE     CopyBitMap, hButt4 ,hStyleB4U, 161, 53
         INVOKE     CopyBitMap, hButtE, hStyleBEU, 91, 45

            mov     Done, 0
            mov     eax, lParam
            mov     xPos, eax
            mov     yPos, eax
            and     xPos, 0000ffffh
            shr     yPos, 16

;---------- [Style B14 HotSpot Button] ----------
            mov     eax, xPos
            mov     ebx, yPos
         .if eax >= Butt14 && eax <= Butt14+8 && ebx >= Butt14+4 && ebx <= Butt14+12
;--------- [Mouse Over] ----------
            INVOKE     SetCapture, hWnd
            .if Butt14+16 != 0
                  mov     Butt14+16, 0
               INVOKE     ButtonType4,  addr Butt14, 0, 0, 0, hFontB, 0, 00ff0000h, addr szStyleB14, 1, 0, 1
            .endif
         .else
;--------- [Mouse Off] ----------
            INVOKE     ReleaseCapture
               and     Butt14+20, 0
            .if Butt14+16 != 1
                  mov     Butt14+16, 1
               INVOKE     ButtonType4,  addr Butt14, 0, 0, 0, hFontB, 0, 00005000h, addr szStyleB14, 0, 0, 4 ;1
            .endif
         .endif

;---------- [Style B16 HotSpot Button] ----------
            mov     eax, xPos
            mov     ebx, yPos
         .if eax >= Butt16 && eax <= Butt16+8 && ebx >= Butt16+4 && ebx <= Butt16+12
            INVOKE     SetCapture, hWnd
            .if Butt16+16 != 0
                  mov     Butt16+16, 0
               INVOKE     CreateHotButt, addr Butt16, 0, 00ff0000h, addr szStyleB16, 0, 0, 3
            .endif
         .else
; Don't           INVOKE     ReleaseCapture
               and     Butt16+20, 0
            .if Butt16+16 != 1
                  mov     Butt16+16, 1
               INVOKE     CreateHotButt, addr Butt16, 0, 0000ff00h, addr szStyleB16, 0, 0, 4
            .endif
         .endif

;---------- [Style B17 HotSpot Button] ----------
            mov     eax, xPos
            mov     ebx, yPos
         .if eax >= Butt17 && eax <= Butt17+8 && ebx >= Butt17+4 && ebx <= Butt17+12
            INVOKE     SetCapture, hWnd
            .if Butt17+16 != 0
                  mov     Butt17+16, 0
               INVOKE     CreateHotButt, addr Butt17, 0, 00ff0000h, addr szStyleB17, 0, 0, 3
            .endif
         .else
; Don't           INVOKE     ReleaseCapture
               and     Butt17+20, 0
            .if Butt17+16 != 1
                  mov     Butt17+16, 1
               INVOKE     CreateHotButt, addr Butt17, 0, 0000ff00h, addr szStyleB17, 0, 0, 4
            .endif
         .endif

;---------- [Style B20 HotSpot Button] ----------
            mov     eax, xPos
            mov     ebx, yPos
         .if eax >= Butt20 && eax <= Butt20+8 && ebx >= Butt20+4 && ebx <= Butt20+12
            INVOKE     SetCapture, hWnd
            .if Butt20+16 != 0
                  mov     Butt20+16, 0
               INVOKE     ButtonType4,  addr Butt20, 0, 0, 0, hFontB, 000000ffh, 00000000h, addr szStyleB20, 1, 1, 1
            .endif
         .else
; Don't           INVOKE     ReleaseCapture
               and     Butt20+20, 0
            .if Butt20+16 != 1
                  mov     Butt20+16, 1
               INVOKE     ButtonType4,  addr Butt20, 0, 0, 0, hFontB, 00ff0000h, 00ffffffh, addr szStyleB20, 0, 1, 1
            .endif
         .endif

;---------- [HotSpot Buttons] ----------
      .elseif wmsg == WM_LBUTTONDOWN
            mov     eax, lParam
            mov     ebx, lParam
            and     eax, 0000ffffh
            shr     ebx, 16
         .if eax >= Butt14 && eax <= Butt14+8 && ebx >= Butt14+4 && ebx <= Butt14+12
               mov     Butt14+20, 1 ; +20 = Button Down
            INVOKE     ButtonType4,  addr Butt14, 0, 0, 0, hFontB, 0, 000000ffh, addr szStyleB14, 2, 0, 4
         .elseif eax >= Butt16 && eax <= Butt16+8 && ebx >= Butt16+4 && ebx <= Butt16+12
               mov     Butt16+20, 1
            INVOKE     CreateHotButt, addr Butt16, 0, 00900000h, 0, 0, 0, 4
            INVOKE     CreateHotButt, addr Butt16, 0, 000000ffh, addr szStyleB16, 1, 1, 2
         .elseif eax >= Butt17 && eax <= Butt17+8 && ebx >= Butt17+4 && ebx <= Butt17+12
               mov     Butt17+20, 1
            INVOKE     CreateHotButt, addr Butt17, 0, 00900000h, 0, 0, 0, 4
            INVOKE     CreateHotButt, addr Butt17, 0, 000000ffh, addr szStyleB17, 1, 1, 2
         .elseif eax >= Butt20 && eax <= Butt20+8 && ebx >= Butt20+4 && ebx <= Butt20+12
               mov     Butt20+20, 1
            INVOKE     ButtonType4,  addr Butt20, 0, 0, 0, hFontB, 00008000h, 00000000h, addr szStyleB20, 2, 1, 1
         .endif 

;---------- [HotSpot Buttons] ----------
      .elseif wmsg == WM_LBUTTONUP
            mov     eax, lParam
            mov     ebx, lParam
            and     eax, 0000ffffh
            shr     ebx, 16
         .if eax >= Butt14 && eax <= Butt14+8 && ebx >= Butt14+4 && ebx <= Butt14+12 && Butt14+20
               mov     Butt14+20, 0
            INVOKE     ButtonType4,  addr Butt14, 0, 0, 0, hFontB, 0, 00ff0000h, addr szStyleB14, 1, 0, 4
            INVOKE     lstrcpy, addr szCaption, addr szStyleB14
               jmp     DisplayEM
         .elseif eax >= Butt16 && eax <= Butt16+8 && ebx >= Butt16+4 && ebx <= Butt16+12 && Butt16+20
            INVOKE     CreateHotButt, addr Butt16, 0, 00ff0000h, addr szStyleB16, 0, 0, 3
            INVOKE     lstrcpy, addr szCaption, addr szStyleB16
               jmp     DisplayEM
         .elseif eax >= Butt17 && eax <= Butt17+8 && ebx >= Butt17+4 && ebx <= Butt17+12 && Butt17+20
            INVOKE     CreateHotButt, addr Butt17, 0, 00ff0000h, addr szStyleB17, 0, 0, 3
            INVOKE     lstrcpy, addr szCaption, addr szStyleB17
               jmp     DisplayEM
         .elseif eax >= Butt20 && eax <= Butt20+8 && ebx >= Butt20+4 && ebx <= Butt20+12 && Butt20+20
            INVOKE     ButtonType4,  addr Butt20, 0, 0, 0, hFontB, 000000ffh, 00000000h, addr szStyleB20, 1, 1, 1
            INVOKE     lstrcpy, addr szCaption, addr szStyleB20
DisplayEM:
            INVOKE     lstrcat, addr szCaption, addr szHotSpot
            INVOKE     SetWindowText, hWnd, addr szCaption
         .endif 

      .elseif wmsg == WM_DESTROY
            mov     Cnt, 27
            lea     ebx, hBitMap
         .while (Cnt)
              push     ebx
            INVOKE     DeleteObject, dword ptr[ebx]
               pop     ebx
               add     ebx, 4
               dec     Cnt
         .endw 
         INVOKE     ImageList_Destroy, hImageList
         INVOKE     CloseHandle, hFile
         INVOKE     PostQuitMessage, NULL

      .elseif wmsg == WM_COMMAND
            mov     eax, wParam
           cwde
         .if eax == IDM_EXIT
            INVOKE     DestroyWindow, hwnd
         .endif

;---------- [Displays the type of Button] ---------- 
           push     eax
            mov     szStyle+8, ' '
         .if eax >= 50 && eax < 57
               sub     eax, 50
            .if eax == 0
                  add     eax, 7
            .endif
               add     eax, 30h
               mov     szStyle+7, al
            INVOKE     lstrcpy, addr szCaption, addr szStyle
            INVOKE     lstrcat, addr szCaption, addr szControl
            INVOKE     SetWindowText, hWnd, addr szCaption
         .elseif eax == 57
               mov     dword ptr szOut, 'YALP'
            INVOKE     lstrcpy, addr szCaption, addr szOut
            INVOKE     lstrcat, addr szCaption, addr szControl
            INVOKE     SetWindowText, hWnd, addr szCaption
         .elseif eax == 58
               mov     dword ptr szOut, 'TIXE'
            INVOKE     lstrcpy, addr szCaption, addr szOut
            INVOKE     lstrcat, addr szCaption, addr szControl
            INVOKE     SetWindowText, hWnd, addr szCaption
         .elseif eax >= 59 && eax < 68
            .if eax == 59
                  mov     szStyle+7, '8'
            .elseif eax == 60
                  mov     szStyle+7, '9'
            .elseif eax == 61
                  mov     word ptr szStyle+7, '01'
            .elseif eax == 62
                  mov     word ptr szStyle+7, '11'
            .elseif eax == 63
                  mov     word ptr szStyle+7, '21'
            .elseif eax == 64
                  mov     word ptr szStyle+7, '31'
            .elseif eax == 65
                  mov     word ptr szStyle+7, '51'
            .elseif eax == 66
                  mov     word ptr szStyle+7, '81'
            .elseif eax == 67
                  mov     word ptr szStyle+7, '91'
            .endif
              push     eax 
            INVOKE     lstrcpy, addr szCaption, addr szStyle
               pop     eax
            .if eax == 63 || eax == 65 || eax == 66
               INVOKE     lstrcat, addr szCaption, addr szControl
            .else
               INVOKE     lstrcat, addr szCaption, addr szToolbar
            .endif
            INVOKE     SetWindowText, hWnd, addr szCaption
         .endif

            pop     eax
         .if eax == 58
            INVOKE     MessageBox, NULL, addr szMsg, addr AppName, MB_YESNO or MB_SYSTEMMODAL
            .if eax == IDYES
               INVOKE     DestroyWindow, hwnd
            .endif
         .endif
      .else

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

Ret0:
         xor     eax, eax
         ret
WndProc endp

;=============================================================================
; Creates the Control Buttons
;=============================================================================
CreateWindowButt PROC uses ebx EXStyle, style, xPos, yPos, wh, ht, hwnd, ID, hButt

      INVOKE     CreateWindowEx, EXStyle, addr ButtClass, 0, style,
                 xPos, yPos, wh, ht, hwnd, ID, hInst, NULL
         mov     ebx, hButt
         mov     dword ptr[ebx], eax
      INVOKE     SetWindowLong, dword ptr[ebx], GWL_WNDPROC, ControlButt
         mov     SubBmp, eax
         ret
CreateWindowButt endp

;=============================================================================
; Creates the Toolbar Buttons
;=============================================================================
CreateWindowTool PROC uses ebx style:DWORD, xPos, yPos, wh, ht, hwnd, ID, hButt

      INVOKE     CreateWindowEx, 0, addr ToolClass, 0, style,
                 xPos, yPos, wh, ht, hwnd, ID, hInst, NULL
         mov     ebx, hButt
         mov     dword ptr[ebx], eax
         ret
CreateWindowTool endp

;=============================================================================
; Creates the appearance for the HotSpot Buttons
;=============================================================================
CreateHotButt  proc  uses esi edi  Butt:DWORD, BackC, TextC, szName, Bor, Frm, Rect

      INVOKE     CreateRect, Butt, addr rect
      .if Rect == 4
            sub     rect.left, 3
            sub     rect.top, 3
      .endif

      .if Rect == 1 || Rect == 3 || Rect == 4
         INVOKE     GetClassWord, hWnd, GCL_HBRBACKGROUND ; Get the window background handle
      .elseif Rect == 2
         INVOKE     CreateHatchBrush, HS_DIAGCROSS, 00ffff00h
      .elseif Rect == 5
         INVOKE     CreateSolidBrush, BackC
      .endif
         mov     hBR, eax
      .if Rect == 5
           mov     Rect, 2
      .endif

      INVOKE     ButtColor, hWnd, hFontB, TextC, 000c0c0ch, eax, szName, Bor, Frm, Rect

      INVOKE     DeleteObject, hBR

         ret
CreateHotButt  endp

;=============================================================================
; Create a standard rectangle from the HotSpot array
;=============================================================================
CreateRect  proc  uses esi edi  Butt:DWORD, Rect

         mov     ecx, 4
         xor     eax, eax
         mov     esi, Butt
         mov     edi, Rect

Loop1:
        push     dword ptr[esi+eax]
         pop     dword ptr[edi+eax]
         add     eax, 4
        loop     Loop1

         ret
CreateRect  endp

;=============================================================================
; Fills a non-rectangle shape
;=============================================================================
FillRegion   proc  hButt:DWORD, BackC, TextBcC, TextC, FrameC, szText

      INVOKE     GetDC, hButt
         mov     hDC, eax
      INVOKE     CreateSolidBrush, BackC
         mov     hBR, eax
      INVOKE     FillRgn, hDC, hRgn, eax
      INVOKE     DeleteObject, hBR
      INVOKE     CreateSolidBrush, TextBcC
         mov     hBR, eax
      INVOKE     ButtColor, hButt6, hFontB, TextC, TextBcC, eax, szText, 0, 0, 0
      INVOKE     DeleteObject, hBR
      INVOKE     CreateSolidBrush, FrameC
         mov     hBR, eax
      INVOKE     FrameRgn, hDC, hRgn, eax, 4, 4
      INVOKE     DeleteObject, hBR
      INVOKE     ReleaseDC, hButt, hDC
         ret
FillRegion   endp

;=============================================================================
; Creates various appearances of Buttons
;=============================================================================
ButtColor  PROC hButt:DWORD, hFont, TextC, TextBgC, BackC, szText, Border, Frame, NoRect

      INVOKE     GetDC, hButt
         mov     hDC, eax
      INVOKE     SelectObject, hDC, hFont    ; Select the font into the dc
      INVOKE     SetTextColor, hDC, TextC    ; Set the text color
;      INVOKE     SetBkColor, hDC, TextBgC    ; Set the text background color
      INVOKE     SetBkMode, hDC, TRANSPARENT ; Set the text background to transparent

      .if !NoRect
         INVOKE     GetClientRect, hButt, addr rect
      .endif

      .if Frame
         .if NoRect == 2
            INVOKE     DrawEdge, hDC, addr rect, EDGE_SUNKEN, BF_RECT	
               jmp     ChkBorder
         .endif
           push     rect.left
           push     rect.top
           push     rect.right
           push     rect.bottom
;         INVOKE     CreateSolidBrush, 00000000h
;            mov     hBR, eax
         INVOKE     FillRect, hDC, addr rect, COLOR_BTNTEXT+1 ;eax
;         INVOKE     DeleteObject, hBR        ; Delete the brush handle
            sub     rect.right, 1
         INVOKE     FillRect, hDC, addr rect, COLOR_3DHIGHLIGHT+1
            add     rect.right, 1
            add     rect.left, 1 ;2
            add     rect.top, 1 ;2
         .if NoRect != 2
            INVOKE     FillRect, hDC, addr rect, COLOR_BTNTEXT+1
         .endif
            sub     rect.right, 1
            sub     rect.bottom, 1
         INVOKE     FillRect, hDC, addr rect, COLOR_3DSHADOW+1
          MOVmd     rect.left, rect.right
            add     rect.right, 1
            sub     rect.top, 1 ;2
          MOVmd     rect.bottom, rect.top
            add     rect.bottom, 1
         INVOKE     FillRect, hDC, addr rect, COLOR_3DSHADOW+1
            pop     rect.bottom
            pop     rect.right
            pop     rect.top
            pop     rect.left
      .endif
;---------- [Face size of the button] ---------- 
ChkBorder:
      .if Border
            add     rect.left, 2
            sub     rect.right, 2
            add     rect.top, 2
            sub     rect.bottom, 2
      .endif
      .if NoRect == 3
         INVOKE     FillRect, hDC, addr rect, COLOR_BTNTEXT+1
            sub     rect.left, 3
            sub     rect.right, 3
            sub     rect.top, 3
            sub     rect.bottom, 3
         INVOKE     FillRect, hDC, addr rect, COLOR_BTNTEXT+1
            add     rect.left, 1
            sub     rect.right, 1
            add     rect.top, 1
            sub     rect.bottom, 1
      .endif
      INVOKE     FillRect, hDC, addr rect, BackC ; Background color
      INVOKE     DrawText, hDC, szText, -1, addr rect, DT_CENTER or DT_VCENTER or DT_SINGLELINE
      INVOKE     ReleaseDC, hButt, hDC           ; Release the control dc
         xor    eax, eax
         ret
ButtColor  endp

;=============================================================================
; Copies an image to the face of a Button
;=============================================================================
CopyBitMap  PROC hButt:DWORD, hBmp, bWh, bHt

      INVOKE     GetDC, hButt               ; Get the dc of the button
         mov     hDC, eax
      INVOKE     CreateCompatibleDC, hDC    ; Create a compatible dc in memory
         mov     hMemDC, eax
      INVOKE     SelectObject, hMemDC, hBmp ; Select the opened bitmap into the dc
      INVOKE     BitBlt, hDC, 0, 0, bWh, bHt, hMemDC, 0, 0, SRCCOPY ;Copy the bitmap
      INVOKE     DeleteDC, hMemDC           ; Delete the memory dc
      INVOKE     ReleaseDC, hButt, hDC      ; Release the control dc

         xor    eax, eax
         ret
CopyBitMap  endp

;=============================================================================
; Creates various appearances of Buttons
;=============================================================================
ButtonType4  PROC hButt:DWORD, hBmp, Wh, Ht, hFont, BackC, TextC, szText, Bor, Face, Rect
LOCAL     hOldFont:DWORD, hOldBrush, hSource

      .if Rect && Rect != 5      ; = HotSpot
         INVOKE     CreateRect, hButt, addr rect
          MOVmd     hSource, hWnd
      .else
         INVOKE     GetClientRect, hButt, addr rect
          MOVmd     hSource, hButt
      .endif
      INVOKE     GetDC, hSource
         mov     hDC, eax

      .if Rect == 4 || Rect == 5                 ; Clears the rectangle 
         INVOKE     SetBkMode, hDC, TRANSPARENT  ; Set the text background to transparent
         INVOKE     GetClassWord, hWnd, GCL_HBRBACKGROUND
         INVOKE     SelectObject, hDC, eax       ; Select the window background handle
            mov     hOldBrush, eax
         INVOKE     FillRect, hDC, addr rect, 00000000h ; Can be any color
         INVOKE     SelectObject, hDC, hOldBrush
      .endif

;---------- [Face 0 = Transparent, 1 = Color, and 2 = Bitmap] ----------
      .if Face == 1
         INVOKE     CreateSolidBrush, BackC
            mov     hBR, eax
         INVOKE     FillRect, hDC, addr rect, hBR
         INVOKE     DeleteObject, hBR        ; Delete the brush handle
      .elseif Face == 2
         INVOKE     CopyBitMap, hButt, hBmp, Wh, Ht
      .endif

;---------- [Border 1 = Raised and 2 = Sunken] ----------
      .if Bor == 1
;         INVOKE     DrawEdge, hDC, addr rect, BDR_RAISED, BF_RECT
         INVOKE     DrawEdge, hDC, addr rect, BDR_RAISEDOUTER, BF_TOPLEFT
         INVOKE     DrawEdge, hDC, addr rect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT
      .elseif Bor == 2
         INVOKE     DrawEdge, hDC, addr rect, EDGE_SUNKEN, BF_RECT
            add     rect.left, 4
            add     rect.top, 4
            sub     rect.right, 2
            sub     rect.bottom, 2
      .endif
      INVOKE     SelectObject, hDC, hFont     ; Select the font into the dc
         mov     hOldFont, eax
      INVOKE     SetTextColor, hDC, TextC     ; Set the text color
      INVOKE     SetBkMode, hDC, TRANSPARENT  ; Set the text background to transparent
      INVOKE     DrawText, hDC, szText, -1, addr rect, DT_CENTER or DT_VCENTER or DT_SINGLELINE
      INVOKE     SelectObject, hDC, hOldFont
      INVOKE     ReleaseDC, hSource, hDC      ; Release the control dc
         xor    eax, eax
         ret
ButtonType4  endp

;=============================================================================
; Subclass procedure for the Control Buttons
;=============================================================================
ControlButt  PROC  uses ebx ecx  hwnd:DWORD, wMsg, wParam, lParam
LOCAL     xPos:DWORD, yPos, hOldBrush

      INVOKE     CallWindowProc, SubBmp, hwnd, wMsg, wParam, lParam

      .if wMsg == WM_ERASEBKGND
            mov     eax, hwnd
         .if eax == hButt12
;add     Test4, 1
;DSPValue hWnd, Test4, 1, 't'
            INVOKE     GetDC, hButt12
               mov     hDC, eax
            INVOKE     GetClassWord, hWnd, GCL_HBRBACKGROUND
            INVOKE     SelectObject, hDC, eax    ; Select the window background handle
               mov     hOldBrush, eax
            INVOKE     GetClientRect, hButt12, addr rect
            INVOKE     FillRect, hDC, addr rect, 00000000h ; Can be any color
            INVOKE     SelectObject, hDC, hOldBrush
            INVOKE     ReleaseDC, hButt12, hDC   ; Release the control dc
               mov     eax, 1
               ret
         .endif
      .endif   

      .if wMsg == WM_PAINT

PaintEM:
            mov     eax, hwnd
         .if eax == hButt1
               mov     Butt1D, 0
            INVOKE     CreateSolidBrush, 00000000h
;            INVOKE     CreatePatternBrush, hBitMap
               mov     hBR, eax
            INVOKE     ButtColor, hButt1, hFontB, 000080ffh, 00000000h, eax, addr szStyleB1, 0, 0, 0
            INVOKE     DeleteObject, hBR

;         .elseif eax == hButt2
;               and     Butt2D, 0
;            INVOKE     SendMessage, hButt2, BM_SETIMAGE, IMAGE_BITMAP, hStyleB2U

         .elseif eax == hButt3
               mov     Butt3D, 0
            INVOKE     CopyBitMap, hwnd, hStyleB3U, 113, 26

         .elseif eax == hButt4
               mov     Butt4D, 0
            INVOKE     CopyBitMap, hwnd, hStyleB4U, 161, 53

         .elseif eax == hButt5
               mov     Butt5D, 0
            INVOKE     CreateSolidBrush, 00000000h
               mov     hBR, eax
            INVOKE     ButtColor, hButt5, hFontB, 00008080h, 00000000h, eax, addr szStyleB5, 0, 0, 0
            INVOKE     DeleteObject, hBR

         .elseif eax == hButt6
               mov     Butt6D, 0
            INVOKE     FillRegion, hButt6, 000e79dah, 000e79dah, 00000000h, 00003f7dh, addr szStyleB6

         .elseif eax == hButtP
               mov     ButtPD, 0
            INVOKE     CopyBitMap, hButtP, hStyleBPU, 85, 29

         .elseif eax == hButtE
               mov     ButtED, 0
            INVOKE     CopyBitMap, hButtE, hStyleBEU, 91, 45

         .elseif eax == hButt12
               and     Butt12D, 0
            INVOKE     ButtonType4,  hButt12, 0, 0, 0, hFontB, 0, 00005000h, addr szStyleB12, 0, 0, 0

         .elseif eax == hButt15
               and     Butt15D, 0
            INVOKE     ButtonType4,  hButt15, hStyleBMU, 36, 26, hFontB, 0, 000080ffh, addr szStyleB15, 0, 2, 0

         .elseif eax == hButt18
               and     Butt18D, 0
            INVOKE     ButtonType4,  hButt18, 0, 0, 0, hFontB, 000000ffh, 00ff0000h, addr szStyleB18, 0, 1, 0
         .endif
            jmp     Ret0
      .endif

      .if wMsg == WM_MOUSEMOVE
         INVOKE     GetClientRect, hwnd, addr rect
          MOVmd     bArray, rect.left
          MOVmd     bArray+4, rect.top
          MOVmd     bArray+8, rect.right
          MOVmd     bArray+12, rect.bottom
            mov     eax, lParam
            mov     xPos, eax
            mov     yPos, eax
            and     xPos, 0000ffffh
            shr     yPos, 16
            mov     eax, hwnd
         .if eax != hButt4
            INVOKE     CopyBitMap, hButt4, hStyleB4U, 161, 53
               mov     eax, hwnd
         .endif
         .if eax != hButtE
            INVOKE     CopyBitMap, hButtE, hStyleBEU, 91, 45
               mov     eax, hwnd
         .endif

            mov     ebx, xPos
            mov     ecx, yPos

         .if eax == hButt1
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               .if Butt1D
                  .if Done != 45
                        mov     Done, 45
                     INVOKE     GetSysColor, COLOR_BTNFACE
                       push     eax
;                     INVOKE     CreateSolidBrush, eax
                     INVOKE     CreateHatchBrush, HS_DIAGCROSS, 0000ff00h ;00808080h
                        mov     hBR, eax
                        pop     ebx
                     INVOKE     ButtColor, hButt1, hFontB, 000000ffh, ebx, eax, addr szStyleB1, 1, 0, 0
                     INVOKE     DeleteObject, hBR
                  .endif
               .else
                  .if Done != 46
                        mov     Done, 46
                     INVOKE     SetCapture, hButt1
                     INVOKE     CreateSolidBrush, 00004000h
;                     INVOKE     CreatePatternBrush, hBitMap
                        mov     hBR, eax
                     INVOKE     ButtColor, hButt1, hFontB, 00ffff80h, 00004000h, eax, addr szStyleB1, 1, 1, 0
                     INVOKE     DeleteObject, hBR
                  .endif
               .endif
            .else
               INVOKE     ReleaseCapture
                  jmp     PaintEM
            .endif

         .elseif eax == hButt2
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               .if Done != 2
                     mov     Done, 2
                  .if !Butt2D
                     INVOKE     SetCapture, hButt2
                     INVOKE     SendMessage, hButt2, BM_SETIMAGE, IMAGE_BITMAP, hStyleB2O
                  .endif
               .endif
            .else
                  and     Done, 0
                  and     Butt2D, 0
               INVOKE     ReleaseCapture
               INVOKE     SendMessage, hButt2, BM_SETIMAGE, IMAGE_BITMAP, hStyleB2U
               INVOKE     SetFocus, hWnd
            .endif

         .elseif eax == hButt3
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               .if Done != 3
                     mov     Done, 3
                  INVOKE     SetCapture, hButt3
                  .if Butt3D
                     INVOKE     CopyBitMap, hButt3, hStyleB3D, 113, 26
                  .else
                     INVOKE     CopyBitMap, hButt3, hStyleB3O, 113, 26
                  .endif
               .endif
            .else
               INVOKE     ReleaseCapture
                  jmp     PaintEM
            .endif

         .elseif eax == hButt4
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               .if Done != 4
                     mov     Done, 4
;                  INVOKE     SetCapture, hButt4
                  .if Butt4D
                     INVOKE     CopyBitMap, hButt4, hStyleB4D, 161, 53
                  .else
                     INVOKE     CopyBitMap, hButt4, hStyleB4O, 161, 53
                  .endif
               .endif
            .else
                  and     Done, 0
;               INVOKE     ReleaseCapture
                  jmp     PaintEM
            .endif

         .elseif eax == hButt5
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               .if Butt5D
                  .if Done != 45
                        mov     Done, 45
                     INVOKE     CreateSolidBrush, 00000000h
                        mov     hBR, eax
                     INVOKE     ButtColor, hButt5, hFontB, 000000ffh, 00000000h, eax, addr szStyleB5, 0, 0, 0
                     INVOKE     DeleteObject, hBR
                  .endif
               .else
                  .if Done != 46
                        mov     Done, 46
                     INVOKE     SetCapture, hButt5
                     INVOKE     CreateSolidBrush, 002e6abah
                        mov     hBR, eax
                     INVOKE     ButtColor, hButt5, hFontB, 00ffff80h, 002e6abah, eax, addr szStyleB5, 0, 0, 0
                     INVOKE     DeleteObject, hBR
                  .endif
               .endif
            .else
               INVOKE     ReleaseCapture
                  jmp     PaintEM
            .endif

         .elseif eax == hButt6
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               .if Butt6D
                  .if Done != 45
                        mov     Done, 45
                     INVOKE     GetDC, hButt6
                        mov     hDC, eax
                     INVOKE     CreateSolidBrush, 000000ffh
                        mov     hBR, eax
                     INVOKE     FillRgn, hDC, hRgn, eax
                     INVOKE     DeleteObject, hBR
                     INVOKE     CreateSolidBrush, 0000ff00h
                        mov     hBR, eax
                     INVOKE     FrameRgn, hDC, hRgn, eax, 10, 10
                     INVOKE     DeleteObject, hBR
                     INVOKE     ReleaseDC, hButt6, hDC
                  .endif
               .else
                  .if Done != 46
                        mov     Done, 46
                     INVOKE     SetCapture, hButt6
                     INVOKE     FillRegion, hButt6, 00003f7dh, 00003f7dh, 00ffff80h, 000e79dah, addr szStyleB6
                  .endif
               .endif
            .else
               INVOKE     ReleaseCapture
                  jmp     PaintEM
            .endif

         .elseif eax == hButtP
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               INVOKE     SetCapture, hButtP
               INVOKE     SetFocus, hButtP
               INVOKE     CopyBitMap, hButtP, hStyleBPO, 85, 29
            .else
               INVOKE     ReleaseCapture
                  jmp     PaintEM
            .endif

         .elseif eax == hButtE
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               .if Done != 7
                     mov     Done, 7
;                  INVOKE     SetCapture, hButtE
                  INVOKE     CopyBitMap, hButtE, hStyleBEO, 91, 45
               .endif
            .else
                  and     Done, 0
;               INVOKE     ReleaseCapture
                  jmp     PaintEM
            .endif

         .elseif eax == hButt12
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               INVOKE     SetCapture, hButt12
               .if Butt12D
                  INVOKE     ButtonType4,  hButt12, 0, 0, 0, hFontB, 0, 000000ffh, addr szStyleB12, 2, 0, 5
               .else
                  INVOKE     ButtonType4,  hButt12, 0, 0, 0, hFontB, 0, 00ff0000h, addr szStyleB12, 1, 0, 5
               .endif
            .else
                  and     Butt12D, 0
               INVOKE     ReleaseCapture
               INVOKE     ButtonType4,  hButt12, 0, 0, 0, hFontB, 0, 00005000h, addr szStyleB12, 0, 0, 5
            .endif

         .elseif eax == hButt15
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               INVOKE     SetCapture, hButt15
               .if Butt15D
                  INVOKE     ButtonType4,  hButt15, hStyleBMU, 36, 26, hFontB, 0, 000000ffh, addr szStyleB15, 2, 2, 0
               .else
                  INVOKE     ButtonType4,  hButt15, hStyleBMU, 36, 26, hFontB, 0, 0000ff00h, addr szStyleB15, 1, 2, 0
               .endif
            .else
                  and     Butt15D, 0
               INVOKE     ReleaseCapture
               INVOKE     ButtonType4,  hButt15, hStyleBMU, 36, 26, hFontB, 0, 000080ffh, addr szStyleB15, 0, 2, 0
            .endif

         .elseif eax == hButt18
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               INVOKE     SetCapture, hButt18
               .if Butt18D
                  INVOKE     ButtonType4,  hButt18, 0, 0, 0, hFontB, 00008000h, 00000000h, addr szStyleB18, 2, 1, 0
               .else
                  INVOKE     ButtonType4,  hButt18, 0, 0, 0, hFontB, 00ff0000h, 00000000h, addr szStyleB18, 1, 1, 0
               .endif
            .else
                  and     Butt18D, 0
               INVOKE     ReleaseCapture
               INVOKE     ButtonType4,  hButt18, 0, 0, 0, hFontB, 000000ffh, 00ff0000h, addr szStyleB18, 0, 1, 0
            .endif
         .endif

      .elseif wMsg == WM_LBUTTONDOWN
            mov     eax, hwnd
            and     Done, 0
         .if eax == hButt1
               mov     Butt1D, 1
            INVOKE     GetSysColor, COLOR_BTNFACE
              push     eax
;            INVOKE     CreateSolidBrush, eax
            INVOKE     CreateHatchBrush, HS_DIAGCROSS, 0000ff00h ;00808080h
               mov     hBR, eax
               pop     ebx
            INVOKE     ButtColor, hButt1, hFontB, 000000ffh, ebx, eax, addr szStyleB1, 1, 0, 0
            INVOKE     DeleteObject, hBR

;---------- [Draws a focus rectangle] ----------
;INVOKE     GetDC, hButt1
;   mov     hDC, eax
;   add     rect.left, 2
;   add     rect.top, 2
;   sub     rect.right, 1
;   sub     rect.bottom, 1
;INVOKE     DrawFocusRect, eax, addr rect
;INVOKE     ReleaseDC, hButt1, hDC

         .elseif eax == hButt2
               mov     Butt2D, 1
            INVOKE     SendMessage, hwnd, BM_SETIMAGE, IMAGE_BITMAP, hStyleB2D

         .elseif eax == hButt3
               mov     Butt3D, 1
            INVOKE     CopyBitMap, hButt3, hStyleB3D, 113, 26

         .elseif eax == hButt4
               mov     Butt4D, 1
            INVOKE     CopyBitMap, hButt4, hStyleB4D, 161, 53

         .elseif eax == hButt5
               mov     Butt5D, 1
            INVOKE     CreateSolidBrush, 00000000h
               mov     hBR, eax
            INVOKE     ButtColor, hButt5, hFontB, 000000ffh, 00000000h, eax, addr szStyleB5, 0, 0, 0
            INVOKE     DeleteObject, hBR

         .elseif eax == hButt6
               mov     Butt6D, 1
            INVOKE     GetDC, hButt6
               mov     hDC, eax
            INVOKE     CreateSolidBrush, 000000ffh
               mov     hBR, eax
            INVOKE     FillRgn, hDC, hRgn, eax
            INVOKE     DeleteObject, hBR
            INVOKE     CreateSolidBrush, 0000ff00h
               mov     hBR, eax
            INVOKE     FrameRgn, hDC, hRgn, eax, 10, 10
            INVOKE     DeleteObject, hBR
            INVOKE     ReleaseDC, hButt6, hDC

         .elseif eax == hButtP
            INVOKE     MessageBeep, MB_ICONEXCLAMATION


         .elseif eax == hButt12
               mov     Butt12D, 1
            INVOKE     ButtonType4,  hButt12, 0, 0, 0, hFontB, 0, 000000ffh, addr szStyleB12, 2, 0, 5

         .elseif eax == hButt15
               mov     Butt15D, 1
            INVOKE     ButtonType4,  hButt15, hStyleBMU, 36, 26, hFontB, 0, 000000ffh, addr szStyleB15, 2, 2, 0

         .elseif eax == hButt18
               mov     Butt18D, 1
            INVOKE     ButtonType4,  hButt18, 0, 0, 0, hFontB, 00008000h, 00000000h, addr szStyleB18, 2, 1, 0
         .endif

      .elseif wMsg == WM_LBUTTONUP
            mov     eax, hwnd
            and     Done, 0
         .if eax == hButt1
               and     Butt1D, 0
            INVOKE     CreateSolidBrush, 00004000h
;            INVOKE     CreatePatternBrush, hBitMap
               mov     hBR, eax
            INVOKE     ButtColor, hButt1, hFontB, 00ffff80h, 00004000h, eax, addr szStyleB1, 1, 1, 0
            INVOKE     DeleteObject, hBR

         .elseif eax == hButt2
               and     Butt2D, 0
            INVOKE     SendMessage, hwnd, BM_SETIMAGE, IMAGE_BITMAP, hStyleB2O
            INVOKE     SetFocus, hWnd

         .elseif eax == hButt3
               and     Butt3D, 0
            INVOKE     CopyBitMap, hButt3, hStyleB3O, 113, 26

         .elseif eax == hButt4
               and     Butt4D, 0
            INVOKE     CopyBitMap, hButt4, hStyleB4O, 161, 53

         .elseif eax == hButt5
               and     Butt5D, 0
            INVOKE     CreateSolidBrush, 002e6abah
               mov     hBR, eax
            INVOKE     ButtColor, hButt5, hFontB, 00ffff80h, 002e6abah, eax, addr szStyleB5, 0, 0, 0
            INVOKE     DeleteObject, hBR

         .elseif eax == hButt6
               and     Butt6D, 0
            INVOKE     FillRegion, hButt6, 00003f7dh, 00003f7dh, 00ffff80h, 000e79dah, addr szStyleB6

         .elseif eax == hButt12
               and     Butt12D, 0
            INVOKE     ButtonType4,  hButt12, 0, 0, 0, hFontB, 0, 00ff0000h, addr szStyleB12, 1, 0, 5

         .elseif eax == hButt15
               and     Butt15D, 0
            INVOKE     ButtonType4,  hButt15, hStyleBMU, 36, 26, hFontB, 0, 0000ff00h, addr szStyleB15, 1, 2, 0

         .elseif eax == hButt18
               and     Butt18D, 0
            INVOKE     ButtonType4,  hButt18, 0, 0, 0, hFontB, 00ff0000h, 00000000h, addr szStyleB18, 1, 1, 0
         .endif
      .endif

Ret1:
         mov     eax, TRUE
         ret

Ret0:
         mov     eax, FALSE
         ret
ControlButt  ENDP

;=============================================================================
; Subclass procedure for the Toolbar Buttons
;=============================================================================
ToolbarButt  PROC uses ebx edx hwnd:DWORD, wMsg, wParam, lParam
LOCAL     ps:PAINTSTRUCT
LOCAL     xPos:DWORD, yPos, Done9

      INVOKE     CallWindowProc, SubTool, hwnd, wMsg, wParam, lParam

      .if wMsg == WM_PAINT
            mov     eax, hwnd
         .if eax == hWndTooL11
            .if !Butt11D 
               INVOKE     CopyBitMap, hWndTooL11, hStyleB11U, 113, 26
            .elseif  Butt11D
                  and     Butt11D, 0
               INVOKE     CopyBitMap, hWndTooL11, hStyleB11O, 113, 26
            .else
               INVOKE     CopyBitMap, hWndTooL11, hStyleB11U, 113, 26
            .endif

         .elseif eax == hWndTooL13
            .if !Down
               INVOKE     ButtonType4,  hWndTooL13, 0, 0, 0, hFontB, 0, 00005000h, addr szStyleB13, 0, 0, 0
            .else
               INVOKE     ButtonType4,  hWndTooL13, 0, 0, 0, hFontB, 0, 00ff0000h, addr szStyleB13, 1, 0, 0
            .endif
               and     Down, 0


         .elseif eax == hWndTooL19
            .if !Down
               INVOKE     ButtonType4,  hWndTooL19, 0, 0, 0, hFontB, 00ffffffh, 000000ffh, addr szStyleB19, 0, 1, 0
            .else
               INVOKE     ButtonType4,  hWndTooL19, 0, 0, 0, hFontB, 0000ff00h, 00000000h, addr szStyleB19, 1, 1, 0
            .endif
               and     Down, 0
         .endif
      .endif

;      .if wMsg == WM_ERASEBKGND

      .if wMsg == WM_MOUSEMOVE

         INVOKE     SendMessage, hwnd, TB_GETITEMRECT, 0, addr rect
          MOVmd     bArray, rect.left
          MOVmd     bArray+4, rect.top
          MOVmd     bArray+8, rect.right
          MOVmd     bArray+12, rect.bottom

            mov     eax, lParam
            mov     xPos, eax
            mov     yPos, eax
            and     xPos, 0000ffffh
            shr     yPos, 16
            mov     eax, hwnd
            mov     ebx, xPos
            mov     ecx, yPos
;DSPValue hWnd, lParam, 1, 't'

         .if eax == hWndTooL09
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               .if Done != 09
                     mov     Done, 09
                  INVOKE     SetCapture, hWndTooL09
                  .if Butt09D
                     INVOKE     SendMessage, hWndTooL09, TB_CHANGEBITMAP, 60, 2
                  .else
                     INVOKE     SendMessage, hWndTooL09, TB_CHANGEBITMAP, 60, 1
                  .endif
               .endif
            .else
                  and     Butt09D, 0
                  and     Done, 0
               INVOKE     ReleaseCapture
               INVOKE     SendMessage, hWndTooL09, TB_CHANGEBITMAP, 60, 0
            .endif

         .elseif eax == hWndTooL11
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
                  INVOKE     SetCapture, hWndTooL11
                  .if Butt11D
                     INVOKE     CopyBitMap, hWndTooL11, hStyleB11D, 113, 26
                  .else
                     INVOKE     CopyBitMap, hWndTooL11, hStyleB11O, 113, 26
                  .endif
            .else
                  and     Butt11D, 0
               INVOKE     ReleaseCapture
                  INVOKE     CopyBitMap, hWndTooL11, hStyleB11U, 113, 26
            .endif

         .elseif eax == hWndTooL13
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               INVOKE     SetCapture, hWndTooL13
               .if Butt13D
                  INVOKE     ButtonType4,  hWndTooL13, 0, 0, 0, hFontB, 0, 000000ffh, addr szStyleB13, 2, 0, 5
               .else
                  INVOKE     ButtonType4,  hWndTooL13, 0, 0, 0, hFontB, 0, 00ff0000h, addr szStyleB13, 1, 0, 0
               .endif
            .else
                  and     Butt13D, 0
               INVOKE     ReleaseCapture
               INVOKE     ButtonType4,  hWndTooL13, 0, 0, 0, hFontB, 0, 00005000h, addr szStyleB13, 0, 0, 0
            .endif

         .elseif eax == hWndTooL19
            .if ebx >= bArray && ebx <= bArray+8 && ecx >= bArray+4 && ecx <= bArray+12
               INVOKE     SetCapture, hWndTooL19
               .if Butt19D
                  INVOKE     ButtonType4,  hWndTooL19, 0, 0, 0, hFontB, 00008000h, 00000000h, addr szStyleB19, 2, 1, 0
               .else
                  INVOKE     ButtonType4,  hWndTooL19, 0, 0, 0, hFontB, 0000ff00h, 00000000h, addr szStyleB19, 1, 1, 0
               .endif
            .else
                  and     Butt19D, 0
               INVOKE     ReleaseCapture
               INVOKE     ButtonType4,  hWndTooL19, 0, 0, 0, hFontB, 00ffffffh, 000000ffh, addr szStyleB19, 0, 1, 0
            .endif
         .endif


      .endif

      .if wMsg == WM_LBUTTONDOWN
            and     Done, 0
            mov     eax, hwnd

         .if eax == hWndTooL09
               mov     Butt09D, 1
            INVOKE     SendMessage, hWndTooL09, TB_CHANGEBITMAP, 60, 2

         .elseif eax == hWndTooL11
               mov     Butt11D, 1
            INVOKE     CopyBitMap, hWndTooL11, hStyleB11D, 113, 26

         .elseif eax == hWndTooL13
               mov     Butt13D, 1
            INVOKE     ButtonType4,  hWndTooL13, 0, 0, 0, hFontB, 0, 000000ffh, addr szStyleB13, 2, 0, 5

         .elseif eax == hWndTooL19
               mov     Butt19D, 1
            INVOKE     ButtonType4,  hWndTooL19, 0, 0, 0, hFontB, 00008000h, 00000000h, addr szStyleB19, 2, 1, 0
         .endif
      .endif

      .if wMsg == WM_LBUTTONUP
            and     Done, 0
            mov     eax, hwnd

         .if eax == hWndTooL09
               and     Butt09D, 0
            INVOKE     SendMessage, hWndTooL09, TB_CHANGEBITMAP, 60, 1

         .elseif eax == hWndTooL11
            INVOKE     CopyBitMap, hWndTooL11, hStyleB11O, 113, 26

         .elseif eax == hWndTooL13
               and     Butt13D, 0
               mov     Down, 1

         .elseif eax == hWndTooL19
               and     Butt19D, 0
               mov     Down, 1
         .endif
      .endif

ret_ok:
         mov     eax, TRUE
         ret

ret_error:
         xor     eax, eax   
         ret
ToolbarButt  ENDP

;=================================================================
ReadEM  proc
      INVOKE     CreateFile, addr PathName,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL
         cmp     eax, -1          ; Error?
          je     EndRead

         mov     hFile, eax
         mov     EditS.dwCookie, eax
         mov     EditS.pfnCallback, offset EditStreamRead
         mov     EditS.dwError, 0
      INVOKE     SendMessage, hWndEdit, EM_STREAMIN, SF_RTF, offset EditS

EndRead:
    ret
ReadEM endp

;=================================================================
EditStreamRead PROC uses ebx edi esi dwCookie:DWORD, pbBuff:DWORD, cb:DWORD, pcb:DWORD
      INVOKE     ReadFile, dwCookie, pbBuff, cb, pcb, 0
         mov     ebx, pcb
         mov     eax, [ebx]      ; Get count read so far
         cmp     eax, cb         ; compare to amount needed
         jg      EditRet         ; if read < size, then more to read later
         mov     eax, 0          ; otherwise, file completely read
EditRet: RET
EditStreamRead ENDP

end start
;INVOKE     MessageBox, NULL, addr szOut, addr AppName, MB_OK
