         title   Button Build

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

            include  G:\WebPage\AsmEdit\include\Windows.inc
            include  user32.inc
            include  kernel32.inc
            include  gdi32.inc
            include  comctl32.inc
            include  comdlg32.inc

   include  G:\WebPage\AsmEdit\include\DSPMACRO.asm

         includelib  user32.lib
         includelib  kernel32.lib
         includelib  gdi32.lib
         includelib  comctl32.lib
         includelib  comdlg32.lib

;===================================================
; PROTO, MACRO, and Data section
;===================================================
WinMain         PROTO  :DWORD, :DWORD, :DWORD, :DWORD
RichEditProc    PROTO  :DWORD, :DWORD, :DWORD, :DWORD
ButCtrlDlg      PROTO  :DWORD, :DWORD, :DWORD, :DWORD
ButEditProc     PROTO  :DWORD, :DWORD, :DWORD, :DWORD
AsciiBase       PROTO  :DWORD, :DWORD
ChgBmpColor     PROTO  :DWORD
ReadInput       PROTO  :DWORD

MOVmd    MACRO Var1, Var2
         push     Var2
          pop     Var1
         ENDM

.const
IDM_EXIT       equ 7001
IDM_BUTCTRL    equ 8001

IDM_CUT        equ 1004
IDM_COPY       equ 1005
IDM_PASTE      equ 1006
IDM_DELETE     equ 1007
IDM_SELALL     equ 1008
IDM_DIALOG     equ 8040

IDD_DLG01      equ 2000
IDC_GRP01      equ 2001
IDC_STATIC01   equ 2002
IDC_REDIT01    equ 2003
IDC_REDIT02    equ 2004
IDC_REDIT03    equ 2005
IDC_REDIT04    equ 2006
IDC_REDIT05    equ 2007
IDC_REDIT06    equ 2008
IDC_REDIT07    equ 2009
IDC_REDIT08    equ 2010
IDC_REDIT09    equ 2011
IDC_CHK01      equ 2012
IDC_CHK02      equ 2013
IDC_CHK03      equ 2014
IDC_CHK04      equ 2015
IDC_CHK05      equ 2016
IDC_CHK06      equ 2017
IDC_CHK07      equ 2018
IDC_CHK08      equ 2019
IDC_GRP02      equ 2020
IDC_LISTBOX01  equ 2021
IDC_BUTT01     equ 2022
IDC_BUTT02     equ 2023
IDC_BUTT03     equ 2024
IDC_BUTT04     equ 2025
IDC_BUTT05     equ 2026
IDC_BUTT06     equ 2027
IDC_BUTT07     equ 2028
IDC_BUTT08     equ 2029
IDC_BUTT09     equ 2030
IDC_BUTT10     equ 2031
IDC_BUTT11     equ 2032
IDC_BUTT12     equ 2033

.data
ClassName      db  'ButCtrl',0
AppName        db  'Create Button Control',0
MenuName       db  'MainMenu',0
PopupMenu      db  'PopupMenu',0
RichEdit       db  'RichEdit20A',0
RichEdDLL      db  'RICHED20.DLL',0
StaticClass    db  'static',0
ButtonClass    db  'button',0

FontNameCN     db  'Courier New',0
FontNameMS     db  'MS Sans Serif',0
FontNameC      db  'Challenge Extra Bold',0

szDividerE     db  ' **** Extended Styles ****         ',0
szES01         db  'WS_EX_DLGMODALFRAME   equ 00000001h',0
szES02         db  'WS_EX_WINDOWEDGE      equ 00000100h',0
szES03         db  'WS_EX_CLIENTEDGE      equ 00000200h',0
szES04         db  'WS_EX_STATICEDGE      equ 00020000h',0
szDividerW     db  ' **** Window Styles ****           ',0
szWS01         db  'WS_CHILD              equ 40000000h',0
szWS02         db  'WS_VISIBLE            equ 10000000h',0
szWS03         db  'WS_BORDER             equ 00800000h',0
szWS04         db  'WS_TABSTOP            equ 00010000h',0
szWS05         db  'WS_GROUP              equ 00020000h',0
szDividerC     db  ' **** Control Styles ****          ',0
szBS01         db  'BS_TEXT               equ 00000000h',0
szBS02         db  'BS_PUSHBUTTON         equ 00000000h',0
szBS03         db  'BS_DEFPUSHBUTTON      equ 00000001h',0
szBS04         db  'BS_OWNERDRAW          equ 0000000Bh',0
szBS05         db  'BS_ICON               equ 00000040h',0
szBS06         db  'BS_BITMAP             equ 00000080h',0
szBS07         db  'BS_LEFT               equ 00000100h',0
szBS08         db  'BS_RIGHT              equ 00000200h',0
szBS19         db  'BS_CENTER             equ 00000300h',0
szBS10         db  'BS_TOP                equ 00000400h',0
szBS11         db  'BS_BOTTOM             equ 00000800h',0
szBS12         db  'BS_VCENTER            equ 00000C00h',0
szBS13         db  'BS_MULTILINE          equ 00002000h',0
szBS14         db  'BS_NOTIFY             equ 00004000h',0
szBS15         db  'BS_FLAT               equ 00008000h',0

szMenu1        db  'Hide Dialog',0
szMenu2        db  'Show Dialog',0
szTextC        db  'Text Color',0
szFaceC        db  'Face Color',0
szHiLiteC      db  'HiLite Color',0
szFlat         db  'Flat',0
szRaised       db  'Raised',0
szBlend        db  'Blended',0

szTemplates    db  'Templates\',0
szButtons      db  'Buttons\',0
szButtonO      db  'ButtonO.gen',0
szButtonS      db  'ButtonS.gen',0
szButtonF      db  'ButtonF.gen',0
szButtonR      db  'ButtonR.gen',0
szButtonB      db  'ButtonB.gen',0
szButtonMO     db  'ButtonMO.gen',0

szError1       db  'The RICHED20.DLL was not found!',0
szError2       db  'The Path To The Template Folder',0dh,0ah
               db  ' Is Incorrect or The File Is Missing.',0

szNULL         db  0
szSlashB       db  '\',0
szQuote        db  '"',0
szQuoteS       db  "'",0
szComma        db  ',',0
szClear        db  '                    ',0
szSpace        db  ' ',0
szZero         db  '0',0
szCRLF         db  0dh,0ah,0
szOR           db  ' or ',0

szResr1        db  ';---------- [Place in the Resource file (.rc)] ----------',0dh,0ah,0
szResrB        db  '901    BITMAP  DISCARDABLE  "',0
szResrI        db  '901      ICON  DISCARDABLE  "',0

szFFFF         db  'FFFF',0
szBBTT         db  'BBTT',0
szFFSS         db  'FFSS',0
szFFWW         db  'FFWW',0
szTTCC         db  'TTCC',0
szFFCC         db  'FFCC',0
szHHCC         db  'HHCC',0
szXXSS         db  'XXSS',0
szSSSS         db  'SSSS',0
szPPSS         db  'PPSS',0
szBOFF         db  'BOFF',0
szTOFF         db  'TOFF',0
szROFF         db  'ROFF',0
szDOFF         db  'DOFF',0
szITFF         db  'ITFF',0
szIOFF         db  'IOFF',0
szSSTB         db  'SSTB',0
szSSTI         db  'SSTI',0

szLLII         db  'LLII',0
szGGII         db  'GGII',0
szDDII         db  'DDII',0

szLLBmp        db  0dh,0ah
               db  ';---------- [Load the Image] ----------',0dh,0ah
               db  '         INVOKE     LoadBitmap, hInst, 901',0dh,0ah
               db  '            mov     hImage, eax',0dh,0ah,0
szLLIco        db  0dh,0ah
               db  ';---------- [Load the Image] ----------',0dh,0ah
               db  '         INVOKE     LoadIcon, hInst, 901',0dh,0ah
               db  '            mov     hImage, eax',0dh,0ah,0
szDDImg        db  '         INVOKE     DeleteObject, hImage',0

szGGObj        db  '         INVOKE     GetObject, hImage, lengthof szBuff0, addr szBuff0',0dh,0ah
               db  '          MOVmd     BmpW, dword ptr szBuff0+4',0dh,0ah
               db  '          MOVmd     BmpH, dword ptr szBuff0+8',0dh,0ah,0

szSSBmp        db  '         INVOKE     SendMessage, hButCtrl, BM_SETIMAGE, IMAGE_BITMAP, hImage',0dh,0ah,0
szSSIco        db  '         INVOKE     SendMessage, hButCtrl, BM_SETIMAGE, IMAGE_ICON, hImage',0dh,0ah,0

fmat1          db  '%01u',0
fmat2          db  '%02u',0
fmat4          db  '%08x',0

szExt          db  '*.bmp;*.ico',0
szFilter       db  'Resource Files',0,'*.bmp;*.ico',0,0
szBmp          db  'Res\Wood02.bmp',0

TextC          dd  00000000h
FaceC          dd  00b8b800h
HiLiteC        dd  000000ffh


.data?
hInst          dd  ?
CommandLine    dd  ?
MainExit       dd  ?
hWnd           dd  ?
hREdDll        dd  ?
hREdit         dd  ?
lpRichEdit     dd  ?
lpButEdit      dd  ?
hMenu          dd  ?
hSMenu         dd  ?
hSMenu3        dd  ?
MenuCnt        dd  ?
hFont          dd  ?
hFontB         dd  ?
hFontC         dd  ?
hFontD         dd  ?
hFontBut       dd  ?
hBmp1U         dd  ?
hBmp5U         dd  ?
hBmp5O         dd  ?
hBmp5D         dd  ?
hIco1U         dd  ?

BmpW           dd  ?
BmpH           dd  ?

hButCtrl       dd  ?
lpButCtrl      dd  ?
lpTabChild     dd  ?
hButCtrlDlg    dd  ?
hStat01        dd  ?
hListbox       dd  ?
hEditList      dd  ?

hTabSeL        dd  16  dup(?)
TabSelect      dd  ?

hEdit01        dd  ?
hEdit02        dd  ?
hEdit03        dd  ?
hEdit04        dd  ?
hEdit05        dd  ?
hEdit06        dd  ?
hEdit07        dd  ?
hEdit08        dd  ?
hEdit09        dd  ?

hBut01         dd  ?
hBut02         dd  ?
hBut03         dd  ?

hButt2         dd  ?
hButt3         dd  ?
hButt4         dd  ?
hButt5         dd  ?
Butt5D         dd  ?

hDefHeap       dd  ?
hBuff          dd  ?
hTextOut       dd  ?
hTipOut        dd  ?
hResOut        dd  ?
hBmpOut        dd  ?
hCodeOut       dd  ?
hOutput        dd  ?

hBRD           dd  ?
DrawOn         dd  ?
BmpOn          dd  ?
IcoOn          dd  ?
TransOn        dd  ?
RaisedOn       dd  ?
DepressOn      dd  ?
ImageTextOn    dd  ?
ImageOnlyOn    dd  ?
SizeIToBOn     dd  ?
SizeBToIOn     dd  ?
SavSel         dd  ?
EXStyles       dd  ?
Styles         dd  ?
FontS          dd  ?
FontW          dd  ?
ColorCode      dd  ?
CustClrs       dd  16  dup(?)

Test4          dd  ?

szRoot         db  256 dup(?)
szFontName     db  64  dup(?)
szBuffW        db  64  dup(?)
szButText      db  128 dup(?)

;---------- [Structures] ----------
mii            MENUITEMINFO   <>

.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     GetProcessHeap
         mov     hDefHeap, eax

      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, 480
         shr     eax, 1
        push     eax
      INVOKE     GetSystemMetrics, SM_CYSCREEN
         sub     eax, 410 ;402
         shr     eax, 1
         pop     ebx

;WS_EX_TOPMOST or 
;---------- [Create the Main Window] ----------
      INVOKE     CreateWindowEx, WS_EX_CLIENTEDGE, addr ClassName,\
                 addr AppName, WS_OVERLAPPEDWINDOW,\
                 ebx, eax, 480, 410, NULL, NULL, hInst, NULL
         mov     hWnd, eax

      INVOKE     ShowWindow, hWnd, SW_SHOWNORMAL
      INVOKE     UpdateWindow, hWnd

      INVOKE     GetMenu, hWnd              ; Get handle to main menu
         mov     hMenu, eax

;---------- [Message loop] ----------
      .while TRUE
         INVOKE     GetMessage, addr msg, NULL, 0, 0
            .break .if (!eax)
         INVOKE     IsDialogMessage, hButCtrlDlg, addr msg
            cmp     eax, 0
            jne     Pass
         INVOKE     TranslateMessage, addr msg
         INVOKE     DispatchMessage, addr msg

Pass:
      .endw
         mov     eax, msg.wParam
         ret
WinMain endp

;===================================================
; WinProc procedure
;===================================================
WndProc proc  uses ebx  hwnd:DWORD, wmsg, wparam, lparam
LOCAL    lf:LOGFONT
LOCAL    dis:DRAWITEMSTRUCT
LOCAL    hBrush:DWORD, hTemp, Cnt, ID, Incr, hMemDC, TextColor, uFormat
LOCAL    szBuff0[64]:BYTE, szBuff1[256]:BYTE

;---------- [Create the Control(s) and one time stuff] ----------
      .if wmsg == WM_CREATE

;---------- [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

         INVOKE     RtlZeroMemory, addr lf, sizeof lf
         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontNameCN
            mov     lf.lfHeight, -12
            mov     lf.lfWeight, 500
         INVOKE     CreateFontIndirect, addr lf
            mov     hFont, eax    ; RichEdit font

         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontNameMS
            mov     lf.lfHeight, -8
            mov     lf.lfWeight, 400
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontD, eax   ; Dialog font

;---------- [Create the Button Font] ----------
         INVOKE     lstrcpy, addr szFontName, addr FontNameMS
            mov     FontS, 14
            mov     FontW, 600
            mov     lf.lfHeight, 14
            mov     lf.lfWeight, 600
         INVOKE     CreateFontIndirect, ADDR lf
            mov     hFontB, eax

         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontNameC
            mov     lf.lfHeight, 32
            mov     lf.lfWeight, 600
         INVOKE     CreateFontIndirect, ADDR lf
            mov     hFontC, eax

         INVOKE     SendMessage, hREdit, WM_SETFONT, hFont, TRUE

;---------- [Load The Bitmaps] ----------
         INVOKE     LoadBitmap, hInst, 901
            mov     hBmp1U, eax
         INVOKE     LoadBitmap, hInst, 902
            mov     hBmp5U, eax
         INVOKE     LoadBitmap, hInst, 903
            mov     hBmp5O, eax
         INVOKE     LoadBitmap, hInst, 904
            mov     hBmp5D, eax
         INVOKE     LoadIcon, hInst, 905
            mov     hIco1U, eax

         INVOKE     GetObject, hBmp1U, lengthof szBuff1, addr szBuff1
          MOVmd     BmpW, dword ptr szBuff1+4
          MOVmd     BmpH, dword ptr szBuff1+8

;---------- [Allocate memory from the default heap] ----------
         INVOKE     HeapAlloc, hDefHeap, 0, 51200
            mov     hBuff, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 4096
            mov     hTextOut, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 4096
            mov     hTipOut, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 4096
            mov     hResOut, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 4096
            mov     hBmpOut, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 4096
            mov     hCodeOut, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 20000
            mov     hOutput, eax

            mov     mii.cbSize, sizeof mii
            mov     mii.fMask, MIIM_DATA or MIIM_ID or MIIM_STATE or\
                               MIIM_SUBMENU or MIIM_TYPE or MIIM_CHECKMARKS

;---------- [Get the current dir] ----------
         INVOKE     GetCurrentDirectory, lengthof szRoot, addr szRoot
         INVOKE     lstrcat, addr szRoot, addr szSlashB

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

;---------- [Size the Edit Control] ----------
            xor     eax, eax             ; Zero out toolbar height
           push     eax                  ; Save height of toolbar

            xor     eax, eax             ; Zero out statusbar height

            pop     edx                  ; edx = height of toolbar
            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
         INVOKE     MoveWindow, hREdit, 0, edx, ebx, ecx, TRUE

      .elseif wmsg == WM_NOTIFY
            jmp     DefWin

      .elseif wmsg == WM_DRAWITEM
         .if wparam == 702
               mov     esi, lparam
               lea     eax, dis
               mov     edi, eax
               mov     ecx, sizeof dis
               rep     movsb
            .if dis.itemID != -1

               .if BmpOn || TransOn
                  INVOKE     GetParent, hButCtrl
                  .if eax == hWnd
                     INVOKE     GetSysColor, COLOR_BTNFACE
                     INVOKE     CreateSolidBrush, eax
                  .else
                     INVOKE     CreateSolidBrush, 00ffffe0h
                  .endif
                     mov     hBrush, eax
                  INVOKE     FillRect, dis.hdc, addr dis.rcItem, eax
                  INVOKE     DeleteObject, hBrush
               .endif

               .if BmpOn
                     mov     eax, hBmp1U
                     mov     hTemp, eax

                  .if (dis.itemState & ODS_SELECTED)
                        add     dis.rcItem.left, 1
                        add     dis.rcItem.top, 1
                  .endif

                  INVOKE     CreateCompatibleDC, dis.hdc ; Create a compatible dc in memory
                     mov     hMemDC, eax

                  INVOKE     SelectObject, hMemDC, hTemp ; Select the opened bitmap into the dc
                  .if !SizeIToBOn
                     INVOKE     BitBlt, dis.hdc, dis.rcItem.left, dis.rcItem.top,\
                                BmpW, BmpH, hMemDC, 0, 0, SRCCOPY
                  .else
                     INVOKE     StretchBlt, dis.hdc, dis.rcItem.left, dis.rcItem.top,\
                                dis.rcItem.right, dis.rcItem.bottom, hMemDC, 0, 0, BmpW, BmpH, SRCCOPY
                  .endif
                  INVOKE     DeleteDC, hMemDC            ; Delete the memory dc
                   MOVmd     TextColor, TextC
                  .if (dis.itemState & ODS_SELECTED)
                      MOVmd     TextColor, HiLiteC
                        sub     dis.rcItem.left, 1
                        sub     dis.rcItem.top, 1
                  .endif

               .else
                   MOVmd     TextColor, TextC
                  .if (dis.itemState & ODS_SELECTED)
                      MOVmd     TextColor, HiLiteC
                  .endif
               .endif

               .if !TransOn
                  INVOKE     CreateSolidBrush, FaceC
                     mov     hBrush, eax
               .else

                  INVOKE     GetParent, hButCtrl
                  .if eax == hWnd
                     INVOKE     GetSysColor, COLOR_BTNFACE
                     INVOKE     CreateSolidBrush, eax
                  .else
                     INVOKE     CreateSolidBrush, 00ffffe0h
                  .endif
                     mov     hBrush, eax
               .endif

                  mov     uFormat, DT_CENTER or DT_VCENTER or DT_SINGLELINE
               .if !BmpOn
                  INVOKE     FillRect, dis.hdc, addr dis.rcItem, hBrush
               .endif
               INVOKE     SetTextColor, dis.hdc, TextColor
               .if !TransOn
                  INVOKE     SetBkColor, dis.hdc, FaceC
               .else
                  INVOKE     SetBkMode, dis.hdc, TRANSPARENT  ; Set the text background to transparent
               .endif
               .if (dis.itemState & ODS_SELECTED)
                  .if DepressOn
                     INVOKE     DrawEdge, dis.hdc, addr dis.rcItem, EDGE_SUNKEN, BF_RECT
                  .endif
                     add     dis.rcItem.left, 2
                     add     dis.rcItem.top, 2
                  .else
                     .if RaisedOn
                        INVOKE     DrawEdge, dis.hdc, addr dis.rcItem, EDGE_RAISED, BF_RECT
                     .endif
               .endif
               .if !ImageOnlyOn
                  INVOKE     DrawText, dis.hdc, addr szButText, -1, addr dis.rcItem, uFormat
               .endif
               INVOKE     DeleteObject, hBrush
            .endif
               mov     dis.itemState, ODS_DEFAULT
               mov     dis.hdc, 0
         .endif

;---------- [System and user commands] ----------
      .elseif wmsg == WM_COMMAND
            mov     eax, wparam
           cwde                          ; Only low word contains command

         .if 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_BUTCTRL && !hButCtrlDlg
            INVOKE     CreateDialogParam, hInst, IDD_DLG01, hwnd, addr ButCtrlDlg, 0
               mov     hButCtrlDlg, eax

         .elseif eax == IDM_DIALOG
            INVOKE     IsWindowVisible, hButCtrlDlg
            .if !eax
               INVOKE     ShowWindow, hButCtrlDlg, SW_SHOWDEFAULT
                  mov     eax, offset szMenu1
                  mov     mii.dwTypeData, eax
            .else
               INVOKE     ShowWindow, hButCtrlDlg, SW_HIDE
                  mov     eax, offset szMenu2
                  mov     mii.dwTypeData, eax
            .endif
            INVOKE     SetMenuItemInfo, hMenu, 2, TRUE, addr mii
            INVOKE     DrawMenuBar, hWnd
            INVOKE     ShowWindow, hREdit, SW_HIDE

         .endif

      .elseif wmsg == WM_CLOSE
            and     Incr, 0
            mov     Cnt, 10
         .while (Cnt)
               mov     eax, Incr
               mov     ecx, hFont[eax*4]
            INVOKE     DeleteObject, ecx
               inc     Incr
               dec     Cnt
         .endw

            and     Incr, 0
            mov     Cnt, 7
         .while (Cnt)
               mov     eax, Incr
               mov     ecx, hBuff[eax*4]
            INVOKE     HeapFree, hDefHeap, 0, ecx
               inc     Incr
               dec     Cnt
         .endw

         INVOKE     DestroyWindow, hwnd

      .elseif wmsg == WM_DESTROY
         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

;======================================================
; SubClass the Tab Edit control procedure
;======================================================
ButEditProc PROC hwnd:DWORD, wmsg, wparam, lparam

      .if hButCtrlDlg
         .if wmsg == WM_KEYUP ;&& wparam == 0dh  ; Enter key
            INVOKE     GetDlgItemText, hButCtrlDlg, IDC_REDIT05, addr szButText, lengthof szButText
         .endif
      .endif

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

         ret
ButEditProc ENDP

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

      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     StretchBlt, hDC, 0, 0, bWh, bHt, hMemDC, 0, 0, 115, 26, SRCCOPY

      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
;=============================================================================
ButtonType  PROC hButt:DWORD, hFontT, BackClr, TextClr, szText, Bor
LOCAL     rect:RECT
LOCAL     hOldFont:DWORD, hBR, hDC

      INVOKE     GetDC, hButt
         mov     hDC, eax
         mov     eax, hButt
      .if Bor == 2 && eax == hButt4
;            mov     BackClr, 00ffffe9h
;         INVOKE     CreateSolidBrush, BackClr
         INVOKE     CreateHatchBrush, HS_DIAGCROSS, 00008000h
      .elseif Bor == 2
            mov     BackClr, 00929292h
         INVOKE     CreateSolidBrush, BackClr
      .else
         INVOKE     CreateSolidBrush, BackClr
      .endif
         mov     hBR, eax
      INVOKE     GetClientRect, hButt, addr rect
      INVOKE     FillRect, hDC, addr rect, hBR
      INVOKE     DeleteObject, hBR             ; Delete the brush handle
         mov     eax, hButt

      .if Bor == 1 && eax != hButt2 && eax != hButt4
         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
      .endif
      INVOKE     SelectObject, hDC, hFontT     ; Select the font into the dc
         mov     hOldFont, eax
         mov     eax, hButt
      .if  Bor == 2 && eax == hButt4
         INVOKE     SetTextColor, hDC, 000000ffh
      .else
         INVOKE     SetTextColor, hDC, TextClr ; Set the text color
      .endif
      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, hButt, hDC         ; Release the control dc

         xor    eax, eax
         ret
ButtonType  ENDP

;======================================================
; SubClass the Button control procedure
;======================================================
ButCtrlProc PROC hwnd:DWORD, wmsg, wparam, lparam
LOCAL    rect:RECT
LOCAL    rectB:RECT
LOCAL    UpDown:DWORD, hBR
LOCAL    szText[64]:BYTE


      INVOKE     CallWindowProc, lpButCtrl, hwnd, wmsg, wparam, lparam
         mov     eax, hwnd
      .if eax == hButt5
         INVOKE     GetClientRect, hwnd, addr rectB
      .endif

         mov     UpDown , 1
      .if wmsg == WM_PAINT

PaintEM:
            mov     eax, hwnd
         .if eax == hBut01 ;hButCtrl
            INVOKE     ButtonType, hwnd, hFontB, FaceC, TextC, addr szTextC, UpDown
         .elseif eax == hBut02
            INVOKE     ButtonType, hwnd, hFontB, FaceC, TextC, addr szFaceC, UpDown
         .elseif eax == hBut03
            INVOKE     ButtonType, hwnd, hFontB, FaceC, HiLiteC, addr szHiLiteC, UpDown
         .elseif eax == hButt2
            INVOKE     ButtonType, hButt2, hFontB, 0000a000h, 00000000h, addr szFlat, UpDown
         .elseif eax == hButt3
            INVOKE     ButtonType, hButt3, hFontB, 00ffa000h, 00000000h, addr szRaised, UpDown
         .elseif eax == hButt4
            INVOKE     ButtonType, hButt4, hFontC, 00ffffe0h, 00800000h, addr szBlend, UpDown
         .elseif eax == hButt5
               mov     Butt5D, 0
            INVOKE     CopyBitMap, hwnd, hBmp5U, rectB.right, rectB.bottom ;115, 26

         .endif
            mov     UpDown, 1

      .elseif wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONDBLCLK
            mov     eax, hwnd
         .if eax == hButt5
               mov     Butt5D, 1
            INVOKE     CopyBitMap, hButt5, hBmp5D, rectB.right, rectB.bottom ;115, 26
         .else
            mov     UpDown, 2
            jmp     PaintEM
         .endif

      .elseif wmsg == WM_MOUSEMOVE
         INVOKE     GetClientRect, hwnd, addr rect
            mov     ebx, lparam
            mov     ecx, ebx
            and     ebx, 0000ffffh
            shr     ecx, 16
            mov     eax, hwnd
         .if eax == hButt5
            .if ebx >= rect.left && ebx <= rect.right && ecx >= rect.top && ecx <= rect.bottom
               INVOKE     SetCapture, hButt5
               .if Butt5D
                  INVOKE     CopyBitMap, hButt5, hBmp5D, rectB.right, rectB.bottom ;115, 26
               .else
                  INVOKE     CopyBitMap, hButt5, hBmp5O, rectB.right, rectB.bottom ;115, 26
               .endif
            .else
               INVOKE     ReleaseCapture
                  jmp     PaintEM
            .endif
               jmp     Ret1
         .endif
         .if wparam == MK_LBUTTON
               mov     UpDown, 2
         .else
               mov     UpDown, 1
         .endif
            jmp     PaintEM

      .elseif wmsg == WM_LBUTTONUP
            mov     eax, hwnd
         .if eax == hButt5
               and     Butt5D, 0
            INVOKE     CopyBitMap, hButt5, hBmp5O, rectB.right, rectB.bottom ;115, 26
         .else
            mov     UpDown, 1
            jmp     PaintEM
         .endif
      .endif

Ret1:
         mov     eax, TRUE
         ret
ButCtrlProc ENDP

;======================================================
; Create Button Control PROCEDURE
;======================================================
ButCtrlDlg PROC uses ebx esi edi hdlg:DWORD, wmsg, wparam, lparam
LOCAL    rect:RECT
LOCAL    rectB:RECT
LOCAL    ofn:OPENFILENAME
LOCAL    Cnt:DWORD, Incr, Index, hTemp, xPos, yPos, Wth, Hgt
LOCAL    szBuff0[256]:BYTE, szBuff1[64]:BYTE, szBuff2[20]:BYTE, szArray[256]:BYTE

      .if wmsg == WM_INITDIALOG
         INVOKE     GetDlgItem, hdlg, IDC_STATIC01
            mov     hStat01, eax
         INVOKE     SetFocus, hStat01
         INVOKE     GetDlgItem, hdlg, IDC_LISTBOX01
            mov     hListbox, eax
         INVOKE     SendMessage, hListbox, WM_SETFONT, hFontD, TRUE
            lea     eax, offset szDividerE
            mov     Index, eax
            mov     Cnt, 27
         .while (Cnt)
               mov     ecx, Index
            INVOKE     lstrcpy, addr szBuff1, ecx
            .if byte ptr szBuff1+2 != '*'
               INVOKE     lstrcpyn, addr szBuff2, addr szBuff1+26, 9
               INVOKE     AsciiBase, addr szBuff2, 16
                  mov     Styles, eax
                  xor     eax, eax
                  mov     ecx, 26
               .while (ecx)
                  .if byte ptr szBuff1[eax] == ' '
                        mov     byte ptr szBuff1[eax], 0
                     .break
                  .endif
                     inc     eax
                     dec     ecx
               .endw

            .else
               INVOKE     lstrcpyn, addr szBuff2, addr szBuff2, 26
                  mov     Styles, 1234
            .endif
            INVOKE     SendMessage, hListbox, LB_ADDSTRING, 0, addr szBuff1
               mov     ecx, eax
            INVOKE     SendMessage, hListbox, LB_SETITEMDATA, ecx, Styles
               add     Index, 36
               dec     Cnt
         .endw

         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 6
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 7
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 12
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 13
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 20
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 23

         INVOKE     CreatePopupMenu
            mov     hSMenu3, eax
            mov     mii.fType, MFT_STRING
            mov     mii.wID, IDM_DIALOG
            mov     mii.hSubMenu, 0
            mov     mii.dwItemData, 8040
            mov     eax, offset szMenu1
            mov     mii.dwTypeData, eax
         INVOKE     InsertMenuItem, hMenu, 2, TRUE, addr mii   ; Adds new menu
         INVOKE     DrawMenuBar, hWnd

            and     Index, 0
            mov     Incr, IDC_REDIT01
            mov     Cnt, 9
         .while (Cnt)
            INVOKE     GetDlgItem, hdlg, Incr
               mov     ecx, Index
               mov     hEdit01[ecx*4], eax
               mov     ecx, eax
               mov     edx, hFontD
            INVOKE     SendMessage, ecx, WM_SETFONT, edx, TRUE
               inc     Index
               inc     Incr
               dec     Cnt
         .endw

            and     Index, 0
            mov     Incr, IDC_BUTT04
            mov     Cnt, 3
         .while (Cnt)
            INVOKE     GetDlgItem, hdlg, Incr
               mov     ecx, Index
               mov     hBut01[ecx*4], eax
               mov     hTemp, eax
               mov     ecx, eax
               mov     edx, hFontD
            INVOKE     SendMessage, ecx, WM_SETFONT, edx, TRUE

;---------- [Control window subclassed] ----------
            INVOKE     SetWindowLong, hTemp, GWL_WNDPROC, ButCtrlProc
               mov     lpButCtrl, eax

               inc     Index
               inc     Incr
               dec     Cnt
         .endw

         INVOKE     GetCurrentDirectory, lengthof szBuff0, addr szBuff0
         INVOKE     lstrcat, addr szBuff0, addr szSlashB
         INVOKE     lstrcat, addr szBuff0, addr szBmp

         INVOKE     SetDlgItemInt, hdlg, IDC_REDIT01, 100, 0
         INVOKE     SetDlgItemInt, hdlg, IDC_REDIT02, 50, 0
         INVOKE     SetDlgItemInt, hdlg, IDC_REDIT03, 100, 0
         INVOKE     SetDlgItemInt, hdlg, IDC_REDIT04, 40, 0
         INVOKE     SetDlgItemText, hdlg, IDC_REDIT06, addr szBuff0
         INVOKE     SetDlgItemText, hdlg, IDC_REDIT07, addr szFontName
         INVOKE     SetDlgItemInt, hdlg, IDC_REDIT08, FontS, 0
         INVOKE     SetDlgItemInt, hdlg, IDC_REDIT09, FontW, 0

         INVOKE     SendMessage, hEdit01, EM_LIMITTEXT, 3, 0 ; Limit text size
         INVOKE     SendMessage, hEdit02, EM_LIMITTEXT, 3, 0
         INVOKE     SendMessage, hEdit03, EM_LIMITTEXT, 3, 0
         INVOKE     SendMessage, hEdit04, EM_LIMITTEXT, 3, 0
         INVOKE     SendMessage, hEdit05, EM_LIMITTEXT, 128, 0
         INVOKE     SendMessage, hEdit08, EM_LIMITTEXT, 2, 0
         INVOKE     SendMessage, hEdit09, EM_LIMITTEXT, 3, 0

         INVOKE     SendMessage, hEdit05, WM_SETTEXT, 0, addr ClassName

;---------- [Control window subclassed] ----------
         INVOKE     SetWindowLong, hEdit05, GWL_WNDPROC, ButEditProc
            mov     lpButEdit, eax

comment^
         INVOKE     CreateWindowEx, NULL, addr ButtonClass, addr szFlat,
                    WS_CHILD or WS_VISIBLE,
                    340, 72, 115, 26, hdlg, 2030, hInst, 0
            mov     hButt2, eax
         INVOKE     SetWindowLong, hButt2, GWL_WNDPROC, ButCtrlProc
            mov     lpButCtrl, eax
  
         INVOKE     CreateWindowEx, NULL, addr ButtonClass, addr szRaised,
                    WS_CHILD or WS_VISIBLE,
                    340, 108, 115, 26, hdlg, 2031, hInst, 0
            mov     hButt3, eax
         INVOKE     SetWindowLong, hButt3, GWL_WNDPROC, ButCtrlProc
            mov     lpButCtrl, eax

         INVOKE     CreateWindowEx, NULL, addr ButtonClass, addr szBlend,
                    WS_CHILD or WS_VISIBLE,
                    340, 144, 115, 26, hdlg, 2032, hInst, 0
            mov     hButt4, eax
         INVOKE     SetWindowLong, hButt4, GWL_WNDPROC, ButCtrlProc
            mov     lpButCtrl, eax

            and     Butt5D, 0
         .if hButt5
            INVOKE     DestroyWindow, hButt5
         .endif
         INVOKE     CreateWindowEx, 0, addr ButtonClass, 0,
                    WS_CHILD or WS_VISIBLE or BS_OWNERDRAW,
                    340, 180, 115, 26, hdlg, 2033, hInst, 0
            mov     hButt5, eax
         INVOKE     SetWindowLong, hButt5, GWL_WNDPROC, ButCtrlProc
            mov     lpButCtrl, eax
^

            and     Butt5D, 0
         .if hButt5
            INVOKE     DestroyWindow, hButt5
         .endif

            and     Index, 0
            mov     Incr, IDC_BUTT09
            mov     Cnt, 4
         .while (Cnt)
            INVOKE     GetDlgItem, hdlg, Incr
               mov     ecx, Index
               mov     hButt2[ecx*4], eax
               mov     hTemp, eax
               mov     ecx, eax
;               mov     edx, hFontD
;            INVOKE     SendMessage, ecx, WM_SETFONT, edx, TRUE

;---------- [Control window subclassed] ----------
            INVOKE     SetWindowLong, hTemp, GWL_WNDPROC, ButCtrlProc
               mov     lpButCtrl, eax

               inc     Index
               inc     Incr
               dec     Cnt
         .endw


      .elseif wmsg == WM_CTLCOLORDLG || wmsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wparam, 00ffffe0h
         INVOKE     SetTextColor, wparam, 00000000h
         .if hBRD
            INVOKE     DeleteObject, hBRD
         .endif
         INVOKE     CreateSolidBrush, 00ffffe0h
            mov     hBRD, eax
            ret

      .elseif wmsg == WM_CTLCOLORLISTBOX || wmsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wparam, 00000000h
         INVOKE     SetTextColor, wparam, 00ffff00h
         INVOKE     GetStockObject, BLACK_BRUSH
            ret

      .elseif wmsg == WM_DRAWITEM
         .if wparam == 702
            INVOKE     SendMessage, hWnd, WM_DRAWITEM, wparam, lparam
         .endif

      .elseif wmsg == WM_COMMAND
            mov     ecx, lparam
            mov     eax, wparam
            mov     edx, wparam
            shr     eax, 16

         .if edx >= IDC_CHK01 && edx <= IDC_CHK08 ||\
             edx >= IDC_BUTT01 && edx <= IDC_BUTT08
            INVOKE     SetFocus, hStat01
         .endif

;---------- [Check Listbox selection] ----------
         .if eax == LBN_SELCHANGE && ecx == hListbox
            INVOKE     SendMessage, hListbox, LB_GETCARETINDEX, 0, 0
               mov     SavSel, eax
            INVOKE     SendMessage, hListbox, LB_GETSEL, SavSel, 0
              push     eax
;            INVOKE     SendMessage, hListbox, LB_GETTEXT, SavSel, addr szBuff1
            .if eax && SavSel == 15
                  mov     Incr, 12
                  mov     Cnt, 15
               .while (Cnt)
                  .if Incr != 17
                     INVOKE     SendMessage, hListbox, LB_SETSEL, 0, Incr
                  .endif
                     inc     Incr
                     dec     Cnt
               .endw
               INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 15
            .elseif eax && SavSel == 12
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 16
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 17
            .elseif eax && SavSel == 13
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 14
            .elseif eax && SavSel == 14
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 13
            .elseif eax && SavSel == 16
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 12
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 17
            .elseif eax && SavSel == 17
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 12
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 16
            .elseif eax && SavSel == 18
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 19
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 20
            .elseif eax && SavSel == 19
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 18
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 20
            .elseif eax && SavSel == 20
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 18
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 19
            .elseif eax && SavSel == 21
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 22
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 23
            .elseif eax && SavSel == 22
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 23
            .elseif eax && SavSel == 23
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 22
            .endif
               pop     eax
            .if eax && SavSel > 11 && SavSel != 15 && SavSel != 17
               INVOKE     SendMessage, hListbox, LB_SETSEL, 0, 15
            .endif
         .endif

         .if wparam == IDCANCEL
               jmp     CloseIt

;----------[IDC_BUTT03 = Browse fo Bitmap] ----------
         .elseif wparam == IDC_BUTT03
            INVOKE     RtlZeroMemory, addr ofn, sizeof ofn
;            INVOKE     lstrcpy, addr szBuff0, addr szExt
            INVOKE     lstrcpy, addr szBuff0, addr szRoot
            INVOKE     lstrcat, addr szBuff0, addr szBmp
               mov     ofn.lStructSize, sizeof ofn
               mov     ofn.lpstrFilter, offset szFilter
               lea     eax, szBuff0
               mov     ofn.lpstrFile, eax
               mov     ofn.nMaxFile, lengthof szBuff0
               mov     ofn.Flags, OFN_NOVALIDATE
            INVOKE     GetOpenFileName, addr ofn
               cmp     eax, FALSE        ; Cancel'ed or error occurred
                je     DlgDone

            INVOKE     SetDlgItemText, hdlg, IDC_REDIT06, addr szBuff0
            INVOKE     LoadImage, 0, addr szBuff0, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR or LR_LOADFROMFILE
               mov     hBmp1U, eax
            INVOKE     GetObject, hBmp1U, lengthof szBuff0, addr szBuff0
             MOVmd     BmpW, dword ptr szBuff0+4
             MOVmd     BmpH, dword ptr szBuff0+8
            .if SizeBToIOn
               INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT03, BmpW, 0
               INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT04, BmpH, 0
            .endif
            INVOKE     SetWindowPos, hWnd, HWND_TOPMOST, 0, 0, 0, 0,\
                       SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW
               jmp     DlgDone

;---------- [IDC_CHK01 = Transparent] ----------
         .elseif wparam == IDC_CHK01
               and     TransOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, IDC_CHK01
            .if eax
                  mov     TransOn, 1
            .endif

;---------- [IDC_CHK02 = Raised  rectangle] ----------
         .elseif wparam == IDC_CHK02
               and     RaisedOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, IDC_CHK02
            .if eax
                  mov     RaisedOn, 1
            .endif

;---------- [IDC_CHK03 = Depress  rectangle] ----------
         .elseif wparam == IDC_CHK03
               and     DepressOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, IDC_CHK03
            .if eax
                  mov     DepressOn, 1
            .endif

;---------- [IDC_CHK04 = Use Images and Text] ----------
         .elseif wparam == IDC_CHK04
               and     ImageTextOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, IDC_CHK04
            .if eax
                  mov     ImageTextOn, 1
                  and     ImageOnlyOn, 0
               INVOKE     SendDlgItemMessage, hdlg, IDC_CHK05, BM_SETCHECK, BST_UNCHECKED, 0
            .endif

;---------- [IDC_CHK05 = Use Images only] ----------
         .elseif wparam == IDC_CHK05
               and     ImageOnlyOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, IDC_CHK05
            .if eax
                  mov     ImageOnlyOn, 1
                  and     ImageTextOn, 0
               INVOKE     SendDlgItemMessage, hdlg, IDC_CHK04, BM_SETCHECK, BST_UNCHECKED, 0
            .endif

;---------- [IDC_CHK06 = Size Image to Button] ----------
         .elseif wparam == IDC_CHK06
               and     SizeIToBOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, IDC_CHK06
            .if eax
                  mov     SizeIToBOn, 1
                  and     SizeBToIOn, 0
               INVOKE     SendDlgItemMessage, hdlg, IDC_CHK07, BM_SETCHECK, BST_UNCHECKED, 0
               INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT03, 100, 0
               INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT04, 40, 0
            .endif

;---------- [IDC_CHK07 = Size Button to Image] ----------
         .elseif wparam == IDC_CHK07
               and     SizeBToIOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, IDC_CHK07
            .if eax
                  mov     SizeBToIOn, 1
                  and     SizeIToBOn, 0
               INVOKE     SendDlgItemMessage, hdlg, IDC_CHK06, BM_SETCHECK, BST_UNCHECKED, 0
               INVOKE     GetObject, hBmp1U, lengthof szBuff0, addr szBuff0
                MOVmd     BmpW, dword ptr szBuff0+4
                MOVmd     BmpH, dword ptr szBuff0+8
               INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT03, BmpW, 0
               INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT04, BmpH, 0
            .else
               INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT03, 100, 0
               INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT04, 40, 0
            .endif

;---------- [IDC_BUTT01 = Quick View - IDC_BUTT02 = Preview] ----------
         .elseif wparam == IDC_BUTT01 || wparam == IDC_BUTT02
            .if hButCtrl
               INVOKE     DestroyWindow, hButCtrl
                  and     hButCtrl, 0
            .endif
            INVOKE     SendDlgItemMessage, hdlg, IDC_CHK08, BM_SETCHECK, BST_UNCHECKED, 0
            .if wparam == IDC_BUTT02
               INVOKE     ShowWindow, hREdit, SW_HIDE
            .endif
            INVOKE     GetDlgItemInt, hButCtrlDlg, IDC_REDIT01, 0, 0
               mov     xPos, eax
            INVOKE     GetDlgItemInt, hButCtrlDlg, IDC_REDIT02, 0, 0
               mov     yPos, eax
            INVOKE     GetDlgItemInt, hButCtrlDlg, IDC_REDIT03, 0, 0
               mov     Wth, eax
            .if !eax
                  jmp     DoError
            .endif
            INVOKE     GetDlgItemInt, hButCtrlDlg, IDC_REDIT04, 0, 0
               mov     Hgt, eax
            .if !eax
                  jmp     DoError
            .endif

            INVOKE     GetDlgItemText, hButCtrlDlg, IDC_REDIT05, addr szButText, lengthof szButText

              call     GetStyles
              call     SetCode

            .if wparam == IDC_BUTT01
               INVOKE     GetSystemMetrics, SM_CYCAPTION
                  dec     eax
                 push     eax
               INVOKE     GetWindowRect, hdlg, addr rect
               INVOKE     GetWindowRect, hBut01, addr rectB ;hBut03 hEdit01
                  mov     eax, rect.left
                  mov     ebx, rect.top
                  sub     rectB.right, eax
                  sub     rectB.top, ebx
                  mov     ebx, rectB.right
                  mov     ecx, rectB.top
                  add     ebx, 5
                  pop     eax
                  sub     ecx, eax
                  mov     edx, hButCtrlDlg
            .else
                  mov     ebx, xPos
                  mov     ecx, yPos
                  mov     edx, hWnd
            .endif

;---------- [Create the Button control] ----------
            INVOKE     CreateWindowEx, EXStyles, addr ButtonClass, addr szButText,\
                       Styles,\
                       ebx, ecx, Wth, Hgt, edx, 702, hInst, NULL
               mov     hButCtrl, eax

;---------- [Tab Control window subclassed] ----------
;            INVOKE     SetWindowLong, hButCtrl, GWL_WNDPROC, ButCtrlProc
;               mov     lpButCtrl, eax

            .if BmpOn
               INVOKE     SendMessage, hButCtrl, BM_SETIMAGE, IMAGE_BITMAP, hBmp1U
            .elseif IcoOn
               INVOKE     SendMessage, hButCtrl, BM_SETIMAGE, IMAGE_ICON, hIco1U
            .endif

            INVOKE     SendMessage, hButCtrl, WM_SETFONT, hFontBut, TRUE

            .if wparam == IDC_BUTT02
               INVOKE     ShowWindow, hButCtrlDlg, SW_HIDE
                  mov     eax, offset szMenu2
                  mov     mii.dwTypeData, eax
               INVOKE     SetMenuItemInfo, hMenu, 2, TRUE, addr mii
               INVOKE     DrawMenuBar, hWnd
            .endif

            INVOKE     SetWindowPos, hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,\
                       SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW

            .if wparam == IDC_BUTT01
               INVOKE     SetWindowPos, hButCtrl, HWND_TOPMOST, 0, 0, 0, 0,\
                          SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW
            .endif

;----------[IDC_BUTT04 = Text Color] ----------
         .elseif wparam == IDC_BUTT04
               mov     ColorCode, 1
              call     Color

;----------[IDC_BUTT05 = Face Color] ----------
         .elseif wparam == IDC_BUTT05
               mov     ColorCode, 2
              call     Color

;----------[IDC_BUTT06 = HiLite Color] ----------
         .elseif wparam == IDC_BUTT06
               mov     ColorCode, 3
              call     Color

;----------[IDC_BUTT07 = Font] ----------
         .elseif wparam == IDC_BUTT07
              call     Font

;----------[IDC_BUTT08 = Build Code] ----------
         .elseif wparam == IDC_BUTT08
            .if hButCtrl
               INVOKE     DestroyWindow, hButCtrl
                  and     hButCtrl, 0
            .endif
              call     Extract

;----------[Home grown Buttons Build Code] ----------
         .elseif wparam > 2029 && wparam < 2034
            .if hButCtrl
               INVOKE     DestroyWindow, hButCtrl
                  and     hButCtrl, 0
            .endif
            INVOKE     IsDlgButtonChecked, hButCtrlDlg, IDC_CHK08
            .if !eax
                  jmp     DlgDone
            .endif
               mov     eax, hOutput
               mov     byte ptr[eax], 0
;            INVOKE     GetCurrentDirectory, lengthof szRoot, addr szRoot
;            INVOKE     lstrcat, addr szRoot, addr szSlashB
            INVOKE     lstrcpy, addr szBuff0, addr szRoot
            INVOKE     lstrcat, addr szBuff0, addr szTemplates
            INVOKE     lstrcat, addr szBuff0, addr szButtons
            .if wparam == 2030
               INVOKE     lstrcat, addr szBuff0, addr szButtonF
            .elseif wparam == 2031
               INVOKE     lstrcat, addr szBuff0, addr szButtonR
            .elseif wparam == 2032
               INVOKE     lstrcat, addr szBuff0, addr szButtonB
            .elseif wparam == 2033
               INVOKE     lstrcat, addr szBuff0, addr szButtonMO
            .endif
            INVOKE     ReadInput, addr szBuff0
              test     eax, eax
                js     DlgDone
            INVOKE     lstrcat, hOutput, hBuff
            INVOKE     SendMessage, hREdit, WM_SETTEXT, NULL, 0
            INVOKE     SendMessage, hREdit, WM_SETTEXT, NULL, hOutput

            INVOKE     ShowWindow, hButCtrlDlg, SW_HIDE
               mov     eax, offset szMenu2
               mov     mii.dwTypeData, eax
            INVOKE     SetMenuItemInfo, hMenu, 2, TRUE, addr mii
            INVOKE     DrawMenuBar, hWnd
            INVOKE     ShowWindow, hREdit, SW_SHOW

         .elseif wparam == 702
            INVOKE     SetFocus, hStat01
         .endif

         .if wparam >= IDC_CHK01 && wparam <= IDC_CHK07
              mov     Incr, 0
              mov     Cnt, 7
            .while (Cnt)
                  mov     eax, Incr
               .if TransOn[eax*4]
                  .if Incr > 2
                     INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 17
                  .endif
                  .if Incr < 7
                     .if Incr < 6
                           mov     Index, 15
                     .else
                           mov     Index, 17
                     .endif
                     INVOKE     SendMessage, hListbox, LB_SETSEL, 1, Index
                     INVOKE     SendMessage, hListbox, LB_SETCARETINDEX, Index, 0
                        mov     ecx, LBN_SELCHANGE
                        shl     ecx, 16
                        mov     edx, hListbox
                     INVOKE     SendMessage, hButCtrlDlg, WM_COMMAND, ecx, edx
                  .endif
               .endif
                  inc     Incr
                  dec     Cnt
            .endw
         .endif
      .endif
         jmp     DlgDone

DoError:
;Do error message
         jmp     DlgDone

CloseIt:
      INVOKE     DeleteMenu, hMenu, 2, MF_BYPOSITION
      INVOKE     DrawMenuBar, hWnd
      .if hBRD
         INVOKE     DeleteObject, hBRD
            and     hBRD, 0
      .endif
      INVOKE     DestroyWindow, hButCtrl
         and     hButCtrl, 0
      INVOKE     ShowWindow, hREdit, SW_SHOW ;DEFAULT
      INVOKE     EndDialog, hdlg, wparam
         and     hButCtrlDlg, 0
         mov     eax, TRUE
         jmp     DlgRet

DlgDone:
         mov     eax, FALSE

DlgRet:
         ret
ButCtrlDlg ENDP

;=====================================================
; Get styles PROCEDURE
;=====================================================
GetStyles PROC
LOCAL    Cnt:DWORD, Index
LOCAL    szBuff1[64]:BYTE, szArray[256]:BYTE

      INVOKE     SendMessage, hListbox, LB_GETSELCOUNT, 0, 0
      .if !eax
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 0
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 1
            mov     eax, 2
      .endif
         mov     ecx, eax
      INVOKE     SendMessage, hListbox, LB_GETSELITEMS, ecx, addr szArray
         and     EXStyles, 0
         and     Styles, 0
         and     Index, 0
         mov     Cnt, eax
      .while (Cnt)
            mov     ecx, Index
         INVOKE     SendMessage, hListbox, LB_GETTEXT, dword ptr szArray[ecx*4], addr szBuff1
         .if byte ptr szBuff1 != ' '
               mov     ecx, Index
            .if dword ptr szBuff1+2 == '_XE_' || dword ptr szBuff1+3 == '_XE_'
               INVOKE     SendMessage, hListbox, LB_GETITEMDATA, dword ptr szArray[ecx*4], 0
                   or     EXStyles, eax

            .else
               INVOKE     SendMessage, hListbox, LB_GETITEMDATA, dword ptr szArray[ecx*4], 0
                   or     Styles, eax
            .endif
         .endif
            inc     Index
            dec     Cnt
      .endw

      .if !(Styles & WS_CHILD)
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 0
             or     Styles, WS_CHILD
      .endif
      .if !(Styles & WS_VISIBLE)
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 1
             or     Styles, WS_VISIBLE
      .endif

         ret
GetStyles ENDP

;=====================================================
; Set code PROCEDURE
;=====================================================
SetCode PROC

         and     DrawOn, 0
         and     BmpOn, 0
         and     IcoOn, 0

      .if (Styles & BS_OWNERDRAW)
            mov     DrawOn, 1
      .endif
      .if (Styles & BS_BITMAP)
            mov     BmpOn, 1
      .endif
      .if (Styles & BS_ICON)
            mov     IcoOn, 1
      .endif

         ret
SetCode ENDP

;=====================================================
; Converts a Dec, Hex, Oct or Bin ascii string to a 32 bit num value.
;=====================================================
;INVOKE     AsciiBase, addr szBuff, addr Num, 10
AsciiBase PROC uses ecx edx esi edi Input:DWORD, Base
         mov     esi, Input
         xor     edi, edi
      INVOKE     lstrlen, Input
         xor     ecx, ecx
      .while (eax)
         .if byte ptr[esi+ecx] > 60h
               sub     byte ptr[esi+ecx], 57h
         .elseif byte ptr[esi+ecx] > 40h
               sub     byte ptr[esi+ecx], 37h
         .else
               xor     byte ptr[esi+ecx], 30h
         .endif
            dec     eax
            inc     ecx
      .endw
         mov     ebx, 1
         mov     esi, Input
         add     esi, ecx
         dec     esi
         xor     edx, edx
      .while (ecx)
            mov     al, byte ptr[esi]      ; Extract byte for conversion
            and     eax, 000000ffh
           imul     eax, ebx
            add     edi, eax               ; Accumulate output
           imul     ebx, Base
            dec     esi
            dec     ecx 
      .endw
          mov     eax, edi
          ret
AsciiBase ENDP

;==============================================================
; Change Font PROCEDURE
;==============================================================
Font  PROC
LOCAL    lf:LOGFONT
LOCAL    cf:CHOOSEFONT
LOCAL    charF:CHARFORMAT2
LOCAL    Temp:DWORD

;---------- [Zero out the structures] ----------
      INVOKE     RtlZeroMemory, addr lf, sizeof lf
      INVOKE     RtlZeroMemory, addr cf, sizeof cf

;---------- [Get the current character format] ----------
         mov     charF.cbSize, sizeof charF
      INVOKE     SendMessage, hREdit, EM_GETCHARFORMAT, TRUE, addr charF
      INVOKE     GetDC, hWnd
        push     eax
      INVOKE     GetDeviceCaps, eax, LOGPIXELSY  ; = 96    e.g.
         mov     Temp, eax
         pop     eax
      INVOKE     ReleaseDC, hWnd, eax
       MOVmd     eax, FontS                      ; = 180   e.g.
        imul     eax, 20
         mul     Temp
         mov     ecx, 1440
         div     ecx
         neg     eax

;---------- [Set the LOGFONT attributes] ----------
         mov     lf.lfHeight, eax
       MOVmd     lf.lfWeight, FontW
         mov     lf.lfCharSet, DEFAULT_CHARSET
         mov     lf.lfPitchAndFamily, FF_DONTCARE
      INVOKE     lstrcpy, addr lf.lfFaceName, addr szFontName

;---------- [Set the CHOOSEFONT attributes] ----------
         mov     cf.lStructSize, sizeof cf
       MOVmd     cf.hwndOwner, hWnd
       MOVmd     cf.hInstance, hInst
         lea     eax, lf
         mov     cf.lpLogFont, eax
         mov     cf.iPointSize, 0
         mov     cf.Flags, CF_SCREENFONTS or CF_INITTOLOGFONTSTRUCT or\
                 CF_FORCEFONTEXIST or CF_EFFECTS
       MOVmd     cf.rgbColors, TextC
      INVOKE     ChooseFont, addr cf
         cmp     eax, FALSE                   ; Cancel'ed or error occurred
          je     FontRet
       MOVmd     TextC, cf.rgbColors
         xor     edx, edx
         mov     eax, cf.iPointSize
         mov     ecx, 10
         div     ecx
       MOVmd     FontS, eax
       MOVmd     FontW, lf.lfWeight
      INVOKE     lstrcpy, addr szFontName, addr lf.lfFaceName
      INVOKE     SetDlgItemText, hButCtrlDlg, IDC_REDIT07, addr szFontName
      INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT08, FontS, 0
      INVOKE     SetDlgItemInt, hButCtrlDlg, IDC_REDIT09, FontW, 0

;---------- [Create a Font] ----------
      INVOKE     CreateFontIndirect, addr lf
         mov     hFontBut, eax

FontRet:
         ret
Font    ENDP

;==============================================================
; Color PROCEDURE
;==============================================================
Color    PROC  uses ebx edx esi edi
LOCAL    cc:CHOOSECOLOR
LOCAL    charF:CHARFORMAT2

;---------- [Zero out the structure] ----------
      INVOKE     RtlZeroMemory, addr cc, sizeof cc

;---------- [Set the CHOOSECOLOR attributes] ----------
         mov     cc.lStructSize, sizeof cc
       MOVmd     cc.hwndOwner, hWnd
       MOVmd     cc.hInstance, hInst
      .if ColorCode == 1
         MOVmd     cc.rgbResult, TextC
      .elseif ColorCode == 2
         MOVmd     cc.rgbResult, FaceC
      .elseif ColorCode == 3
         MOVmd     cc.rgbResult, HiLiteC
      .endif
         mov     cc.lpCustColors, offset CustClrs
         mov     cc.Flags, CC_RGBINIT
      INVOKE     ChooseColor, addr cc
         cmp     eax, FALSE                  ; Cancel'ed or error occurred
          je     ColorRet
         mov     eax, cc.rgbResult
      .if ColorCode == 1
           mov     TextC, eax
      .elseif ColorCode == 2
           mov     FaceC, eax
      .elseif ColorCode == 3
           mov     HiLiteC, eax
      .endif
      INVOKE     ButCtrlProc, hBut01, WM_PAINT, 0, 0
      INVOKE     ButCtrlProc, hBut02, WM_PAINT, 0, 0
      INVOKE     ButCtrlProc, hBut03, WM_PAINT, 0, 0

ColorRet:
         ret
Color    ENDP

;======================================================
; 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

;======================================================
; Find Replace Procedure
;======================================================
FindRep PROC lpInput:DWORD, lpReplace
LOCAL    ft:FINDTEXT
LOCAL    cr:CHARRANGE

         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
         mov     eax, lpInput
         mov     ft.lpstrText, eax

FindNext:
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax != -1
            mov     ft.chrg.cpMin, eax
            inc     ft.chrg.cpMin
            mov     cr.cpMin, eax
            mov     cr.cpMax, eax
            add     cr.cpMax, 4
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, lpReplace
            jmp     FindNext
      .endif

         ret
FindRep ENDP

;===================================
; Read file Procedure
;===================================
ReadInput PROC  Input:DWORD
LOCAL    hFile:DWORD, BytesRead

         mov     ecx, Input
      INVOKE     CreateFile, ecx,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 0, OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE, 0
      .if eax == -1
         INVOKE     MessageBox, NULL, addr szError2, Input, MB_OK or MB_ICONWARNING or MB_SYSTEMMODAL
            mov     eax, -1
      .else
            mov     hFile, eax
         INVOKE     ReadFile, hFile, hBuff, 51100, addr BytesRead, NULL
            mov     eax, hBuff
            mov     ecx, BytesRead
            mov     byte ptr [eax+ecx], 0
         INVOKE     CloseHandle, hFile
      .endif
         RET
ReadInput ENDP

;======================================================
; Extract Tab control information PROCEDURE
;======================================================
Extract PROC uses ebx esi edi
LOCAL    xPos:DWORD, yPos, Wth, Hgt, TabNum
LOCAL    Cnt:DWORD, Cnt1, Index
LOCAL    szWork[64]:BYTE, szPosSize[64]:BYTE, szEXStyles[256]:BYTE, szStyles[512]:BYTE
LOCAL    szBuff0[256]:BYTE, szBuff1[64]:BYTE, szBuff2[20]:BYTE, szArray[256]:BYTE
LOCAL    szResStr[256]:BYTE, szLoadStr[512]:BYTE

         mov     eax, hTextOut
         mov     byte ptr[eax], 0
         mov     eax, hTipOut
         mov     byte ptr[eax], 0
         mov     eax, hResOut
         mov     byte ptr[eax], 0
         mov     eax, hBmpOut
         mov     byte ptr[eax], 0
         mov     eax, hCodeOut
         mov     byte ptr[eax], 0
         mov     eax, hOutput
         mov     byte ptr[eax], 0
         mov     byte ptr szEXStyles, 0
         mov     byte ptr szStyles, 0
         mov     byte ptr szWork, 0
         mov     byte ptr szPosSize, 0

      INVOKE     GetDlgItemInt, hButCtrlDlg, IDC_REDIT01, 0, 0
         mov     xPos, eax
      INVOKE     GetDlgItemInt, hButCtrlDlg, IDC_REDIT02, 0, 0
         mov     yPos, eax
      INVOKE     GetDlgItemInt, hButCtrlDlg, IDC_REDIT03, 0, 0
         mov     Wth, eax
      .if !eax
            mov     Wth, 100
      .endif
      INVOKE     GetDlgItemInt, hButCtrlDlg, IDC_REDIT04, 0, 0
         mov     Hgt, eax
      .if !eax
            mov     Hgt, 40
      .endif

        call     GetStyles
        call     SetCode

      INVOKE     wsprintf, addr szBuff2, addr fmat1, xPos
      INVOKE     lstrcat, addr szPosSize, addr szBuff2
      INVOKE     lstrcat, addr szPosSize, addr szComma
      INVOKE     lstrcat, addr szPosSize, addr szSpace
      INVOKE     wsprintf, addr szBuff2, addr fmat1, yPos
      INVOKE     lstrcat, addr szPosSize, addr szBuff2
      INVOKE     lstrcat, addr szPosSize, addr szComma
      INVOKE     lstrcat, addr szPosSize, addr szSpace
      INVOKE     wsprintf, addr szBuff2, addr fmat1, Wth
      INVOKE     lstrcat, addr szPosSize, addr szBuff2
      INVOKE     lstrcat, addr szPosSize, addr szComma
      INVOKE     lstrcat, addr szPosSize, addr szSpace
      INVOKE     wsprintf, addr szBuff2, addr fmat1, Hgt
      INVOKE     lstrcat, addr szPosSize, addr szBuff2

;---------- [Extract the Extended, Window, and Control styles] ----------
      INVOKE     SendMessage, hListbox, LB_GETSELCOUNT, 0, 0
      .if !eax
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 0
         INVOKE     SendMessage, hListbox, LB_SETSEL, 1, 1
            mov     eax, 2
      .endif
         mov     ecx, eax
      INVOKE     SendMessage, hListbox, LB_GETSELITEMS, ecx, addr szArray
         and     Index, 0
         and     Cnt1, 0
         mov     Cnt, eax
      .while (Cnt)
            mov     ecx, Index
         INVOKE     SendMessage, hListbox, LB_GETTEXT, dword ptr szArray[ecx*4], addr szBuff1
         .if byte ptr szBuff1 != ' '
               mov     ecx, Index
            .if dword ptr szBuff1+2 == '_XE_' || dword ptr szBuff1+3 == '_XE_'
               .if byte ptr szEXStyles != 0
                  INVOKE     lstrcat, addr szEXStyles, addr szOR
               .endif
               INVOKE     lstrcat, addr szEXStyles, addr szBuff1

            .else
               .if Cnt1 != 0
                  INVOKE     lstrcat, addr szStyles, addr szOR
                  .if Cnt1 == 4 || Cnt1 == 8 || Cnt1 == 12
                     INVOKE     lstrcat, addr szStyles, addr szSlashB
                     INVOKE     lstrcat, addr szStyles, addr szCRLF
                     INVOKE     lstrcat, addr szStyles, addr szClear
                  .endif
               .endif
               INVOKE     lstrcat, addr szStyles, addr szBuff1
                  inc     Cnt1
            .endif
         .endif
            inc     Index
            dec     Cnt
      .endw

      .if byte ptr szEXStyles == 0
         INVOKE     lstrcpy, addr szEXStyles, addr szZero
      .endif
      INVOKE     lstrcat, addr szStyles, addr szComma
      INVOKE     lstrcat, addr szStyles, addr szSlashB

;---------- [Extract the Bitmap resources] ----------
      INVOKE     GetDlgItemText, hButCtrlDlg, IDC_REDIT06, addr szBuff0, sizeof szBuff0
         mov     ecx, eax
         lea     esi, szBuff0
         lea     edi, szResStr
      .while (ecx)
            mov     al, byte ptr[esi]
            mov     byte ptr[edi], al
         .if al == '\'
               inc     edi
               mov     byte ptr[edi], '\'
         .endif
            inc     esi
            inc     edi
            dec     ecx
      .endw
         mov     byte ptr[edi], 0
      INVOKE     lstrcat, addr szResStr, addr szQuote
      INVOKE     lstrcat, addr szResStr, addr szCRLF

;---------- [Build the output] ----------
      INVOKE     LockWindowUpdate, hREdit
      INVOKE     lstrcpy, addr szBuff0, addr szRoot
      INVOKE     lstrcat, addr szBuff0, addr szTemplates
      INVOKE     lstrcat, addr szBuff0, addr szButtons
      .if DrawOn
               INVOKE     lstrcat, addr szBuff0, addr szButtonO
      .else
               INVOKE     lstrcat, addr szBuff0, addr szButtonS
      .endif
      INVOKE     ReadInput, addr szBuff0
        test     eax, eax
          js     ExtractDone

      .if BmpOn || IcoOn
         INVOKE     lstrcat, hOutput, addr szResr1
         .if BmpOn
            INVOKE     lstrcat, hOutput, addr szResrB
         .else
            INVOKE     lstrcat, hOutput, addr szResrI
         .endif
           INVOKE     lstrcat, hOutput, addr szResStr
      .endif

      INVOKE     lstrcat, hOutput, hBuff
      INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, 0
      INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, hOutput

      INVOKE     FindRep, addr szFFFF, addr szFontName
      INVOKE     FindRep, addr szBBTT, addr szButText
      INVOKE     wsprintf, addr szWork, addr fmat1, FontS
      INVOKE     FindRep, addr szFFSS, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat1, FontW
      INVOKE     FindRep, addr szFFWW, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat4, TextC
      INVOKE     FindRep, addr szTTCC, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat4, FaceC
      INVOKE     FindRep, addr szFFCC, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat4, HiLiteC
      INVOKE     FindRep, addr szHHCC, addr szWork
      INVOKE     FindRep, addr szXXSS, addr szEXStyles
      INVOKE     FindRep, addr szSSSS, addr szStyles
      INVOKE     FindRep, addr szPPSS, addr szPosSize

      .if BmpOn
         INVOKE     lstrcpy, addr szLoadStr, addr szLLBmp
         .if !DrawOn
            INVOKE     lstrcat, addr szLoadStr, addr szSSBmp
         .endif
         INVOKE     FindRep, addr szLLII, addr szLoadStr
         INVOKE     FindRep, addr szDDII, addr szDDImg
      .elseif IcoOn
         INVOKE     lstrcpy, addr szLoadStr, addr szLLIco
         .if !DrawOn
            INVOKE     lstrcat, addr szLoadStr, addr szSSBmp
         .endif
         INVOKE     FindRep, addr szLLII, addr szLoadStr
         INVOKE     FindRep, addr szDDII, addr szDDImg
      .else
         INVOKE     FindRep, addr szLLII, addr szSpace
         INVOKE     FindRep, addr szDDII, addr szSpace
      .endif
      INVOKE     wsprintf, addr szWork, addr fmat1, BmpOn
      INVOKE     FindRep, addr szBOFF, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat1, TransOn
      INVOKE     FindRep, addr szTOFF, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat1, RaisedOn
      INVOKE     FindRep, addr szROFF, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat1, DepressOn
      INVOKE     FindRep, addr szDOFF, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat1, ImageTextOn
      INVOKE     FindRep, addr szITFF, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat1, ImageOnlyOn
      INVOKE     FindRep, addr szIOFF, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat1, SizeIToBOn
      INVOKE     FindRep, addr szSSTB, addr szWork
      INVOKE     wsprintf, addr szWork, addr fmat1, SizeBToIOn
      INVOKE     FindRep, addr szSSTI, addr szWork

      .if DrawOn && BmpOn
         INVOKE     FindRep, addr szGGII, addr szGGObj
      .endif
      INVOKE     ShowWindow, hButCtrlDlg, SW_HIDE
         mov     eax, offset szMenu2
         mov     mii.dwTypeData, eax
      INVOKE     SetMenuItemInfo, hMenu, 2, TRUE, addr mii
      INVOKE     DrawMenuBar, hWnd
      INVOKE     ShowWindow, hREdit, SW_SHOW
      INVOKE     SendMessage, hREdit, EM_SETSEL, 0, 0
      INVOKE     LockWindowUpdate, 0

ExtractDone:
         ret
Extract ENDP

end start
