      title   Assembler Editor

         comment '======================================================|'
         comment '* AsmEdit v5.0 uses RICHED44.DLL  V1                  *'
         comment '* Copyright (r) Ewayne L. Wagner, All Rights Reserved.*'
         comment '* Unless you can improve on the program and send me   *'
         comment '* the changes. yooper@kalamazoo.net                   *'
         comment '======================================================|'

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

            include  AsmEdit.inc
            include  Build.asm
            include  MenuMaint.asm
            include  MRUFiles.asm
            include  TreeList.asm
            include  Print.asm
            include  CodeHelper.asm

.code

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

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

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

;      INVOKE     LoadLibrary, addr CodeHelper   ; Load the CodeHelper.dll
;         mov     hCodeHelper, 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
      INVOKE     FreeLibrary, hREdDllMS
;      INVOKE     FreeLibrary, hCodeHelper

      .if hLibR
         INVOKE     FreeLibrary, hLibR
      .endif
      .if hLibCB
         INVOKE     FreeLibrary, hLibCB
      .endif
      .if hStepByStep
         INVOKE     FreeLibrary, hStepByStep
      .endif

NoGo:
      INVOKE     ExitProcess, MainExit

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

         mov     wc.cbSize, sizeof WNDCLASSEX
         mov     wc.style, CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW
         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, 0
         mov     wc.lpszClassName, offset ClassName
      INVOKE     LoadIcon, hInst, 700
         mov     hIcon, eax
         mov     wc.hIcon, eax
         mov     wc.hIconSm, eax
      INVOKE     LoadCursor, NULL, IDC_ARROW
         mov     wc.hCursor, eax
      INVOKE     RegisterClassEx, addr wc

         mov     wc.lpfnWndProc, offset WorkAreaProc
         mov     wc.lpszClassName, offset WorkClass
         mov     wc.lpszMenuName, NULL
      INVOKE     RegisterClassEx, addr wc

         mov     wc.hbrBackground, COLOR_WINDOWTEXT+1
         mov     wc.lpfnWndProc, offset BuildProc
         mov     wc.lpszClassName, offset BuildClass
         mov     wc.lpszMenuName, NULL
      INVOKE     RegisterClassEx, addr wc

      INVOKE     CreateSolidBrush, Color.TreeListBC
         mov     hSavBRM, eax
         mov     wc.hbrBackground, eax
         mov     wc.lpfnWndProc, offset KeyWordProc
         mov     wc.lpszClassName, offset KeyWordClass
         mov     wc.lpszMenuName, NULL
      INVOKE     RegisterClassEx, addr wc

      INVOKE     LoadMenu, hInst, offset MenuName
         mov     hMenu, eax

         mov     lpcbData, 16
      INVOKE     RegQuerySZ, addr szWndPos, addr WndPos
      .if WndPos+8 > 100 && WndPos+12 > 100
            jmp     UseSavePos
      .endif

;---------- [Center the window] ----------
      INVOKE     GetSystemMetrics, SM_CXSCREEN
         sub     eax, 725
         shr     eax, 1
         mov     WndPos, eax
      INVOKE     GetSystemMetrics, SM_CYSCREEN
         sub     eax, 537
         shr     eax, 1
         mov     WndPos+4, eax
         mov     WndPos+8, 725
         mov     WndPos+12, 537

UseSavePos:
;---------- [Create the Main Window] ----------
      INVOKE     CreateWindowEx, WS_EX_CLIENTEDGE, addr ClassName, addr AppName,\
                 WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or WS_CLIPSIBLINGS,\
                 WndPos, WndPos+4, WndPos+8, WndPos+12, NULL, hMenu, hInst, NULL
         mov     hWnd, eax

;---------- [Show the window check Setup and go into message dispatch loop
      INVOKE     RegQuery, addr szMaxWin, MaxWin
      .if MaxWin
         INVOKE     ShowWindow, hWnd, SW_SHOWMAXIMIZED
      .else
         INVOKE     ShowWindow, hWnd, SW_SHOWNORMAL
      .endif
      INVOKE     UpdateWindow, hWnd

      .if IndentOn
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 4, addr szIND
      .endif
      .if AutoRefOn
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 6, addr szREF
      .endif

      .if NoSetup
         INVOKE     MessageBox, NULL, addr szError4, addr AppName, 
                    MB_YESNO or MB_ICONEXCLAMATION or MB_SYSTEMMODAL
         .if eax == IDYES
            INVOKE     lstrcpy, addr WorkBuff, addr AsmRootDir
            INVOKE     lstrcat, addr WorkBuff, addr szSetup
            INVOKE     ShellExecute, hWnd, addr szOpen, addr WorkBuff, NULL, NULL, SW_SHOWNORMAL
         .endif
      .endif

      INVOKE     LoadMenuItems, addr szRedit, 1

      .if !hAccel   ; Gets created and loaded in the MenuMaint program
         INVOKE     LoadAccelerators, hInst, IDR_ACCEL
            mov     hAccel, eax
      .endif
        call     SetTitle
        call     CheckState

;---------- [Message loop] ----------
      .while TRUE
         INVOKE     GetMessage, addr msg, 0, 0, 0
            .break .if (!eax)
         INVOKE     IsDialogMessage, hWndDlg, addr msg
         .if eax != 0
               jmp     Pass
         .endif
         INVOKE     IsDialogMessage, hWndDlgG, addr msg
         .if eax != 0
               jmp     Pass
         .endif
         INVOKE     IsDialogMessage, hFRDlg, addr msg
         .if eax != 0
            .if msg.wParam == 6
               INVOKE     PostMessage, hWnd, WM_COMMAND, IDM_FINDTEXT, 0
            .endif
               jmp     Pass
         .endif
         INVOKE     TranslateAccelerator, hWnd, hAccel, addr msg
         .if eax == 0
            INVOKE     TranslateMessage, addr msg
            INVOKE     DispatchMessage, addr msg
         .endif

Pass:
      .endw

         mov     eax, msg.wParam
         ret

WinMain ENDP

;BeginLoop:
;      INVOKE     GetMessage, addr msg, 0, 0, 0
;         cmp     ax, 0
;          je     EndLoop
;      INVOKE     TranslateAccelerator, hWnd, hAccel, addr msg
;         cmp     eax, 0
;         jne     BeginLoop
;      INVOKE     IsDialogMessage, hWndDlg, addr msg
;         cmp     eax, 0
;         jne     BeginLoop
;      INVOKE     IsDialogMessage, hWndDlgG, addr msg
;         cmp     eax, 0
;         jne     BeginLoop
;      INVOKE     IsDialogMessage, hFRDlg, addr msg
;         cmp     eax, 0
;         jne     BeginLoop
;      INVOKE     TranslateMessage, addr msg
;      INVOKE     DispatchMessage, addr msg
;         jmp     BeginLoop

;EndLoop:
;         ret

;WinMain ENDP

;===================================================
; WinProc procedure
;===================================================
WndProc PROC uses ebx esi edi hwnd:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    rectI:RECT
LOCAL    pt:POINT
LOCAL    cm:COLORMAP
LOCAL    tm:TEXTMETRIC
LOCAL    charF:CHARFORMAT2
LOCAL    sysi:SYSTEM_INFO
LOCAL    tbb:TBBUTTON
LOCAL    tbab:TBADDBITMAP
LOCAL    lvf:LV_FINDINFO
LOCAL    lvi:LV_ITEM
LOCAL    tvi:TV_ITEM

LOCAL    ShFileOp:SHFILEOPSTRUCT

LOCAL    bSize:DWORD, hTbBmp, ID, Cnt, Len, Chg, TabBack, TabText, DWStyles
LOCAL    TreeW:DWORD, TreeH, TempWord1, TempWord2, hKey, hBRT, hTemp
LOCAL    szWork[64]:BYTE, szBuff[256]:BYTE, CurDir[256]:BYTE

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

            mov     osv.dwOSVersionInfoSize, sizeof OSVERSIONINFO
         INVOKE     GetVersionEx, addr osv
          MOVmd     osvID, osv.dwPlatformId ;dwBuildNumber    ; Get OS type Win9x or NT
;dwMajorVersion, dwMinorVersion
;                Major Minor
;Windows 95      4     0
;Windows 98      4     10
;Windows Me      4     90
;Windows NT 3.51 3     51
;Windows NT 4.0  4     0
;Windows 2000    5     0
;Windows XP      5     1

         INVOKE     GetSystemDefaultLangID
            mov     LangID, eax
         .if eax == 404h || eax == 804h || eax == 0c04h || eax == 1004h ||\
             eax == 1404h || eax == 0412h
               mov     ChineseOn, eax
         .endif

         INVOKE     GetOEMCP           ; Current (OEM) code-page identifier
            mov     cpOEM, eax
         INVOKE     GetACP             ; Current ANSI code-page identifie
            mov     cpANSI, eax

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

;---------- [Create the Toolbar Window] ----------
         INVOKE     CreateWindowEx, 0, addr ToolClass, 0,
                    WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS or CCS_NOPARENTALIGN or\
                    CCS_NORESIZE or CCS_ADJUSTABLE or TBSTYLE_FLAT or\
                    WS_CLIPSIBLINGS,\
                    0, -1, 569, 24, hwnd, 0, hInst, 0
         .if !eax
;Do message
               jmp     Ret0
         .endif
            mov     hWndTool, eax

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

;---------- [Load The Bitmaps] ----------
            mov     cm.From, 00c0c0c0h
         INVOKE     GetSysColor, COLOR_BTNFACE
            mov     cm.To, eax
         INVOKE     CreateMappedBitmap, hInst, 701, 0, addr cm, 1
            mov     hTBBmp, eax

         INVOKE     SendMessage, hWndTool, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0

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

            mov     tbab.hInst, 0
          MOVmd     tbab.nID, hTBBmp
         INVOKE     SendMessage, hWndTool, TB_ADDBITMAP, 1, addr tbab

;---------- [Create the Toolbar structures] ----------
         TBButt     hWndTool, 0, IDM_NEW, 0
         TBButt     hWndTool, 1, IDM_OPEN, 0
         TBButt     hWndTool, 2, IDM_SAVE, 0
         TBButt     hWndTool, 3, IDM_SAVEALL, 0
          TBSep     hWndTool
         TBButt     hWndTool, 4, IDM_CUT, 0
         TBButt     hWndTool, 5, IDM_COPY, 0
         TBButt     hWndTool, 6, IDM_PASTE, 0
         TBButt     hWndTool, 7, IDM_DELETE, 0
         TBButt     hWndTool, 8, IDM_UNDO, 0
         TBButt     hWndTool, 9, IDM_REDO, 0
          TBSep     hWndTool
         TBButt     hWndTool, 10,IDM_FINDTEXT, 0
         TBButt     hWndTool, 11,IDM_FINDNEXT, 0
         TBButt     hWndTool, 12,IDM_FINDPREV, 0
         TBButt     hWndTool, 13,IDM_REPLACETEXT, 0
          TBSep     hWndTool
         TBButt     hWndTool, 14,IDM_CODEH, 0
         TBButt     hWndTool, 15,IDM_QUICKC, 0
         TBButt     hWndTool, 16,IDM_USERC, 0
          TBSep     hWndTool
         TBButt     hWndTool, 17,IDM_WORK, 0
         TBButt     hWndTool, 18,IDM_MULT, 0
         TBButt     hWndTool, 19,IDM_RUN, 0
         TBButt     hWndTool, 20,IDM_DOS, 0
          TBSep     hWndTool
         TBButt     hWndTool, 21,IDM_SYNTAX, 0
         TBButt     hWndTool, 22,IDM_EXIT, 0

         INVOKE     CreateWindowEx, 0, addr ToolClass, 0,\
                    WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS or CCS_NOPARENTALIGN or\
                    CCS_NORESIZE or CCS_ADJUSTABLE or TBSTYLE_LIST or TBSTYLE_FLAT or\
                    WS_CLIPSIBLINGS,\
                    570, -1, 82, 24, hwnd, 0, hInst, 0
            mov     hWndToolA, eax
;INVOKE     SetWindowTheme, hWndToolA, 0, 0

         INVOKE     SendMessage, hWndToolA, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
            mov     eax, 00100000h
         INVOKE     SendMessage, hWndToolA, TB_SETBUTTONSIZE, 0, eax
            mov     eax, 00100000h
         INVOKE     SendMessage, hWndToolA, TB_SETBITMAPSIZE, 0, eax
         INVOKE     SendMessage, hWndToolA, TB_ADDSTRING, 0, addr szButtTxt1
         TBButt     hWndToolA, 0, IDM_GOTO, eax
         INVOKE     SendMessage, hWndToolA, TB_ADDSTRING, 0, addr szButtTxt2
         TBButt     hWndToolA, 0, IDM_BUILD, eax

         INVOKE     CreateWindowEx, 0, addr ToolClass, 0,\
                    WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS or CCS_NOPARENTALIGN or\
                    CCS_NORESIZE or CCS_ADJUSTABLE or TBSTYLE_LIST or TBSTYLE_FLAT or\
                    WS_CLIPSIBLINGS,\
                    653, -1, 1200, 24, hwnd, 0, hInst, 0
            mov     hWndToolB, eax

         INVOKE     SendMessage, hWndToolB, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
            mov     eax, 00100000h
         INVOKE     SendMessage, hWndToolB, TB_SETBUTTONSIZE, 0, eax
            mov     eax, 00100000h
         INVOKE     SendMessage, hWndToolB, TB_SETBITMAPSIZE, 0, eax
         INVOKE     SendMessage, hWndToolB, TB_ADDSTRING, 0, addr szButtTxt3
         TBButt     hWndToolB, 0, IDM_PROJECTS, eax

         INVOKE     CreateWindowEx, WS_EX_STATICEDGE, addr ToolClass, 0,
                    WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS or CCS_NOPARENTALIGN or\
                    CCS_NODIVIDER or CCS_NORESIZE or CCS_ADJUSTABLE or TBSTYLE_FLAT or\
                    TBSTYLE_LIST or WS_BORDER or WS_CLIPSIBLINGS,\
                    0, 391, 132, 20, hwnd, 0, hInst, 0
           test     eax, eax     
             jz     Ret0
            mov     hWndTool2, eax

         INVOKE     SendMessage, hWndTool2, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0

            mov     ecx, 00090000h
         INVOKE     SendMessage, hWndTool2, TB_SETBITMAPSIZE, 0, ecx

         INVOKE     SendMessage, hWndTool2, TB_ADDSTRING, 0, addr szButtTxt4
         TBButt     hWndTool2, 0, 1091, eax
          TBSep     hWndTool2
         INVOKE     SendMessage, hWndTool2, TB_ADDSTRING, 0, addr szButtTxt5
         TBButt     hWndTool2, 0, 1092, eax

;---------- [Q U I C K   C O D E   T O O L B A R] ----------
         INVOKE     CreateWindowEx, 0, addr ToolClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or CCS_NORESIZE or \
                    CCS_VERT or CCS_LEFT or TBSTYLE_BUTTON or TBSTYLE_TOOLTIPS or \
                    TBSTYLE_WRAPABLE or TBSTYLE_FLAT,\
                    115, 23, 250, 26, hwnd, 48, hInst, 0
            mov     hWndToolQ, eax

            mov     cm.From, 00c0c0c0h
         INVOKE     GetSysColor, COLOR_BTNFACE
            mov     cm.To, eax
         INVOKE     CreateMappedBitmap, hInst, 702, 0, addr cm, 1
            mov     hTBBmpQ, eax
   
         INVOKE     SendMessage, hWndToolQ, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0

;---------- [Size the Bitmap and Button] ----------
            mov     ecx, 20  ; loword = bitmap Width
            mov     eax, 20  ; hiword = bitmap Height
            shl     eax, 16
            mov     ax, cx
            mov     ecx, eax
           push     ecx
         INVOKE     SendMessage, hWndToolQ, TB_SETBITMAPSIZE, 0, ecx
            pop     ecx
         INVOKE     SendMessage, hWndToolQ, TB_SETBUTTONSIZE, 0, ecx

            mov     tbab.hInst, 0
          MOVmd     tbab.nID, hTBBmpQ
         INVOKE     SendMessage, hWndToolQ, TB_ADDBITMAP, 1, addr tbab

;---------- [Create the Quick Code Toolbar structures] ----------
            mov     Cnt, 0
            mov     ID, 7501
         .while (Cnt < 13)
               mov     ecx, Cnt
               mov     edx, ID
            TBButt     hWndToolQ, ecx, edx, 0
               inc     Cnt
               inc     ID
         .endw
            mov     pt.x, 17
            mov     pt.y, 1
         INVOKE     SendMessage, hWndToolQ, TB_SETROWS, addr pt, addr rect

;---------- [U S E R   C O D E   T O O L B A R] ----------
         INVOKE     CreateWindowEx, 0, addr ToolClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or CCS_NORESIZE or \
                    CCS_VERT or CCS_LEFT or TBSTYLE_BUTTON or TBSTYLE_TOOLTIPS or \
                    TBSTYLE_WRAPABLE or TBSTYLE_FLAT,\
                    141, 23, 250, 26, hwnd, 0, hInst, 0
            mov     hWndToolU, eax
         INVOKE     LoadBitmap, hInst, 703
            mov     hTBBmpU, eax
         INVOKE     ChgBmpColor, hTBBmpU
            mov     hTBBmpU ,eax
         INVOKE     SendMessage, hWndToolU, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0

;---------- [Size the Bitmap and Button] ----------
            mov     ecx, 16  ; loword = bitmap Width
            mov     eax, 16  ; hiword = bitmap Height
            shl     eax, 16
            mov     ax, cx
            mov     ecx, eax
           push     ecx
         INVOKE     SendMessage, hWndToolU, TB_SETBITMAPSIZE, 0, ecx
            pop     ecx
         INVOKE     SendMessage, hWndToolU, TB_SETBUTTONSIZE, 0, ecx

            mov     tbab.hInst, 0
          MOVmd     tbab.nID, hTBBmpU
         INVOKE     SendMessage, hWndToolU, TB_ADDBITMAP, 1, addr tbab

;---------- [Create the User Code Toolbar structures] ----------
            mov     Cnt, 0
            mov     ID, 8501
         .while (Cnt < 40)
               mov     ecx, Cnt
               mov     edx, ID
            TBButt     hWndToolU, ecx, edx, 0
               inc     Cnt
               inc     ID
         .endw
            mov     pt.x, 40
            mov     pt.y, 1
         INVOKE     SendMessage, hWndToolU, TB_SETROWS, addr pt, addr rect

;---------- [Create the property and function controls
         INVOKE     CreateWindowEx, WS_EX_CLIENTEDGE, addr ComboClass, 0,\
                    WS_CHILD or WS_VSCROLL or CBS_HASSTRINGS or CBS_DROPDOWN or\
                    CBS_OWNERDRAWFIXED,\
                    522, 24, 194, 210, hwnd, 86, hInst, 0

            mov     hWndProp, eax
         INVOKE     SendMessage, hWndProp, CB_SETITEMHEIGHT, -1, 15       ; Selection field
         INVOKE     SendMessage, hWndProp, CB_SETITEMHEIGHT, 0, 15        ; List items

            lea     esi, offset szComboProps
            xor     eax, eax

Getlen:
         .if byte ptr[esi+eax] == 2ch
               mov     Len, eax
               inc     Len 
            INVOKE     lstrcpyn, addr szWork, esi, Len
            INVOKE     SendMessage, hWndProp, CB_ADDSTRING, 0, addr szWork
               add     esi, Len
               xor     eax, eax
               jmp     Getlen
         .elseif byte ptr[esi+eax] == 0h
            INVOKE     SendMessage, hWndProp, CB_SETCURSEL, 4, 0
               jmp     LoadedOK
         .endif
            inc     eax
            jmp     Getlen

LoadedOK:
         INVOKE     CreateWindowEx, WS_EX_STATICEDGE, addr ListboxClass, 0,\
                    WS_CHILD or WS_BORDER or WS_HSCROLL or WS_VSCROLL or LBS_HASSTRINGS or\
                    LBS_NOINTEGRALHEIGHT or LBS_NOTIFY or LBS_OWNERDRAWFIXED or LBS_SORT,\
                    522, 24, 194, 429, hwnd, 89, hInst, 0
            mov     hWndFunct, eax
         INVOKE     SendMessage, hWndFunct, LB_SETHORIZONTALEXTENT, 150, 0
         INVOKE     SendMessage, hWndFunct, LB_SETITEMHEIGHT, 0, 15           ; List items

         INVOKE     LoadImage, hInst, 704, IMAGE_BITMAP, 9, 9, LR_DEFAULTCOLOR   
            mov     hBmpS, eax

            mov     AutoSave, 1
            mov     IndentOn, 1
            mov     CloseBuild, 1
            mov     FilterOn, 1
            mov     ItalicOn, 1
            mov     LeadingOn, 1
            mov     ProjOn, 1
            mov     DriveOn, 0
            mov     SmoothOn, 1
            mov     SyntaxOn, 1
            mov     UserOn, 1
            mov     PropCode, 4
            mov     AutoRefOn, 1
            mov     WheelNum, 10
            mov     ProjGroup, 0
            mov     FilterGroup, 0
            mov     CodeHelperOn, 0
            mov     BeepOn, 0
            mov     SpaceAfter, 1
            mov     RightAlign, 1
            mov     MinMatch, 3
            mov     Indent, 6
            mov     Outdent, 5
           call     Initialize
            and     ProjDrive, 0
         .if DriveOn
               mov     ProjDrive, 1
         .endif

;---------- [Create the fonts] ----------
         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontMS

            mov     lf.lfHeight, 14
            mov     lf.lfWeight, 600
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontButt, eax

            mov     lf.lfHeight, -12
            mov     lf.lfWeight, 500
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontC, eax   ; Combo font

            mov     lf.lfWeight, 600
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontTB, eax  ; Toolbar font

            mov     lf.lfHeight, -8
            mov     lf.lfWeight, 400
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontT, eax   ; Tab font

         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontTah
            mov     lf.lfHeight, -13 ;-11
            mov     lf.lfWeight, 500 ;600
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontBLD, eax ; Build font

           push     FontEdit.lfWeight
            mov     FontEdit.lfWeight, 600
         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFontB, eax
            mov     Font.hFontB, eax

          movzx     eax, byte ptr FontEdit.lfItalic
           push     eax
            mov     FontEdit.lfItalic, TRUE
         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFontBI, eax
            mov     Font.hFontBI, eax
            pop     eax
            mov     FontEdit.lfItalic, al
            pop     FontEdit.lfWeight

          movzx     eax, byte ptr FontEdit.lfItalic
           push     eax
            mov     FontEdit.lfItalic, TRUE
         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFontI, eax
            mov     Font.hFontI, eax
            pop     eax
            mov     FontEdit.lfItalic, al

          movzx     eax, byte ptr FontEdit.lfCharSet
           push     eax
            mov     al, BALTIC_CHARSET
            mov     FontEdit.lfCharSet, al
         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFontUni, eax
            mov     Font.hFontUni, eax
            pop     eax
            mov     FontEdit.lfCharSet, al

         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFont, eax     ; Edit font
            mov     Font.hFont, eax

         INVOKE     CreateFontIndirect, offset FontLine
            mov     hFontL, eax    ; Line num font
            mov     Font.hFontL, eax

         INVOKE     CreateFontIndirect, addr FontTree
            mov     hFontTL, eax   ; Tree List font


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

         INVOKE     SendMessage, hWndToolA, WM_SETFONT, hFontTB, TRUE
         INVOKE     SendMessage, hWndToolB, WM_SETFONT, hFontTB, TRUE
         INVOKE     SendMessage, hWndTool2, WM_SETFONT, hFontT, TRUE
         INVOKE     SendMessage, hWndProp, WM_SETFONT, hFontC, TRUE
         INVOKE     SendMessage, hWndFunct, WM_SETFONT, hFontC, TRUE

         pushad
         INVOKE     CreateTab, hwnd
          popad

         INVOKE     CreateWindowEx, NULL, addr StaticClass, NULL,\
                    WS_CHILD or WS_VISIBLE or SS_BITMAP or SS_NOTIFY,\
                    0, 0, 0, 0, hREdit, 43001, hInst, NULL
            mov     hSel, eax
         INVOKE     SendMessage, hSel, STM_SETIMAGE, IMAGE_BITMAP, hBmpS
         INVOKE     MoveWindow, hSel, 0, 0, 0, 0, TRUE

         INVOKE     SendMessage, hWndTab, WM_SETFONT, hFontT, TRUE
            mov     ecx, 16
            shl     ecx, 16
            mov     eax, 40
            mov     cx, ax
         INVOKE     SendMessage, hWndTab, TCM_SETITEMSIZE, 0, ecx
            mov     ecx, 0
            shl     ecx, 16
            mov     eax, 5
            mov     cx, ax
         INVOKE     SendMessage, hWndTab, TCM_SETPADDING, 0, ecx

;---------- [Create the WorkArea Window] ----------
         INVOKE     CreateWindowEx, WS_EX_TOOLWINDOW, addr WorkClass, addr szWorkArea,\
                    WS_POPUP or WS_CAPTION or WS_THICKFRAME,\
                    479, 456, 372, 132, hwnd, NULL, hInst, NULL
            mov     hWorkArea, eax

;---------- [Create the WorkArea 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 WS_CLIPSIBLINGS,\
                    0, 0, 364, 108, hWorkArea, 4488, hInst, NULL
            mov     hWEdit, eax

            mov     eax, hwnd
            mov     hWnd, eax
           call     GetXY

;---------- [Create the Build Window] ----------
         INVOKE     CreateWindowEx, WS_EX_TOOLWINDOW, addr BuildClass, addr szBuild,\
                    WS_POPUP or WS_CAPTION or WS_SYSMENU or WS_THICKFRAME,\
                    xBuild, yBuild, 332, 282, hwnd, NULL, hInst, NULL
            mov     hBuild, eax

;---------- [Create the Build 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 WS_CLIPSIBLINGS,\
                    0, 0, 324, 258, hBuild, 4489, hInst, NULL
            mov     hBEdit, eax

         INVOKE     SendMessage, hWEdit, WM_SETFONT, hFont, TRUE
         INVOKE     SendMessage, hWEdit, UM_SUBCLASSCTRL, 0, WorkEditProc
            mov     lpWorkEdit, eax

         INVOKE     SendMessage, hBEdit, WM_SETFONT, hFontBLD, TRUE
         INVOKE     SendMessage, hBEdit, UM_SUBCLASSCTRL, 0, BuildEditProc
            mov     lpBuildEdit, eax

           push     Color.EditTC
           push     Color.EditBC
           push     Color.SelectTC
           push     Color.SelectBC
           push     Color.SelbarBC
            mov     Color.EditTC, 00ffff00h
            mov     Color.EditBC, 0
            mov     Color.SelectTC, 00ffffffh
            mov     Color.SelectBC, 000000ffh
            mov     Color.SelbarBC, 00a0a0a0h
         INVOKE     SendMessage, hBEdit, UM_SETCOLORS, 0, addr Color
         INVOKE     SendMessage, hBEdit, UM_HILIGHT, STATE_NOHILITE, 0
            pop     Color.SelbarBC
            pop     Color.SelectBC
            pop     Color.SelectTC
            pop     Color.EditBC
            pop     Color.EditTC

         INVOKE     SendMessage, hREdit, UM_HTMLCOLOR, 0, addr Color01+64
         INVOKE     SendMessage, hWEdit, EM_EXLIMITTEXT, 0, 100000
         INVOKE     SendMessage, hBEdit, EM_EXLIMITTEXT, 0, 10000
         INVOKE     SendMessage, hREdit, UM_SETFONTS, 0, addr Font
         INVOKE     SendMessage, hREdit, UM_SETCOLORS, 0, addr Color
         INVOKE     SendMessage, hREdit, UM_TABWIDTH, TAB, 0
         INVOKE     SendMessage, hREdit, UM_ITALIC, ItalicOn, 0
         .if NoHiLiteBW
            INVOKE     SendMessage, hREdit, UM_BLACKWHITE, STATE_BLACKWHITE, 0
         .endif
            mov     eax, Speed
           imul     eax, 1000000
         INVOKE     SendMessage, hREdit, UM_SETSCROLLSPEED, 0, eax
         INVOKE     SendMessage, hREdit, UM_SMOOTHSCROLL, 0, SmoothOn
         INVOKE     SendMessage, hREdit, UM_MOUSEWHEEL, WheelNum, 0

;---------- [Set handles] ----------
            mov     eax, hwnd
            mov     Hand.hWnd, eax
            mov     eax, hWndStat
            mov     Hand.hWndStat, eax
            mov     eax, hREdit
            mov     Hand.hREdit, eax
            mov     eax, hSel
            mov     Hand.hSel, eax
            mov     eax, hWorkArea
            mov     Hand.hWorkArea, eax
            mov     eax, hWEdit
            mov     Hand.hWEdit, eax
         INVOKE     SendMessage, hREdit, UM_SETHANDLES, 0, addr Hand

         INVOKE     SetFocus, hREdit

         INVOKE     GetMenu, hwnd              ; Get the handle to the main menu
         INVOKE     GetSubMenu, eax, 0         ; Get handle to 1st sub menu
         INVOKE     GetMenuItemCount, eax      ; Get count of items in the sub menu
            mov     MenuCnt, eax               ; Menu count for ProcessMRUFiles
         INVOKE     GetMenu, hwnd              ; Get handle to main menu
         INVOKE     GetSubMenu, eax, 8         ; Get handle to 8th sub menu, 8 == &Window it May change
            mov     hWndMenu, eax
         INVOKE     CreatePopupMenu
            mov     hSubMenuW, eax
         INVOKE     InsertMenu, hWndMenu, -1, MF_BYPOSITION or\
                    MF_STRING or MF_POPUP, hSubMenuW, addr szOpenFiles

         INVOKE     ProcessMRUFiles, hwnd, 1, MenuCnt, 0, addr szRedit, 0

            and     ID, 0
            mov     Cnt, 16
         .while (Cnt)
               mov     eax, ID
               mov     ecx, Color01[eax*4]
               mov     edx, KeyArray[eax*4]
            INVOKE     SendMessage, hREdit, UM_SETSYNTAXWORDS, ecx, edx
               inc     ID
               dec     Cnt
         .endw

         INVOKE     HeapAlloc, hDefHeap, HEAP_ZERO_MEMORY, 300
            mov     hBuff, eax
         INVOKE     HeapAlloc, hDefHeap, HEAP_ZERO_MEMORY, 1500
            mov     hProjArray, eax
         INVOKE     HeapAlloc, hDefHeap, HEAP_ZERO_MEMORY, 900
            mov     hAccelArray, eax
         INVOKE     HeapAlloc, hDefHeap, HEAP_ZERO_MEMORY, 51200
            mov     hOutPut, eax
         INVOKE     HeapAlloc, hDefHeap, HEAP_ZERO_MEMORY, 300
            mov     hHead, eax

           push     ProjDrive
            and     ProjDrive, 0
           call     InitTreeList
            mov     ProjDrive, 1
           call     InitTreeList
            pop     ProjDrive

         INVOKE     SendMessage, hWndTree, WM_SETFONT, hFontTL, TRUE
         INVOKE     SendMessage, hWndList, WM_SETFONT, hFontTL, TRUE

            mov     mii.cbSize, sizeof mii             ; MIIM_TYPE
            mov     mii.fMask, MIIM_DATA or MIIM_ID or MIIM_STATE or\
                               MIIM_SUBMENU or MIIM_CHECKMARKS or MIIM_BITMAP or MIIM_FTYPE
            mov     sci.cbSize, sizeof sci
            mov     sci.fMask, SIF_ALL                 ; Init. scroll info

         INVOKE     GetSystemMetrics, SM_CYCAPTION     ; 19
            mov     dwTop, eax
         INVOKE     GetSystemMetrics, SM_CYMENU        ; 19
            add     dwTop, eax
         INVOKE     GetSystemMetrics, SM_CYSIZEFRAME   ; 4
            add     dwTop, eax
         INVOKE     GetWindowRect, hWndTool, addr rect ; 24
            mov     eax, rect.bottom
            sub     eax, rect.top
            add     dwTop, eax
            add     dwTop, 4                           ; Border

         INVOKE     GetClientRect, hREdit, addr rect
            mov     eax, rect.bottom
            mov     dwBot, eax

         INVOKE     CreateSolidBrush, Color.DialogBC
            mov     hBRD, eax
         INVOKE     CreateSolidBrush, 00ffffeah
            mov     hBRS, eax

         .if IndentOn
            INVOKE     SendMessage, hREdit, UM_AUTOINDENT, IndentOn, 0
         .endif

;---------- [Fill the page setup structure
            mov     psd.lStructSize, sizeof psd
           push     hWnd
            pop     psd.hwndOwner
           push     hInst
            pop     psd.hInstance



            mov     psd.rtMargin.left, 360
            mov     psd.rtMargin.top, 360
            mov     psd.rtMargin.right, 360
            mov     psd.rtMargin.bottom, 516
            mov     psd.ptPaperSize.x, 8500
            mov     psd.ptPaperSize.y, 11000

;---------- [Allocate memory for the keyword list
         INVOKE     GetProcessHeap
         INVOKE     HeapAlloc, eax, HEAP_NO_SERIALIZE or HEAP_ZERO_MEMORY, MAXWORDMEM
            mov     hWordMem, eax
            mov     SizeWordMem, MAXWORDMEM
            mov     rpWordFree, 256*4

;---------- [Load the printer keyword list and colors
            and     ID, 0
            mov     Cnt, 12
         .while (Cnt)
               mov     eax, ID
               mov     ecx, Color02[eax*4]
               mov     edx, KeyArray[eax*4]
            INVOKE     LoadKeyWords, ecx, edx
               inc     ID
               dec     Cnt
         .endw

            mov     PrtHeading, 1
            mov     PH, 2
         INVOKE     SetTimer, hwnd, ID_TIMER1, 100, 0 ; Timer every mil second

         .if PathName
;            INVOKE     PostMessage, hwnd, WM_OPENCOMMANDARGS, 0, 0 ; From file type association or cmd
               mov     OpenFlg1, 1
               mov     OA, 1
              call     OpenFileA
         .endif

              call     LoadLookUp

;            INVOKE     GetProcAddress, hCodeHelper, addr FuncNameTAL
;            .if eax
;                 push     offset AsmRootDir
;                 push     hWnd
;                 call     eax
;            .else
;
;            .endif

;********************************************************************
;********************************************************************

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

;---------- [Size the Statusbar Control] ----------
            mov     eax, lParam         ; Get width
            and     eax, 0ffffh         ; Lowword
            shr     eax, 2              ; /4   
            mov     ecx, eax            ; Save factor
            sub     eax, 40
            mov     sbParts, eax        ; Make part 1 1/4 the width
            add     eax, ecx
            add     eax, 60
            mov     [sbParts+4], eax    ; and also part2, .. etc
            add     eax, ecx
            sub     eax, 75
            mov     [sbParts+8], eax
            add     eax, ecx
            sub     eax, 35
            mov     [sbParts+12], eax
            add     eax, 24
            mov     [sbParts+16], eax
            add     eax, 24
            mov     [sbParts+20], eax
            add     eax, 24
            mov     [sbParts+24], eax
            mov     [sbParts+28], -1    ; The last part extends to the end
         INVOKE     SendMessage, hWndStat, SB_SETPARTS, 8, addr sbParts
         INVOKE     MoveWindow, hWndStat, 0, 0, 0, 0, TRUE

         INVOKE     lstrcpy, addr szFileSize, addr szSize
         INVOKE     lstrcat, addr szFileSize, addr Fsize
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 0, addr szFileSize
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 1, addr LineData 

;---------- [Size the Toolbar Control] ----------
         INVOKE     SendMessage, hWndTool, TB_AUTOSIZE, 0, 0
         INVOKE     SendMessage, hWndTool, TB_BUTTONCOUNT, 0, 0
            mov     ecx, eax
            dec     ecx
         INVOKE     SendMessage, hWndTool, TB_GETITEMRECT, ecx, addr rect
         INVOKE     MoveWindow, hWndTool, 0, -1, rect.right, 24, TRUE
            inc     rect.right
           push     rect.right
         INVOKE     SendMessage, hWndToolA, TB_GETITEMRECT, 1, addr rect
            pop     ecx
           push     ecx
         INVOKE     MoveWindow, hWndToolA, ecx, -1, rect.right, 24, TRUE
            pop     eax
            add     rect.right, eax
            inc     rect.right
         INVOKE     MoveWindow, hWndToolB, rect.right, -1, 1200, 24, TRUE

         .if ProjOn || DriveOn
            .if ProjOn
               INVOKE     ShowWindow, hWndTree, SW_SHOWDEFAULT
               INVOKE     ShowWindow, hWndList, SW_SHOWDEFAULT
               INVOKE     ShowWindow, hWndTreeD, SW_HIDE
               INVOKE     ShowWindow, hWndListD, SW_HIDE

            .else
               INVOKE     ShowWindow, hWndTree, SW_HIDE
               INVOKE     ShowWindow, hWndList, SW_HIDE
               INVOKE     ShowWindow, hWndTreeD, SW_SHOWDEFAULT
               INVOKE     ShowWindow, hWndListD, SW_SHOWDEFAULT
            .endif
            INVOKE     ShowWindow, hWndTool2, SW_SHOWDEFAULT

         .else
            INVOKE     ShowWindow, hWndTree, SW_HIDE
            INVOKE     ShowWindow, hWndList, SW_HIDE
            INVOKE     ShowWindow, hWndTreeD, SW_HIDE
            INVOKE     ShowWindow, hWndListD, SW_HIDE
            INVOKE     ShowWindow, hWndTool2, SW_HIDE
         .endif
         .if QuickOn
            INVOKE     ShowWindow, hWndToolQ, SW_SHOWDEFAULT
         .else
            INVOKE     ShowWindow, hWndToolQ, SW_HIDE
         .endif
         .if UserOn
            INVOKE     ShowWindow, hWndToolU, SW_SHOWDEFAULT
         .else
            INVOKE     ShowWindow, hWndToolU, SW_HIDE
         .endif

         INVOKE     GetWindowRect, hWndTree, addr rect
            mov     eax, rect.right
            sub     eax, rect.left
            mov     TreeW, eax
            mov     eax, rect.bottom
            sub     eax, rect.top
            mov     TreeH, eax

;---------- [Size the Controls] ----------
         INVOKE     GetWindowRect, hWndTool2, addr rect   ; Rectangle of toolbar12
            mov     eax, rect.bottom
            sub     eax, rect.top
            mov     ToolH2, eax

            xor     eax, eax                              ; Zero out toolbar height
         .if hWndTool
            INVOKE     GetWindowRect, hWndTool, addr rect ; Rectangle of toolbar
               mov     eax, rect.bottom
               sub     eax, rect.top
         .endif
            mov     ToolH, eax                            ; Toolbar height

            xor     eax, eax                              ; Zero out statusbar height
         .if hWndStat
            INVOKE     GetWindowRect, hWndStat, addr rect ; Rectangle of statusbar
               mov     eax, rect.bottom
               sub     eax, rect.top
         .endif
           push     eax                                   ; eax = height of statusbar
         INVOKE     GetClientRect, hWnd, addr rect
            pop     eax
            dec     eax
            add     eax, ToolH
            sub     rect.bottom, eax

            mov     ecx, SplitV
            mov     edx, SplitH[4]
            mov     SplitH[8], ecx
            sub     edx, ToolH
            inc     edx
           push     ecx
           push     edx
         INVOKE     MoveWindow, hWndTree, 1, ToolH, ecx, edx, TRUE
            pop     edx
            pop     ecx
         INVOKE     MoveWindow, hWndTreeD, 1, ToolH, ecx, edx, TRUE
            mov     edx, rect.bottom
            mov     ecx, SplitH[12]
            mov     edi, ecx
            sub     edx, ecx
            add     edx, 5
            mov     ecx, SplitV
           push     ecx
           push     edx
         INVOKE     MoveWindow, hWndList, 1, edi, ecx, edx, TRUE
            pop     edx
            pop     ecx
         INVOKE     MoveWindow, hWndListD, 1, edi, ecx, edx, TRUE
            mov     ecx, SplitV
            sub     ecx, 4
           push     ecx
         INVOKE     SendMessage, hWndList, LVM_GETCOLUMNWIDTH, 0, 0
            pop     ecx
         .if eax != ecx
              push     ecx
            INVOKE     SendMessage, hWndList, LVM_SETCOLUMNWIDTH, 0, ecx
               pop     ecx
            INVOKE     SendMessage, hWndListD, LVM_SETCOLUMNWIDTH, 0, ecx
         .endif
            mov     ecx, rect.right
            mov     edx, rect.bottom
            mov     SplitV[12], edx
            xor     esi, esi
         .if ProjOn || DriveOn
            mov     esi, SplitV[8]
            sub     esi, 2
            sub     ecx, SplitH[8]
         .endif
            mov     edi, edx
            sub     edi, 2
         .if QuickOn
               add     esi, 30
               sub     ecx, 30
         .endif
         .if UserOn
               add     esi, 26
               sub     ecx, 26
         .endif

         .if PropOn
               sub     ecx, 130
         .endif

            mov     xFunct, esi
            add     xFunct, ecx
           push     ecx
         INVOKE     MoveWindow, hWndTab, esi, ToolH, ecx, edi, TRUE
         INVOKE     SendMessage, hWndTab, TCM_GETITEMRECT, 1, addr rectI
            pop     ecx
            mov     eax, rectI.bottom
            sub     eax, rectI.top
            mov     TabHgt, eax
            add     TabHgt, 2
            sub     edi, eax
            mov     rect.left, 1
            mov     rect.top, 0
         .if ProjOn || DriveOn
            mov     rect.left, 2
            sub     ecx, 1
         .endif
            sub     edi, 1
            mov     hFunct, edi
         INVOKE     MoveWindow, hREdit, rect.left, rect.top, ecx, edi, TRUE
            add     edi, TabHgt
            add     edi, 6
            mov     ecx, TabHgt
            add     ecx, 3
            mov     edx, SplitV
            inc     edx
         INVOKE     MoveWindow, hWndTool2, 0, edi, edx, ecx, TRUE
            mov     eax, TabHgt
            shl     eax, 16
            mov     edx, SplitV
            shr     edx, 1
            mov     ax, dx
         INVOKE     SendMessage, hWndTool2, TB_SETBUTTONSIZE, 0, eax
            mov     ecx, 2
         .if ProjOn || DriveOn
               mov     esi, SplitV[8]
               inc     esi
         .else
               mov     esi, 2
         .endif
            sub     edi, 4
         INVOKE     MoveWindow, hWndToolQ, esi, ToolH, 27, edi, TRUE
         .if QuickOn
            add     esi, 30
         .endif
         INVOKE     MoveWindow, hWndToolU, esi, ToolH, 23, edi, TRUE

         .if PropOn
               add     xFunct, 2
               mov     edi, rect.top
               add     edi, ToolH
            INVOKE     MoveWindow, hWndProp, xFunct, edi, 128, 150, TRUE
               add     edi, 22
               sub     hFunct, 22
               mov     yFunct, edi
               mov     wFunct, 129
            INVOKE     MoveWindow, hWndFunct, xFunct, edi, 129, hFunct, TRUE
         .endif

           call     GetXY
         INVOKE     MoveWindow, hBuild, xBuild, yBuild, 332, 282, TRUE

         .if hResParent
            INVOKE     GetClientRect, hREdit, addr rect
               mov     edx, rect.bottom
               shl     edx, 16
               mov     ecx, rect.right
               mov     dx, cx
            INVOKE     SendMessage, hResParent, WM_SIZE, 0, edx
         .endif
         .if hCtrlParent
            INVOKE     GetClientRect, hREdit, addr rect
               mov     edx, rect.bottom
               shl     edx, 16
               mov     ecx, rect.right
               mov     dx, cx
            INVOKE     SendMessage, hCtrlParent, WM_SIZE, 0, edx
         .endif

      .elseif wMsg == WM_MOVE
         .if PropOn
            INVOKE     ShowWindow, hWndFunct, SW_HIDE
            INVOKE     ShowWindow, hWndFunct, SW_SHOWDEFAULT
         .endif

      .elseif wMsg == WM_SETFOCUS
            INVOKE     SetFocus, hREdit
            INVOKE     ShowCaret, hREdit

      .elseif wMsg == WM_ACTIVATEAPP
         INVOKE     DefWindowProc, hWnd, WM_NCACTIVATE, wParam, 0 
            ret

      .elseif wMsg == WM_NCACTIVATE
            mov     eax, TRUE 
            ret

      .elseif wMsg == WM_DRAWITEM
;---------- [Draw the Tabs] ----------
            mov     esi, lParam
            lea     edi, dis
            mov     ecx, sizeof dis
            rep     movsb
         .if wParam == 702
            .if dis.itemID != -1
                  and     TabBack, 0
                  and     TabText, 0
                  mov     eax, dis.itemID
                  mov     ecx, hTabSeL[eax*8]
               INVOKE     SendMessage, ecx, EM_GETMODIFY, 0, 0
               .if eax
                     mov     TabText, 000000ffh
               .endif
                  lea     eax, szBuff
                  mov     tci.pszText, eax
                  mov     tci.cchTextMax, sizeof szBuff
               INVOKE     SendMessage, hWndTab, TCM_GETITEM, dis.itemID, addr tci
               .if dis.itemState == ODS_SELECTED
                     mov     TabBack, 00ffffffh
                  INVOKE     CreateSolidBrush, TabBack
                     mov     hBRT, eax
                  INVOKE     FillRect, dis.hdc, addr dis.rcItem, eax
                  INVOKE     SetTextColor, dis.hdc, TabText
                  INVOKE     SetBkColor, dis.hdc, TabBack
               .else
                  .if dis.itemID
                        mov     TabBack, 00ffff00h
                  .else
                     .if LineOn
                         MOVmd     TabBack, Color.LinebarBC
                     .else
                         MOVmd     TabBack, Color.SelbarBC
                     .endif
                  .endif
                  INVOKE     CreateSolidBrush, TabBack
                     mov     hBRT, eax
                  INVOKE     FillRect, dis.hdc, addr dis.rcItem, eax
                  INVOKE     SetTextColor, dis.hdc, TabText
                  INVOKE     SetBkColor, dis.hdc, TabBack
               .endif        
               INVOKE     DrawText, dis.hdc, tci.pszText, -1, addr dis.rcItem,\
                          DT_CENTER or DT_VCENTER or DT_SINGLELINE
               INVOKE     DeleteObject, hBRT
            .endif
               mov     dis.itemState, ODS_DEFAULT

         .elseif wParam == 89 || wParam == 86
            .if dis.itemID != -1
               .if wParam == 89
                  INVOKE     SendMessage, hWndFunct, LB_GETTEXT, dis.itemID, addr szBuff
               .else
                  INVOKE     SendMessage, hWndProp, CB_GETLBTEXT, dis.itemID, addr szBuff
               .endif
                  mov     Len, eax
               INVOKE     GetTextMetrics, dis.hdc, addr tm
                  mov     eax, dis.rcItem.bottom
                  add     eax, dis.rcItem.top
                  sub     eax, tm.tmHeight
                  shr     eax, 1
                  mov     esi, eax
               .if (dis.itemState & ODS_SELECTED)
                  INVOKE     CreateSolidBrush, 00800000h                  ; Highlight background color
                     mov     hBRT, eax
                  INVOKE     FillRect, dis.hdc, addr dis.rcItem, eax
                  INVOKE     SetTextColor, dis.hdc, 00ffffffh             ; Highlight text color
                  INVOKE     SetBkColor, dis.hdc, 00800000h               ; Highlight text background color
               .else
                  INVOKE     CreateSolidBrush, Color.TreeListBC           ; Background color BackGC
                     mov     hBRT, eax
                  INVOKE     FillRect, dis.hdc, addr dis.rcItem, eax
                  .if wParam == 89
                     INVOKE     SetTextColor, dis.hdc, Color.TreeListTC   ; Text color - dis.itemData
                  .else
                     INVOKE     SetTextColor, dis.hdc, 000000ffh          ; Text color - dis.itemData
                  .endif
                  INVOKE     SetBkColor, dis.hdc, Color.TreeListBC        ; Text background color
               .endif        
                  add     dis.rcItem.left, 3
               INVOKE     TextOut, dis.hdc, dis.rcItem.left, esi, addr szBuff, Len
                  mov     dis.rcItem.left, -1
                  mov     dis.rcItem.right, 150
                  dec     dis.rcItem.top
;                  sub     dis.rcItem.bottom, 1
               INVOKE     DeleteObject, hBRT
               INVOKE     CreateSolidBrush, 00000000h                     ; Frame color
                  mov     hBRT, eax
               INVOKE     FrameRect, dis.hdc, addr dis.rcItem, eax
                  inc     dis.rcItem.top
               INVOKE     DeleteObject, hBRT
            .endif
               mov     dis.itemState, ODS_DEFAULT
               mov     dis.hdc, 0
        .endif

;********************************************************************
;********************************************************************
;********************************************************************

;---------- [Notify messages] ----------
      .elseif wMsg == WM_NOTIFY
         .if wParam == 44 || wParam == 45               ; Treeview
            .if wParam == 44
               INVOKE     TreeViewNotify, wParam, lParam
            .else
               INVOKE     TreeViewNotifyD, wParam, lParam
            .endif
               jmp     Ret0
         .elseif wParam == 46 || wParam == 47           ; Listview
               and     Run, 0
               mov     ebx, lParam
            .if [ebx.NMHDR].code == NM_CLICK
               INVOKE     DisplayFileName
               .if eax == -1
                     jmp     Ret0
               .endif
                  mov     OA, 1
                 call     OpenFileA
                  jmp     Ret0
            .elseif [ebx.NMHDR].code == NM_RCLICK && wParam == 46
                  mov     Run, 75
               INVOKE     DisplayFileName
                  and     Run, 0
                  jmp     Ret0
            .endif
         .endif

            mov     ebx, lParam                      ; Get pointer to NMHDR
            mov     eax, (NMHDR ptr [ebx]).code
         .if eax == TTN_NEEDTEXT
;            INVOKE    ReleaseCapture
               mov     eax, (NMHDR ptr [ebx]).idFrom ; Resource id

;---------- [Extract the Tooltip from the registry] ----------
            .if eax > 8500 && eax < 8541
                  sub     eax, 8500
                  mov     ecx, eax
               INVOKE     BaseAscii, ecx, addr szWork, 2, 10, 0, 1, 0

                  mov     al, byte ptr szWork
                  mov     byte ptr szUserK+2, al
                  mov     al, byte ptr szWork+1
                  mov     byte ptr szUserK+3, al

               INVOKE     lstrcpy, addr WorkBuff, addr szRedit
               INVOKE     lstrcat, addr WorkBuff, addr szUserKey
      
;--------------- [Open or create the user name registry] --------------- 
               INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, offset WorkBuff, 0, offset szREGSZ, 0,\
                          KEY_WRITE or KEY_READ, 0, addr hKey, addr lpdwDisp
                  mov     lpcbData, 250
   
;--------------- [Get the user name from the registry] --------------- 
               INVOKE     RegQueryValueEx, hKey, addr szUserK, 0, addr lpType, addr szBuff, addr lpcbData
               .if eax != 0
                     mov     byte ptr szBuff, 0
               .endif
               INVOKE     RegCloseKey, hKey
   
                  mov     ecx, lParam                   ; Get the buffer addr
                  lea     eax, szBuff
                  mov     (TOOLTIPTEXT ptr [ecx]).lpszText, eax
            .else

                  mov     ebx, eax
               INVOKE     LoadString, hInst, ebx, addr szToolTip, lengthof szToolTip
                  mov     ebx, lParam                   ; Get the buffer addr
                  lea     eax, szToolTip
                  mov     (TOOLTIPTEXT ptr [ebx]).lpszText, eax
            .endif
               jmp     Ret0

         .elseif eax == TCN_SELCHANGE
            INVOKE     SendMessage, hWndTab, TCM_GETCURSEL, 0, 0  ; New selected Tab

;---------- [If Lines] ----------
            .if !eax
               .if LineOn
                     and     LineOn, 0
               .else
                     mov     LineOn, 1
               .endif
               INVOKE     SendMessage, hREdit, UM_SHOWLINES, 1, 0
               INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, TabSelect, 0  ; Old selected Tab
               INVOKE     MoveWindow, hSel, 0, 0, 0, 0, TRUE
               INVOKE     SendMessage, hREdit, UM_CHECKLINES, 0, 0
                  mov     LineOn, eax
                  jmp     Ret0
            .endif

;            INVOKE     LockWindowUpdate, hWnd           ; Lock parent to avoid flicker
INVOKE     SendMessage, hREdit, WM_SETREDRAW, 0, 0
               mov     eax, TabSelect                   ; Previous selected Tab
            .if eax
                  mov     SavSelect, eax
            .endif
              push     eax
               mov     ecx, hTabSeL[eax*8]              ; Extract previous Tabs handle
            INVOKE     ShowWindow, ecx, SW_HIDE         ; Hide its window


               lea     eax, FileName
               mov     tci.pszText, eax                 ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof FileName
            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, TabSelect, addr tci
            .if byte ptr FileName == '*' && byte ptr FileName+2 == 'R'
               .if hResForm
                  INVOKE     ShowWindow, hResForm, SW_HIDE
               .endif
            .elseif byte ptr FileName == '*' && byte ptr FileName+2 == 'C'
               .if hCtrlForm
                  INVOKE     ShowWindow, hCtrlForm, SW_HIDE
               .endif
            .endif


            INVOKE     SendMessage, hWndTab, TCM_GETCURSEL, 0, 0  ; New selected Tab
               mov     TabSelect, eax                   ; Save the Tab ID
               pop     ebx

            .if !TabSelect && ebx
               INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, ebx, 0  ; New selected Tab
                  mov     eax, ebx
                  mov     TabSelect, ebx
            .elseif !TabSelect && !ebx
                  mov     ebx, SavSelect
                  mov     TabSelect, ebx
               INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, ebx, 0  ; New selected Tab
                  mov     eax, ebx
            .endif

               mov     ecx, hTabSeL[eax*8]             ; Extract new Tabs handle
               mov     hREdit, ecx
               and     SavHand, 0

FromClose:
            INVOKE     IsWindowVisible, hBuild
            .if eax
               INVOKE     ShowWindow, hBuild, SW_HIDE
            .endif
               lea     eax, FileName
               mov     tci.pszText, eax                 ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof FileName
            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, TabSelect, addr tci
            INVOKE     lstrcpy, addr FileName, tci.pszText
            INVOKE     lstrcpy, addr PathName, tci.lParam
              call     SetTitle
;INVOKE     MessageBox, NULL, addr FileName, addr AppName, MB_OK

            INVOKE     ShowWindow, hREdit, SW_SHOW      ; Show its window
            INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
               mov     BytesRead, eax
            INVOKE     BaseAscii, BytesRead, addr Fsize, 0, 10, 1, 0, 1
            INVOKE     lstrcpy, addr szFileSize, addr szSize
            INVOKE     lstrcat, addr szFileSize, addr Fsize
            INVOKE     SendMessage, hWndStat, SB_SETTEXT, 0, addr szFileSize

            INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr

              call     SetSize
            INVOKE     SetFocus, hREdit
;            INVOKE     LockWindowUpdate, 0              ; Unock parent
            INVOKE     SendMessage, hREdit, WM_SETREDRAW, 1, 0
            INVOKE     SendMessage, hREdit, UM_REDRAW, 0, 1

            .if byte ptr FileName == '*' && byte ptr FileName+2 == 'R'
               INVOKE     SetFocus, hResParent
               .if hResForm
                  INVOKE     ShowWindow, hResForm, SW_SHOW
               .endif
            .elseif byte ptr FileName == '*' && byte ptr FileName+2 == 'C'
               INVOKE     SetFocus, hCtrlParent
               .if hCtrlForm
                  INVOKE     ShowWindow, hCtrlForm, SW_SHOW
               .endif
            .endif

            .if SavHand
               INVOKE     DestroyWindow, SavHand
            .endif

;            .if SavSyntaxOn
                  mov     eax, TabSelect                   ; Current selected Tab
                  mov     ecx, hTabSeL+[eax*8+4]           ; Extract current Tabs code   ;handle
               .if SyntaxOn && ecx != 1 || !SyntaxOn && ecx == 1
                  .if SyntaxOn
                        and     SyntaxOn, 0
                  .else
                        mov     SyntaxOn, 1
                  .endif
                  INVOKE     SetValues, UM_HILIGHT, STATE_NOHILITE, 0
                    call     CheckState
               .endif
;            .endif

               mov     ecx, 22034
              call     DoBookmarks
              call     GetExtent

            .if ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm'
;                 call     FindStart
            .endif
            .if ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm' ||\
                ExtType == '.' && ExtType + 1 == 'r' && ExtType + 2 == 'c' ||\
                ExtType == 'i' && ExtType + 1 == 'n' && ExtType + 2 == 'c' ||\
                ExtType == 'r' && ExtType + 1 == 'c'

                  mov     eax, hREdit
                  mov     esi, hProjArray
                  xor     edx, edx
                  mov     ecx, ProjCnt
               .while (ecx)
                  .if dword ptr[esi+edx] == eax
                        xor     ebx, ebx
                        mov     eax, dword ptr[esi+edx+4]
                        mov     bl, byte ptr[esi+edx+8]
                        mov     bh, byte ptr[esi+edx+9]
                        mov     hItem, eax
                       push     ebx
                       push     ProjGroup
                        mov     ecx, esi
                        add     ecx, edx
                        add     ecx, 10 ;9
;                     INVOKE     lstrcpy, addr szProject, ecx
                        mov     byte ptr ProjGroup, bh
                        mov     ebx, ProjGroup
                     INVOKE     lstrcpy, ProjNamArray[ebx*4], ecx
INVOKE     lstrcpy, addr szBuff, ProjNamArray[ebx*4]
                        pop     eax
                     .if ProjOn && eax != ProjGroup
              call     CheckState
              call     LoadProjectTree
                     .endif
                        pop     ebx
                        mov     ecx, 1
                     .break
                  .endif
                     add     edx, 36
                     dec     ecx
               .endw
                 push     ebx
                 push     ecx

               .if PropOn
                  INVOKE     WriteReadMem, 1, PropCode
               .endif
                  pop     ecx

               .if ProjOn
                     mov     edi, hItem
               .else
                     mov     edi, hItemD
               .endif
                  mov     esi, ProjDrive
               .if ecx && bl == 1 && edi
;                  INVOKE     LockWindowUpdate, hWnd
INVOKE     SendMessage, hREdit, WM_SETREDRAW, 0, 0
                     mov     FromTab, 1
                  INVOKE     SendMessage, hWndTree[esi*4], TVM_SELECTITEM, TVGN_CARET, edi
xor     eax, eax

.if !eax
         INVOKE     SendMessage, hWndTree[esi*4], TVM_GETNEXTITEM, TVGN_ROOT, 0
         .if !eax
               jmp     NoParent
         .endif
            mov     hTemp, eax
         INVOKE     SendMessage, hWndTree[esi*4], TVM_GETNEXTITEM, TVGN_CHILD, hTemp
         .while (eax != 0) 
               mov     hTemp, eax
               mov     tvi.hItem, eax
               mov     tvi.imask, TVIF_TEXT
               lea     eax, szWork
               mov     tvi.pszText, eax
               mov     tvi.cchTextMax, sizeof szWork
            INVOKE     SendMessage, hWndTree[esi*4], TVM_GETITEM, NULL, addr tvi
            INVOKE     lstrcmpi, addr szWork, addr szBuff
            .if eax == 0
                MOVmd     hItem, hTemp
                  mov     FromTab, 1
               INVOKE     SendMessage, hWndTree[esi*4], TVM_SELECTITEM, TVGN_CARET, hItem
               INVOKE     SendMessage, hWndTree[esi*4], TVM_ENSUREVISIBLE, 0, hItem
               .break
            .endif
            INVOKE     SendMessage, hWndTree[esi*4], TVM_GETNEXTITEM, TVGN_NEXT, hTemp
         .endw
.endif

                     and     FromTab, 0
                     mov     eax, edi
                     mov     rect.left, eax

;---------- [Select the item in the Listview
                  .if FileName
                        mov     lvf.flags, LVFI_STRING
                        mov     lvf.psz, offset FileName
                     INVOKE     SendMessage, hWndList[esi*4], LVM_FINDITEM, -1, addr lvf
                     .if eax != -1
                           mov     lvi.iItem, eax
                           mov     lvi.imask, LVIF_STATE
                           mov     lvi.state, LVIS_SELECTED or LVIS_FOCUSED
                           mov     lvi.stateMask, -1
                        INVOKE     SendMessage, hWndList[esi*4], LVM_SETITEMSTATE, lvi.iItem, addr lvi
                     .endif
                  .endif

;---------- [Set the scroll for the Treeview
                  INVOKE     SendMessage, hWndTree[esi*4], TVM_GETITEMRECT, TRUE, addr rect
                  INVOKE     GetScrollInfo, hWndTree[esi*4], SB_VERT, addr sci
                  INVOKE     SendMessage, hWndTree[esi*4], TVM_GETVISIBLECOUNT, 0, 0
                     mov     ecx, rect.bottom
                     sub     ecx, rect.top
                    imul     eax, ecx      ; Height of line
                     shr     eax, 1
                     xor     ebx, ebx
                     xor     ecx, ecx
                  .if rect.top <= eax
                        sub     eax, rect.top
                        mov     ebx, eax
                  .elseif rect.top >= eax
                        sub     rect.top, eax
                        mov     ecx, rect.top
                  .endif

                     mov     eax, sci.nPos

                  .if ebx
                        shr     ebx, 4
                        sub     eax, ebx
                  .elseif ecx
                        shr     ecx, 4
                        inc     ecx
                        add     eax, ecx
                  .endif
                  .if sdword ptr eax < 0          ; Check for negative number
                        xor     eax, eax
                  .endif
                     shl     eax, 16
                     mov     ecx, SB_THUMBPOSITION
                     mov     ax, cx
;;;;.if ProjOn  ; $$$$
                  INVOKE     SendMessage, hWndTree[esi*4], WM_VSCROLL, eax, 0
;;;;.endif
;                  INVOKE     SendMessage, hWndStat, SB_SETTEXT, 2, addr szProject
                     mov     eax, ProjGroup
                  INVOKE     SendMessage, hWndStat, SB_SETTEXT, 2, ProjNamArray[eax*4]
;                  INVOKE     LockWindowUpdate, 0
NoParent:
                  INVOKE     ShowWindow, hREdit, SW_SHOW
                  INVOKE     SendMessage, hREdit, WM_SETREDRAW, 1, 0
                  INVOKE     SendMessage, hREdit, UM_REDRAW, 0, 1
                  .if PropOn
                     INVOKE     SendMessage, hWndFunct, LB_SETCURSEL, -1, 0
                  .endif
               .endif
                  pop     ebx
            .endif

         .elseif eax == EN_SELCHANGE
               mov     ecx, [ebx].EDITCHANGE.LineNum
               inc     ecx
            INVOKE     BaseAscii, ecx, addr cnt1, 6, 10, 0, 1, 0
            .if [ebx].EDITCHANGE.SelType != 44  ; 44 = mouse wheel
                  mov     ecx, [ebx].EDITCHANGE.TotLines
               INVOKE     BaseAscii, ecx, addr cnt2, 6, 10, 0, 1, 0
                  mov     ecx, [ebx].EDITCHANGE.cr.cpMin
                  sub     ecx, [ebx].EDITCHANGE.cpLine
                  inc     ecx
               .if sdword ptr ecx < 0 || sdword ptr ecx > 9999
                     mov     ecx, 1
               .endif
                  mov     CurPos, ecx
               INVOKE     BaseAscii, ecx, addr cnt3, 4, 10, 0, 1, 0
                  mov     ecx, [ebx].EDITCHANGE.LineLen
               .if ecx
                     dec     ecx
               .endif
               INVOKE     BaseAscii, ecx, addr cnt4, 4, 10, 0, 1, 1
                  mov     eax, [ebx].EDITCHANGE.cr.cpMax
                  sub     eax, [ebx].EDITCHANGE.cr.cpMin
                  mov     SelectOn, eax
            .endif
            INVOKE     SendMessage, hWndStat, SB_SETTEXT, 1, addr LineData 

            INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
            .if eax != BytesRead
                  mov     BytesRead, eax
               INVOKE     BaseAscii, BytesRead, addr Fsize, 0, 10, 1, 0, 1
               INVOKE     lstrcpy, addr szFileSize, addr szSize
               INVOKE     lstrcat, addr szFileSize, addr Fsize
                  mov     ecx, 22034
                 call     DoBookmarks
;               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 0, addr szFileSize ;N O T E !! Uncomment $$$$$$$$$
            .endif
            INVOKE     SendMessage, hREdit, UM_CHECKLINES, 0, 0
               mov     LineOn, eax
              call     CheckState

         .endif
            jmp     DefWin

;---------- [From Addins] ----------
      .elseif wMsg == IDM_GETDWORDS
            lea     eax, hWnd
            ret

      .elseif wMsg == IDM_GETPROC
            lea     eax, BaseAscii
            mov     lpBaseAscii, eax
            lea     eax, AsciiBase
            mov     lpAsciiBase, eax
            lea     eax, CheckState
            mov     lpEnaDisMenu, eax
            lea     eax, lpBaseAscii
            ret

      .elseif wMsg == IDM_GETDATA
            lea     eax, RootDir
            mov     lpRoot, eax
            lea     eax, PathName
            mov     lpPath, eax
            lea     eax, FileName
            mov     lpName, eax
            lea     eax, szProject
            mov     lpProject, eax
            lea     eax, szLoadPath
            mov     lpProPath, eax
            lea     eax, szRedit
            mov     lpRegKey, eax
            lea     eax, lpRoot
            ret

      .elseif wMsg == WM_CTLCOLORLISTBOX || wMsg == WM_CTLCOLOREDIT
            mov     eax, lParam
         .if eax && eax != hREdit ;&& PropOn
            INVOKE     SetBkColor, wParam, Color.TreeListBC
            INVOKE     SetTextColor, wParam, Color.TreeListTC
               mov     eax, hSavBRM
               ret
         .endif

;********************************************************************
;********************************************************************
;********************************************************************
;********************************************************************

;---------- [System and user commands] ----------
      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
            mov     ebx, wParam
            mov     ecx, lParam
            shr     ebx, 16
           cwde                          ; Only low word contains command
            mov     wParam, eax

;---------- [Properties list] ----------
         .if eax == 86 && ebx == CBN_SELCHANGE
            INVOKE     SendMessage, hWndProp, CB_GETCURSEL, 0, 0
               mov     PropCode, eax
            .if PathName
               INVOKE     WriteReadMem, 1, PropCode
            .endif

;---------- [Function list] ----------
         .elseif eax == 89 && ebx == LBN_SELCHANGE
            INVOKE     SendMessage, hWndFunct, LB_GETCURSEL, 0, 0
            INVOKE     SendMessage, hWndFunct, LB_GETITEMDATA, eax, 0
               dec     eax
            INVOKE     SendMessage, hREdit, EM_LINEINDEX, eax, 0
               mov     cr.cpMin, eax
               mov     cr.cpMax, eax
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
            INVOKE     SendMessage, hREdit, EM_SCROLLCARET, 0, 0
            INVOKE     CenterSel, 0

;---------- [Build menu] ----------
         .elseif eax > 2100 && eax < 2500
            INVOKE     DoMenus, wParam, 1

;---------- [Addins menu] ----------
         .elseif eax > 3100 && eax < 3500
            INVOKE     DoMenus, wParam, 2

;---------- [Tools menu] ----------
         .elseif eax > 4100 && eax < 4500
            INVOKE     DoMenus, wParam, 3

;---------- [Help menu] ----------
         .elseif eax > 7100 && eax < 7500
            INVOKE     DoMenus, wParam, 4

;---------- [Quick code
         .elseif eax > 7500 && eax < 8541 || eax >= IDM_BUTTBUILD && eax <= IDM_NOEDITSAMP
               lea     eax, szWork
               mov     tci.pszText, eax              ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof szWork
            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, TabSelect, addr tci
;---------- [Bypass Code Toolbars if ResEdit or CtrlBuild] ----------
            .if byte ptr szWork == '*' && byte ptr szWork+2 == 'R' ||\
                byte ptr szWork == '*' && byte ptr szWork+2 == 'C'
                  jmp     Ret0
            .endif
            INVOKE     QuickCode, wParam, 0

;---------- [Quick code
         .elseif eax == IDM_CALC
            INVOKE     QuickCode, wParam, 0

         .elseif eax == 7077                         ; From StepByStep
            INVOKE     ReadTheFile, addr szLoadPath

         .elseif eax == IDM_STEPBYSTEP
            .if hStepByStep
                  jmp     GetProcStep
            .endif
            INVOKE     LoadLibrary, addr LibNameSB
            .if !eax
               INVOKE     MessageBox, NULL, addr szError5, addr LibNameSB, MB_OK or MB_ICONERROR
                  jmp     Ret0
            .endif
               mov     hStepByStep, eax

GetProcStep:
            INVOKE     GetProcAddress, hStepByStep, addr FuncNameSB
            .if !eax
                  jmp     Ret0
            .endif

           push     eax
         INVOKE     StripFileExt, addr PathName
         INVOKE     StripFileName, addr PathName
            pop     eax

              push     offset szByteCode
              push     offset szRedit
              push     offset PathName ;szProjPath
              push     offset FileName
              push     hREdit
              push     hInst
              push     hWnd
              call     eax
               jmp     Ret0

         .elseif eax == IDM_NEW

;---------- [Resequence the Untitled windows and create one if less then 4] ----------
            INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
               mov     Cnt, eax
               mov     ID, 0
               mov     byte ptr szUntitled+10, '0'

            .while (Cnt)
                  lea     eax, FileName   
                  mov     tci.pszText, eax                   ; Pointer to string containing tab text
                  mov     tci.cchTextMax, sizeof FileName
               INVOKE     SendMessage,  hWndTab, TCM_GETITEM, ID, addr tci
               INVOKE     lstrcpy, addr FileName, tci.pszText
               .if byte ptr FileName == '('
                     add     byte ptr szUntitled+10, 1
                     mov     tci.pszText, offset szUntitled  ; Pointer to string containing tab text
                     mov     tci.cchTextMax, 0
                  INVOKE     lstrcpy, tci.lParam, addr szUntitled
                  INVOKE     SendMessage, hWndTab, TCM_SETITEM, ID, addr tci
                  INVOKE     lstrcpy, addr PathName, addr szUntitled
                    call     SetTitle

                  .if byte ptr szUntitled+10 == '4'
                        mov     eax, ID                      ; Current selected Tab
                        mov     ecx, hTabSeL[eax*8]         ; Extract current Tabs handle
                        mov     hREdit, ecx
                     INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, ID, 0
                        mov     nmhdr.code, TCN_SELCHANGE
                        lea     eax, nmhdr
                     INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
                     INVOKE     SetFocus, hREdit
                        jmp     Ret0
                  .endif
               .endif
                  dec     Cnt
                  inc     ID
            .endw


            INVOKE     LockWindowUpdate, hWnd          ; Lock parent to avoid flicker
               mov     NewTabWnd, 1
              call     NewTab
               and     NewTabWnd, 0
            INVOKE     SendMessage, hWndTab, TCM_GETCURSEL, 0, 0  ; New selected Tab
               mov     TabSelect, eax                    ; Save the Tab ID

            .if SW55
               .if SW55 == 1
                  INVOKE     lstrcpy, addr szWork, addr szResEdit
               .elseif SW55 == 2
                  INVOKE     lstrcpy, addr szWork, addr szCtrlBuild
               .endif
                  and     SW55, 0
                  lea     eax, szWork
                  mov     tci.pszText, eax  ; Pointer to string containing tab text
                  mov     tci.cchTextMax, 0
               INVOKE     lstrcpy, tci.lParam, addr szWork
               INVOKE     SendMessage, hWndTab, TCM_SETITEM, TabSelect, addr tci
            .endif

            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, TabSelect, addr tci
            INVOKE     lstrcpy, addr FileName, tci.pszText
            INVOKE     lstrcpy, addr PathName, tci.lParam
              call     SetTitle
              call     SetSize
            INVOKE     LockWindowUpdate, 0              ; Unock parent
              call     LoadOpenItems

;--------------- [File name list from the file menu] --------------- 
         .elseif eax > 1400 && eax < 1416
              push     eax
            INVOKE     lstrcpy, addr WorkBuff, addr PathName
               pop     eax
            INVOKE     GetRegPath, eax, addr szRedit
            INVOKE     lstrcpy, addr PathName, eax
               mov     OpenFlg1, 1
               mov     OA, 1
              call     OpenFileA

;--------------- [Select tab from window menu] --------------- 
         .elseif eax > 9400 && eax < 9499
               sub     eax, 9400
            INVOKE     SendMessage,  hWndTab, TCM_SETCURSEL, eax, 0
               mov     nmhdr.code, TCN_SELCHANGE
               lea     eax, nmhdr
            INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
              call     CheckState

         .elseif eax == IDM_OPEN
              call     OpenFileA

         .elseif eax == IDM_OPENHEX
               mov     OpenFlg1, 9
              call     OpenFileA
            .if eax == -1
               INVOKE     SetFocus, hREdit
                  jmp     Ret0
            .endif
               mov     ecx, hBuff
            INVOKE     lstrcpy, ecx, addr PathName
              call     ReadF
            .if eax
               INVOKE     BuildHex, hREdit, fpMem, BytesR, 16
                 call     CheckState
            .endif
            .if hpMem
               INVOKE     GlobalUnlock, fpMem
               INVOKE     GlobalFree, hpMem
                  mov     hpMem, 0
            .endif 

         .elseif eax == IDM_SAVE
               and     SaveAs, 0
              call     SaveFile
              call     CheckState

         .elseif eax == IDM_SAVEAS
               mov     SaveAs, 1    
              call     SaveFile
              call     CheckState

         .elseif eax == IDM_SAVEHEXAS
              call     ConvHex
              call     CheckState

         .elseif eax == IDM_SAVEUNIAS
              call     ConvToUnicode

         .elseif eax == IDM_SAVEALL
              push     TabSelect
               lea     eax, FileName
               mov     tci.pszText, eax                ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof FileName
            INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
               dec     eax
               mov     Cnt, eax
               mov     ID, 1                           ; Bypass Line tab
            .while (Cnt)
                  mov     eax, ID                      ; Selected Tab
                  mov     ecx, hTabSeL[eax*8]          ; Extract Edits handle
                  mov     hREdit, ecx
               INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, ID, 0
               INVOKE     SendMessage,  hWndTab, TCM_GETITEM, ID, addr tci
               INVOKE     lstrcpy, addr PathName, tci.lParam
                  mov     nmhdr.code, TCN_SELCHANGE
                  lea     eax, nmhdr
               INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
                  and     SaveAs, 0
                 call     SaveFile
               .if eax == IDCANCEL
                     jmp     Ret0
               .endif
                  inc     ID
                  dec     Cnt
            .endw
               pop     TabSelect
            INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, TabSelect, 0
               mov     nmhdr.code, TCN_SELCHANGE
               lea     eax, nmhdr
            INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
              call     CheckState

         .elseif eax == IDM_TABSW
            INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
               mov     ecx, TabSelect                     ; Tab ID
               inc     ecx
            .if eax == ecx && eax > 1
                  mov     ecx, 1
            .elseif eax > ecx
            .else
                  jmp     Ret0
            .endif
            INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, ecx, 0
               mov     nmhdr.code, TCN_SELCHANGE
               lea     eax, nmhdr
            INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
               jmp     Ret0

         .elseif eax == IDM_CLOSETAB && TabSelect
CloseTab:
               and     SavHand, 0
               lea     eax, FileName
               mov     tci.pszText, eax                   ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof FileName
            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, TabSelect, addr tci
            INVOKE     lstrcpy, addr FileName, tci.pszText
            INVOKE     lstrcpy, addr PathName, tci.lParam

            .if byte ptr FileName == '*' && byte ptr FileName+2 == 'R' ||\
                byte ptr FileName == '*' && byte ptr FileName+2 == 'C'
               .if hResParent && byte ptr FileName+2 == 'R'
                  INVOKE     LoadLibrary, addr LibNameR
                  .if eax
                        mov     hLibR, eax
                     INVOKE     GetProcAddress, hLibR, addr FuncNameWC
                     .if eax
                           xor     ecx, ecx
                          push     ecx
                          call     eax
                        INVOKE     FreeLibrary, hLibR
                           and     hLibR, 0
                     .else
                     .endif
                  .else
                  .endif
                     mov     OpenCloseOnR, 0
                  INVOKE     EnableMenuItem, hMenu, IDM_RESOPEN, MF_ENABLED
                  INVOKE     EnableMenuItem, hMenu, IDM_RESCLOSE, MF_GRAYED
               .endif

               .if hCtrlParent && byte ptr FileName+2 == 'C'
                  INVOKE     LoadLibrary, addr LibNameCB
                  .if eax
                        mov     hLibCB, eax
                     INVOKE     GetProcAddress, hLibCB, addr FuncNameWC
                     .if eax
                           xor     ecx, ecx
                          push     ecx
                          call     eax
                        INVOKE     FreeLibrary, hLibCB
                           and     hLibCB, 0
                     .else
                     .endif
                  .else
                  .endif
                     mov     OpenCloseOnCB, 0
                  INVOKE     EnableMenuItem, hMenu, IDM_CTRLOPEN, MF_ENABLED
                  INVOKE     EnableMenuItem, hMenu, IDM_CTRLCLOSE, MF_GRAYED
               .endif
            .endif

               mov     eax, TabSelect                     ; Current selected Tab
               mov     ecx, hTabSeL[eax*8]                ; Extract current Tabs handle
               mov     SavHand, ecx
               mov     hREdit, ecx
            INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
            .if eax != 0
               INVOKE     MessageBox, NULL, addr szError2, addr AppName,
                          MB_YESNOCANCEL or MB_ICONEXCLAMATION or MB_SYSTEMMODAL
               .if eax == IDYES
                     and     SaveAs, 0
                    call     SaveFile
               .endif
            .endif
            INVOKE     MoveWindow, hSel, 0, 0, 0, 0, TRUE
               mov     ecx, 22035
              call     DoBookmarks

            INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
            .if eax == 2
                  and     SavHand, 0
               .if PropOn
                     and     PropOn, 0
                  INVOKE     ShowWindow, hWndProp, SW_HIDE
                  INVOKE     ShowWindow, hWndFunct, SW_HIDE
               .endif
                  mov     byte ptr szUntitled+10, '1'
                  mov     tci.pszText, offset szUntitled  ; Pointer to string containing tab text
                  mov     tci.cchTextMax, 0

                  mov     byte ptr szUntitled+10, '1'
               INVOKE     lstrcpy, tci.lParam, addr szUntitled

               INVOKE     SendMessage, hWndTab, TCM_SETITEM, TabSelect, addr tci
               INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, offset szCR ;szNULL
               INVOKE     SendMessage, hREdit, EM_SETMODIFY, FALSE, 0
               INVOKE     SetFocus, hREdit

                  and     CloseAllOn, 0
               INVOKE     lstrcpy, addr PathName, tci.lParam
                  mov     eax, hREdit
                  mov     esi, hProjArray
                  xor     edx, edx
                  mov     ecx, ProjCnt
               .while (ecx)
                  .if dword ptr[esi+edx] == eax
                        mov     dword ptr[esi+edx], 1234
                        mov     word ptr[esi+edx+8], 00
                     .break
                  .endif
                     add     edx, 36
                     dec     ecx
               .endw
                 call     SetSize

            .else
               INVOKE     LockWindowUpdate, hWnd          ; Lock parent to avoid flicker
               INVOKE     SendMessage, hWndTab, TCM_DELETEITEM, TabSelect, 0
                  xor     ecx, ecx
               .if TabSelect > 1
                     dec     TabSelect
               .else
                     inc     ecx
               .endif
                 push     ecx
               INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, TabSelect, 0
                  mov     eax, TabSelect                  ; Save the Tab ID
                  pop     ecx
               .if ecx
                     inc     eax
               .endif
                  mov     ecx, hTabSeL[eax*8]             ; Extract new Tabs handle
                  mov     hREdit, ecx
               INVOKE     SetFocus, hREdit

;---------- [Shift handle left if close] ----------
                  xor     eax, eax
                  mov     ecx, 32
               .while     ecx                             ; Find handle of active window in the array
                     mov     edx, SavHand
                  .if hTabSeL[eax] == edx
                      MOVmd     hTabSeL[eax], hTabSeL[eax+8]
                      MOVmd     hTabSeL[eax+4], hTabSeL[eax+12]
                        add     eax, 8
                        dec     ecx
                     .while     ecx                       ; Shift the array to the left
                         MOVmd     hTabSeL[eax], hTabSeL[eax+8]
                         MOVmd     hTabSeL[eax+4], hTabSeL[eax+12]
                           add     eax, 8
                           dec     ecx
                     .endw
                     .break  
                  .endif
                     add     eax, 8
                     dec     ecx
               .endw

                  mov     eax, SavHand
                  mov     esi, hProjArray
                  xor     edx, edx
                  mov     ecx, ProjCnt
               .while (ecx)
                  .if dword ptr[esi+edx] == eax
                        mov     dword ptr[esi+edx], 1234
                        mov     word ptr[esi+edx+8], 00
                     .break
                  .endif
                     add     edx, 36
                     dec     ecx
               .endw

               INVOKE     LockWindowUpdate, 0             ; Unock parent
               INVOKE     ShowWindow, hREdit, SW_SHOW
                 call     SetSize

               .if CloseAllOn                             ; Close all tabs
                  .if SavHand
                     INVOKE     DestroyWindow, SavHand
                  .endif
                  INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
                  .if eax > 1
                        jmp     CloseTab
                  .endif
                     and     SavHand, 0
                  INVOKE     RtlZeroMemory, hProjArray, 1500
               .endif
                  and     CloseAllOn, 0
            .endif
              call     LoadOpenItems
               jmp     FromClose

         .elseif eax == IDM_CLOSEALL
            INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
               dec     eax
               mov     TabSelect, eax
            INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, TabSelect, 0
               mov     nmhdr.code, TCN_SELCHANGE
               lea     eax, nmhdr
            INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
               mov     CloseAllOn, 1
               jmp     CloseTab

         .elseif eax == IDM_PAGESETUP
              call     DoPageSU

         .elseif eax == IDM_PRINT
              call     Print

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

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

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

         .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_UNDO || eax == IDM_REDO
            INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
               mov     Chg, eax
            .if wParam == IDM_UNDO
               INVOKE     SendMessage, hREdit, EM_UNDO, 0, 0
            .else
               INVOKE     SendMessage, hREdit, EM_REDO, 0, 0
            .endif
            INVOKE     SendMessage, hREdit, EM_SETMODIFY, Chg, 0
              call     CheckState

         .elseif eax == IDM_UNDOREDO
            INVOKE     SendMessage, hREdit, EM_EMPTYUNDOBUFFER, 0, 0
              call     CheckState

         .elseif eax == IDM_CLRCLIP
            INVOKE     OpenClipboard, NULL
            INVOKE     EmptyClipboard
            INVOKE     CloseClipboard
              call     CheckState

         .elseif eax == IDM_FINDTEXT
            INVOKE     SendMessage, hREdit, EM_GETSELTEXT, 0, addr szFind
            INVOKE     CreateDialogParam, hInst, 4901, hREdit, addr FindReplace, 4901
               cmp     eax, 0            ; Canceled?
                je     Ret0              ; yes, then return
            INVOKE     SetDlgItemText, hFRDlg, 101, addr szFind

         .elseif eax == IDM_FINDNEXT
               and     Prev, 0
               mov     FRFlags, 1
               mov     ft.chrg.cpMax, -1

FindNext1:
            INVOKE     SendMessage, hREdit, EM_GETSELTEXT, 0, addr szFind
            INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
            .if !Prev 
                  add     cr.cpMin, 1
            .endif
             MOVmd     ft.chrg.cpMin, cr.cpMin
               lea     eax, offset szFind
               mov     ft.lpstrText, eax
            INVOKE     Find, hwnd, 1, FRFlags, ft.lpstrText, Prev

         .elseif eax == IDM_FINDPREV
               mov     Prev, 1
               and     FRFlags, 0
               mov     ft.chrg.cpMax, 0
               jmp     FindNext1

         .elseif eax == IDM_REPLACETEXT
            INVOKE     SendMessage, hREdit, EM_GETSELTEXT, 0, addr szFind
            INVOKE     CreateDialogParam, hInst, 4902, hREdit, addr FindReplace, 4902
               cmp     eax, 0            ; Canceled?
                je     Ret0              ; yes, then return
            INVOKE     SetDlgItemText, hFRDlg, 101, addr szFind

         .elseif eax == IDM_GOTO && !hGoto
            INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
            .if eax
               INVOKE     CreateDialogParam, hInst, 4801, hwnd, addr GotoLineProc, 0
            .endif

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

         .elseif eax == IDM_EDITF
               mov     FontCode, 1
              call     ChgFont

         .elseif eax == IDM_LINEF
               mov     FontCode, 2
              call     ChgFont

         .elseif eax == IDM_TREEF
               mov     FontCode, 3
              call     ChgFont

         .elseif eax == IDM_PRINTF
               mov     FontCode, 4
              call     ChgFont

         .elseif eax == IDM_COLOR
            .if hColor || hWndDlg
                  jmp     Ret0
            .endif
            INVOKE     CreateDialogParam, hInst, 4805, hREdit, addr ChgColor, 0
            .if eax
                  mov     hColor, eax
                  mov     hWndDlg, eax
               INVOKE     SendMessage, hColor, WM_COMMAND, 200, 0
            .endif

         .elseif eax == IDM_INDENT
            .if IndentOn
                  and     IndentOn, 0
               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 4, addr szNULL
            .else
                  mov     IndentOn, 1
               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 4, addr szIND
            .endif
            INVOKE     SendMessage, hREdit, UM_AUTOINDENT, IndentOn, 0
              call     CheckState

         .elseif eax == IDM_CONSTR
            .if ConstrainOn
                  and     ConstrainOn, 0
               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 5, addr szNULL
            .else
                  mov     ConstrainOn, 1
               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 5, addr szCUR
            .endif
            INVOKE     SendMessage, hREdit, UM_SETCONSTRAIN, 0, ConstrainOn
              call     CheckState

         .elseif eax == IDM_COLUMN && eax == 9999 ; ********************
            .if ColumnOn
                  and     ColumnOn, 0
               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 7, addr szNULL
            .else
                  mov     ColumnOn, 1
               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 7, addr szCOL
            .endif
            INVOKE     SendMessage, hREdit, UM_SETCOLUMNBLK, 0, ColumnOn
              call     CheckState

         .elseif eax == IDM_CONVTAB
            .if hWndDlg
                  jmp     Ret0
            .endif
               lea     eax, FileName
               mov     tci.pszText, eax                    ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof FileName
            INVOKE     SendMessage, hWndTab, TCM_GETITEM, TabSelect, addr tci
            INVOKE     lstrcpy, addr FileName, tci.pszText
            .if byte ptr FileName == '('
               INVOKE     MessageBox, NULL, addr szError3, addr AppName, MB_OK or MB_ICONINFORMATION
                  jmp     Ret0
            .endif
            INVOKE     CreateDialogParam, hInst, 4802, hREdit, addr ConvTabs, 0
               mov     hWndDlg, eax

         .elseif eax > 22000 && eax < 22034
               mov     ecx, eax
              call     DoBookmarks

         .elseif eax == IDM_PROJECTS
            .if ProjOn
                  and     ProjOn, 0
            .else
                  and     ProjDrive, 0
                  mov     ProjOn, 1
               .if DriveOn
                     and     DriveOn, 0
                  INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_CLOSEALL, 0
               .endif
;                  and     ProjDrive, 0
;                  mov     ProjOn, 1
;                  and     DriveOn, 0
            .endif
            INVOKE     SendMessage, hWndTree, TVM_SELECTITEM, TVGN_CARET, hItem
            INVOKE     SendMessage, hWndTree, TVM_ENSUREVISIBLE, 0, hItem
              call     SetSize
              call     CheckState

         .elseif eax == IDM_DRIVES
            .if DriveOn
                  and     DriveOn, 0
            .else
                  mov     ProjDrive, 1
                  mov     DriveOn, 1
               .if ProjOn
                     and     ProjOn, 0
                  INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_CLOSEALL, 0
               .endif
;                  mov     ProjDrive, 1
;                  mov     DriveOn, 1
;                  and     ProjOn, 0
            .endif
            INVOKE     SendMessage, hWndTreeD, TVM_SELECTITEM, TVGN_CARET, hItemD
            INVOKE     SendMessage, hWndTreeD, TVM_ENSUREVISIBLE, 0, hItemD
              call     SetSize
              call     CheckState

         .elseif eax == IDM_CODEH
            .if CodeHelperOn
                  and     CodeHelperOn, 0
            .else
                  mov     CodeHelperOn, 1
            .endif
              call     CheckState

         .elseif eax == IDM_QUICKC
            .if QuickOn
                  and     QuickOn, 0
            .else
                  mov     QuickOn, 1
            .endif
              call     SetSize
              call     CheckState

         .elseif eax == IDM_USERC
            .if UserOn
                  and     UserOn, 0
            .else
                  mov     UserOn, 1
            .endif
              call     SetSize
              call     CheckState

         .elseif eax == IDM_AUTOR
            .if AutoRefOn
                  and     AutoRefOn, 0
               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 6, addr szNULL
            .else
                  mov     AutoRefOn, 1
               INVOKE     SendMessage, hWndStat, SB_SETTEXT, 6, addr szREF
            .endif
              call     CheckState

         .elseif eax == IDM_FUNCT
            .if PropOn
                  and     PropOn, 0
                  mov     TempWord2, SW_HIDE
            .else
                  mov     PropOn, 1
                  mov     TempWord2, SW_SHOWDEFAULT
               .if PathName
                  INVOKE     WriteReadMem, 1, PropCode
               .endif
            .endif
              call     SetSize
            INVOKE     ShowWindow, hWndFunct, TempWord2
            INVOKE     ShowWindow, hWndProp, TempWord2
              call     CheckState

         .elseif eax == IDM_PREF
            .if hPref || hWndDlg
                  jmp     Ret0
            .endif
            INVOKE     CreateDialogParam, hInst, 4806, hREdit, addr SetPreferences, 0
               mov     hPref, eax
               mov     hWndDlg, eax

         .elseif eax == IDM_CODEHELPER
            .if hPref || hWndDlg
                  jmp     Ret0
            .endif
            INVOKE     CreateDialogParam, hInst, 5801, hREdit, addr SetCodeHelper, 0




               mov     hType, eax
               mov     hWndDlg, eax

         .elseif eax >= IDM_FILTERDEF && eax <= IDM_FILTER02
               sub     eax, IDM_FILTERDEF
               mov     FilterGroup, eax
               and     Run, 0
              call     CheckState
            INVOKE     ReadTheFile, addr szLoadPath

         .elseif eax == IDM_FILTERMAINT
            INVOKE     DialogBoxParam, hInst, IDD_KWMAINT, hREdit, addr KeywordMaint, 1

         .elseif eax == IDM_EDITMENU
               mov     Opt, 1
            INVOKE     CreateDialogParam, hInst, IDD_CUSTMENU, hREdit, addr MenuDlg, addr szRedit
               mov     hWndDlg, eax

         .elseif eax == IDM_EDITUSER
               mov     Opt, 20
            INVOKE     CreateDialogParam, hInst, IDD_USERNAME, hREdit, addr MenuDlg, addr szRedit
               mov     hWndDlg, eax

         .elseif eax == IDM_TOGLINES
            .if LineOn
                  and     LineOn, 0
            .else
                  mov     LineOn, 1
            .endif
            INVOKE     SendMessage, hREdit, UM_SHOWLINES, 1, 0
            INVOKE     MoveWindow, hSel, 0, 0, 0, 0, TRUE
            INVOKE     SendMessage, hREdit, UM_CHECKLINES, 0, 0
               mov     LineOn, eax

         .elseif eax == IDM_LEADING
            .if LeadingOn
                  and     LeadingOn, 0
            .else
                  mov     LeadingOn, 1
            .endif
            INVOKE     SendMessage, hREdit, UM_LEADINGZEROS, 1, 0
              call     CheckState

         .elseif eax == IDM_HILITEOFF
            INVOKE     HiliteSelection, 0

         .elseif eax == IDM_HILITE01
            INVOKE     HiliteSelection, 1

         .elseif eax == IDM_HILITE02
            INVOKE     HiliteSelection, 2

         .elseif eax == IDM_HILITE03
            INVOKE     HiliteSelection, 3

         .elseif eax == IDM_HILITE04
            INVOKE     HiliteSelection, 4

         .elseif eax == IDM_HILITECLRA
            INVOKE     SendMessage, hREdit, UM_CLEARHILIGHTS, STATE_HILITE9, 0 ;Clear all HiLites

         .elseif eax == IDM_EXPORT || eax == IDM_IMPORT
               mov     ecx, 51       ; Read from registry
            .if eax == IDM_IMPORT
                  mov     ecx, 52    ; Write to registry
            .endif
              call     ExpImpRegistory

         .elseif eax == IDM_DISPLY
            INVOKE     lstrcpy, addr WorkBuff, addr PathName
            INVOKE     lstrcpy, addr PathName, addr AsmRootDir
            INVOKE     lstrcat, addr PathName, addr szRegistryDir
            INVOKE     lstrcat, addr PathName, addr szRegAsmEdit
               mov     OA, 1
               mov     OpenFlg1, 1
              call     OpenFileA
            INVOKE     lstrcpy, addr PathName, addr WorkBuff

         .elseif eax >= IDM_ROOT && eax <= IDM_BACKUP
               sub     eax, IDM_ROOT
              imul     eax, 19
               lea     esi, rDEFr[eax]
               mov     szBuff, 0
               mov     lpcbData, sizeof szBuff
            INVOKE     RegQuerySZ, esi, addr szBuff
            .if szBuff == ' ' || !szBuff
                  jmp     Ret0
            .endif

            INVOKE     lstrcpy, addr WorkBuff, addr PathName
            INVOKE     lstrcpy, addr PathName, addr szBuff
            INVOKE     lstrcat, addr PathName, addr szAll
               mov     OA, 0
               mov     OpenFlg1, 3
              call     OpenFileA
            INVOKE     lstrcpy, addr PathName, addr WorkBuff

         .elseif eax == IDM_SETUP
            INVOKE     lstrcpy, addr WorkBuff, addr AsmRootDir
            INVOKE     lstrcat, addr WorkBuff, addr szSetup
            INVOKE     ShellExecute, hWnd, addr szOpen, addr WorkBuff, NULL, NULL, SW_SHOWNORMAL

         .elseif eax >= IDM_PROJECTDEF && eax <= IDM_PROJECT05
            .if DriveOn
                 push     eax
               INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_CLOSEALL, 0
                  pop     eax
            .endif
               and     ProjDrive, 0
               and     DriveOn, 0
              push     ProjGroup
               sub     eax, IDM_PROJECTDEF
               mov     ProjGroup, eax
               pop     eax
            .if eax == ProjGroup && ProjOn
                  jmp     Ret0
            .endif
               mov     ProjOn, 1
              call     CheckState
              call     LoadProjectTree
;;;            INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_CLOSEALL, 0

         .elseif eax == IDM_PROJECTMAINT
            .if hProjMaint || hWndDlg
                  jmp     Ret0
            .endif
            INVOKE     CreateDialogParam, hInst, IDD_GROUPS, hREdit, addr ProjectMaint, 1
               mov     hWndDlg, eax

         .elseif eax == IDM_PROJECTWITH
            .if hCreateProj || hWndDlg
                  jmp     Ret0
            .endif
            INVOKE     CreateDialogParam, hInst, IDD_CREATE, hREdit, addr CreateProject, 1
               mov     hWndDlg, eax

         .elseif eax == IDM_PROJECTWITHOUT || eax == 902 ; 902 = Addin new project
            .if hCreateProj || hWndDlg

                  jmp     Ret0
            .endif
               mov     ecx, 2
            .if eax == 902
                  mov     ecx, lParam
               INVOKE     DialogBoxParam, hInst, IDD_CREATEFOLDER, hREdit, addr CreateProject, ecx
            .else
               INVOKE     CreateDialogParam, hInst, IDD_CREATEFOLDER, hREdit, addr CreateProject, ecx
                  mov     hWndDlg, eax
            .endif

         .elseif eax == IDM_POINTER
            .if hCreateProj || hWndDlg
                  jmp     Ret0
            .endif
            INVOKE     CreateDialogParam, hInst, IDD_CREATEFOLDER, hREdit, addr CreateProject, 3
               mov     hWndDlg, eax

         .elseif eax == IDM_PROJECTDLL
            INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
            .if eax
               INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_NEW, 0
            .endif
            INVOKE     lstrcpy, addr WorkBuff, addr AsmRootDir
            INVOKE     lstrcat, addr WorkBuff, addr szAddinTemp
               mov     ecx, hBuff
            INVOKE     lstrcpy, ecx, addr WorkBuff
              call     ReadF
            .if eax
               INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, fpMem
                  mov     szRoot, 0
                  mov     lpcbData, sizeof szRoot
               INVOKE     RegQuerySZ, addr rDEFb, addr szRoot
               INVOKE     FindRep, hREdit, addr szAsmEditDir, addr AsmRootDir
               INVOKE     FindRep, hREdit, addr szHutchDir, addr szRoot
            .endif
            .if hpMem
               INVOKE     GlobalUnlock, fpMem
               INVOKE     GlobalFree, hpMem
                  mov     hpMem, 0
            .endif

         .elseif eax == IDM_COPYF
            .if hCopyFile
                  jmp     Ret0
            .endif
               lea     eax, FileName
               mov     tci.pszText, eax                    ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof FileName
            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, TabSelect, addr tci
            INVOKE     lstrcpy, addr FileName, tci.pszText
            .if byte ptr FileName == '('
               INVOKE     MessageBox, NULL, addr szError3, addr AppName, MB_OK or MB_ICONINFORMATION
                  jmp     Ret0
            .endif
            INVOKE     lstrcpy, addr WorkBuff, tci.lParam
            INVOKE     StripFileExt, addr WorkBuff
            INVOKE     StripFileName, addr WorkBuff
            INVOKE     CreateDialogParam, hInst, 4808, hREdit, addr CopyFiles, 0

         .elseif eax == IDM_SPLIT
            INVOKE     SendMessage, hREdit, UM_SHOWSPLIT, 1, 0

         .elseif eax == IDM_COMPILE
               and     SaveAs, 0
              call     SaveFile
              call     CheckState
               mov     szProj, 0
            INVOKE     SendMessage, hBEdit, WM_SETTEXT, 0, addr szNULL
            INVOKE     BuildCreate, IDM_COMPILE, addr FileName
               jmp     DoOutput

         .elseif eax == IDM_ASSEMBLE
               and     SaveAs, 0
              call     SaveFile
              call     CheckState
               mov     szProj, 0
            INVOKE     SendMessage, hBEdit, WM_SETTEXT, 0, addr szNULL
            INVOKE     BuildCreate, IDM_ASSEMBLE, addr FileName
               jmp     DoOutput

         .elseif eax == IDM_LINK
;            INVOKE     UpdateAll, SAVE_ALL
               mov     szProj, 0
            INVOKE     SendMessage, hBEdit, WM_SETTEXT, 0, addr szNULL
            INVOKE     BuildCreate, IDM_LINK, addr FileName
               jmp     DoOutput

         .elseif eax == IDM_BUILD
            INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
            .if !eax
                  jmp     Ret0
            .endif
            INVOKE     ShowWindow, hBuild, SW_SHOW
               and     SaveAs, 0
              call     SaveFile
              call     CheckState
               mov     szProj, 0
            INVOKE     SendMessage, hBEdit, WM_SETTEXT, 0, addr szNULL
            INVOKE     BuildCreate, IDM_BUILD, addr FileName
            .if eax != -1 && CloseBuild
               INVOKE     ShowWindow, hBuild, SW_HIDE
               INVOKE     SetFocus, hREdit
                  jmp     Ret0
            .endif

DoOutput:
            INVOKE     ShowWindow, hBuild, SW_SHOW
            INVOKE     SetFocus, hBEdit

         .elseif eax == IDM_RESOPEN
            .if hResParent
                  jmp     Ret0
            .endif
            .if hLibR
               INVOKE     FreeLibrary, hLibR
                  and     hLibR, 0
            .endif
               mov     SW44, 6
               mov     SW55, 1
            INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_NEW, 0
               and     SW55, 0
            INVOKE     LoadLibrary, addr LibNameR
            .if eax
                  mov     hLibR, eax
               INVOKE     IsWindowVisible, hBuild
               .if eax
                  INVOKE     ShowWindow, hBuild, SW_HIDE
               .endif
                  mov     OpenCloseOnR, 1
               INVOKE     EnableMenuItem, hMenu, IDM_RESOPEN, MF_GRAYED
               INVOKE     EnableMenuItem, hMenu, IDM_RESCLOSE, MF_ENABLED
               INVOKE     GetProcAddress, hLibR, addr FunctNameR
               .if eax
                     mov     hResParent, 44
                    push     offset hResForm
                    push     offset hResParent
                    push     offset hREdit
                    push     hWnd
                    call     eax
               .else
               .endif
            .else
               INVOKE     MessageBox, NULL, addr szError5, addr LibNameR, MB_OK or MB_ICONERROR
            .endif
               jmp     Ret0

         .elseif eax == IDM_RESCLOSE
            .if OpenCloseOnR
                  mov     SW55, 3
                  jmp     FindTab
            .endif
               jmp     Ret0

         .elseif eax == IDM_CTRLOPEN
            .if hCtrlParent
                  jmp     Ret0
            .endif
            .if hLibCB
               INVOKE     FreeLibrary, hLibCB
                  and     hLibCB, 0
            .endif

               mov     SW44, 6
               mov     SW55, 2
            INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_NEW, 0
               and     SW55, 0
            INVOKE     LoadLibrary, addr LibNameCB
            .if eax
                  mov     hLibCB, eax
               INVOKE     IsWindowVisible, hBuild
               .if eax
                  INVOKE     ShowWindow, hBuild, SW_HIDE
               .endif
                  mov     OpenCloseOnCB, 1
               INVOKE     EnableMenuItem, hMenu, IDM_CTRLOPEN, MF_GRAYED
               INVOKE     EnableMenuItem, hMenu, IDM_CTRLCLOSE, MF_ENABLED
               INVOKE     DrawMenuBar, hWnd

               INVOKE     GetProcAddress, hLibCB, addr FunctNameCB
               .if eax
                     mov     hCtrlParent, 44
                    push     offset hCtrlForm
                    push     offset hCtrlParent
                    push     offset hREdit
                    push     hWnd
                    call     eax
               .else
               .endif
            .else
               INVOKE     MessageBox, NULL, addr szError5, addr LibNameCB, MB_OK or MB_ICONERROR
            .endif
               jmp     Ret0

         .elseif eax == IDM_CTRLCLOSE
            .if OpenCloseOnCB
                  mov     SW55, 4
                  jmp     FindTab
            .endif
               jmp     Ret0

FindTab:
               lea     eax, FileName
               mov     tci.pszText, eax                ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof FileName
            INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
               mov     Cnt, eax
               mov     ID, 0
            .while (Cnt)
               INVOKE     SendMessage,  hWndTab, TCM_GETITEM, ID, addr tci
               .if SW55 == 3 && byte ptr FileName == '*' && byte ptr FileName+2 == 'R' ||\
                   SW55 == 4 && byte ptr FileName == '*' && byte ptr FileName+2 == 'C'
                  INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, ID, 0
                  INVOKE     SendMessage,  hWndTab, TCM_GETITEM, ID, addr tci
                  INVOKE     lstrcpy, addr PathName, tci.lParam
                     mov     nmhdr.code, TCN_SELCHANGE
                     lea     eax, nmhdr
                  INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
                     and     SW55, 0
                     jmp     CloseTab
               .endif
                  inc     ID
                  dec     Cnt
            .endw
               jmp     Ret0

         .elseif eax == IDM_SNIP
            .if hSnip
                  jmp     Ret0
            .endif
            INVOKE     CreateDialogParam, hInst, IDD_SNIP, hREdit, addr Snippets, 0
               mov     hSnip, eax
               mov     hWndDlg, eax

         .elseif eax == IDM_ASCII
            INVOKE     CreateDialogParam, hInst, 4807, hREdit, addr Translate, 0

         .elseif eax == IDM_WHELP
               mov     lpcbData, 250
            INVOKE     RegQuerySZ, addr rDEFh, addr szBuff
;            INVOKE     WinHelp, hwnd, addr szBuff, HELP_FINDER, 0
            INVOKE     SendMessage, hREdit, EM_GETSELTEXT, 0, addr szWork
            INVOKE     WinHelp, hWnd, addr szBuff, HELP_KEY, addr szWork

         .elseif eax == IDM_VERSION
;            INVOKE     ShellAbout, hWnd, offset AppName, offset AboutMsg, hIcon
;            INVOKE     SetFocus, hREdit
            INVOKE     CreateDialogParam, hInst, IDD_VERSION, hREdit, addr GetSysInfo, 1
               mov     hWndDlg, eax

         .elseif eax == IDM_SYSINFO
            INVOKE     CreateDialogParam, hInst, IDD_SYSINFO, hREdit, addr GetSysInfo, 2
               mov     hWndDlg, eax

         .elseif eax == IDM_WORK
            .if WorkArea
               INVOKE     SetWindowPos, hWorkArea, HWND_TOP, 0, 0, 0, 0,\
                          SWP_NOMOVE or SWP_NOSIZE or SWP_HIDEWINDOW
               INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_WORK, 17
               INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_WORK, MF_UNCHECKED or MF_BYCOMMAND
                  mov     WorkArea, 0
            .else
               INVOKE     SetWindowPos, hWorkArea, HWND_TOP, 0, 0, 0, 0,\
                          SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW
               INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_WORK, 26
               INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_WORK, MF_CHECKED or MF_BYCOMMAND
                  mov     WorkArea, 1
            .endif
            INVOKE     SetFocus, hREdit

         .elseif eax == IDM_MULT

INVOKE     RtlZeroMemory, addr ShFileOp, sizeof ShFileOp
INVOKE     lstrcpy, addr szBuff, addr szTestDel
INVOKE     lstrlen, addr szBuff
   mov     byte ptr szBuff[eax+1], 0
INVOKE     MessageBox, NULL, addr szBuff, addr AppName, MB_OK
   mov     ShFileOp.wFunc, FO_DELETE
   mov     ShFileOp.hwnd, 0            ; If 0, then no parent can task switch away
   lea     eax, szBuff
   mov     ShFileOp.pFrom, eax
   mov     ShFileOp.fFlags, FOF_SILENT or FOF_NOCONFIRMATION or FOF_ALLOWUNDO
INVOKE     SHFileOperation, addr ShFileOp
DSPValue hWnd, eax, 1, 'm'

;
;            INVOKE     lstrcpy, addr CurDir, addr AsmRootDir
;            INVOKE     lstrcat, addr CurDir, addr szAsmEdit
;            INVOKE     ShellExecute, hWnd, addr szOpen, addr CurDir, NULL, NULL, SW_SHOWNORMAL

         .elseif eax == IDM_RUN
               lea     eax, FileName
               mov     tci.pszText, eax                    ; Pointer to string containing tab text
               mov     tci.cchTextMax, sizeof FileName
            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, TabSelect, addr tci
            INVOKE     lstrcpy, addr FileName, tci.pszText
            .if byte ptr FileName == '('
               INVOKE     MessageBox, NULL, addr szError3, addr AppName, MB_OK or MB_ICONINFORMATION
                  jmp     Ret0
            .endif
            INVOKE     lstrcpy, addr WorkBuff, tci.lParam
            INVOKE     lstrlen, addr FileName
              push     eax
            INVOKE     lstrlen, addr WorkBuff
               pop     ecx
               sub     eax, ecx
               inc     eax
            INVOKE     lstrcpyn, addr WorkBuff, addr WorkBuff, eax
               mov     Run, 1    ; Run the exe
            INVOKE     GetCurrentDirectory, lengthof CurDir, addr CurDir
            INVOKE     SetCurrentDirectory, addr WorkBuff
            INVOKE     ReadTheFile, addr WorkBuff
               and     Run, 0
            INVOKE     ShellExecute, hWnd, addr szOpen, addr WorkBuff, NULL, NULL, SW_SHOWNORMAL
            INVOKE     SetCurrentDirectory, addr CurDir

         .elseif eax == IDM_DOS
            INVOKE     GetWindowsDirectory, addr WorkBuff, lengthof WorkBuff
            INVOKE     lstrcat, addr WorkBuff, addr szDos
            INVOKE     ShellExecute, hWnd, addr szOpen, addr WorkBuff, NULL, NULL, SW_SHOWNORMAL
            .if eax <= 32
               INVOKE     GetSystemDirectory, addr WorkBuff, lengthof WorkBuff
               INVOKE     lstrcat, addr WorkBuff, addr szDos
               INVOKE     ShellExecute, hWnd, addr szOpen, addr WorkBuff, NULL, NULL, SW_SHOWNORMAL
            .endif

         .elseif eax == IDM_SYNTAX
            .if SyntaxOn
                  and     SyntaxOn, 0
            .else
                  mov     SyntaxOn, 1
            .endif
               mov     ebx, TabSelect                   ; Current selected Tab
               mov     eax, SyntaxOn
               mov     hTabSeL[ebx*8+4], eax
             MOVmd     SavSyntaxOn, SyntaxOn
            INVOKE     SetValues, UM_HILIGHT, STATE_NOHILITE, 0
              call     CheckState

         .elseif eax == IDM_CLOSEBUILD
            .if CloseBuild
                  and     CloseBuild, 0
            .else
                  mov     CloseBuild, 1
            .endif
              call     CheckState

         .elseif eax == 1091 || eax == 1092           ; Filter buttons
            .if FilterOn
                  and     FilterOn, 0
            .else
                  mov     FilterOn, 1
            .endif
              call     CheckState
            .if ProjOn
               INVOKE     ReadTheFile, addr szLoadPath
            .else
               INVOKE     ReadTheFile, addr szLoadPathD
            .endif

         .elseif eax == IDM_SHIFTR
            INVOKE     GetKeyState, VK_TAB
               and     eax, 80h
              push     eax
            .if WordOn && eax
   INVOKE     ShowWindow, hParListBox, SW_HIDE
   INVOKE     ShowWindow, hWndListBox, SW_HIDE
      and     WordOn, 0
            .endif
               pop     eax
            INVOKE     ShiftLine, 1, eax

         .elseif eax == IDM_SHIFTL
            INVOKE     GetKeyState, VK_TAB
               and     eax, 80h
            INVOKE     ShiftLine, 2, eax

         .elseif eax == IDM_SHIFTTO
            INVOKE     ShiftLine, 3, 0

         .elseif eax == IDM_COMMENT
            INVOKE     ShiftLine, 4, 0

         .elseif eax == IDM_UNCOMMENT
            INVOKE     ShiftLine, 5, 0

         .elseif eax == 601
            INVOKE     GetForegroundWindow ;GetFocus
            INVOKE     GetWindow, eax, GW_CHILD
               mov     ecx, eax
            INVOKE     SendMessage, ecx, WM_CUT, 0 ,0 ;hWEdit

         .elseif eax == 602
            INVOKE     GetForegroundWindow ;GetFocus
            INVOKE     GetWindow, eax, GW_CHILD
               mov     ecx, eax
            INVOKE     SendMessage, ecx, WM_COPY, 0 ,0

         .elseif eax == 603
            INVOKE     GetForegroundWindow ;GetFocus
            INVOKE     GetWindow, eax, GW_CHILD
               mov     ecx, eax
            INVOKE     SendMessage, ecx, WM_PASTE, 0 ,0

         .elseif eax == 604
            INVOKE     GetForegroundWindow ;GetFocus
            INVOKE     GetWindow, eax, GW_CHILD
               mov     ecx, eax
            INVOKE     SendMessage, ecx, EM_SETSEL, 0, -1

         .elseif eax == 605
            INVOKE     GetForegroundWindow ;GetFocus
            INVOKE     GetWindow, eax, GW_CHILD
               mov     ecx, eax
            INVOKE     SendMessage, ecx, WM_SETTEXT, 0, offset szCR

         .endif

      .elseif wMsg == WM_MOUSEMOVE
         INVOKE     ChkSplitter, wParam, lParam

      .elseif wMsg == WM_LBUTTONUP

;---------- [Restore the cursor and call WM_SIZE] ----------
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
            and     BarType, 0
         .if hSplitBar
            INVOKE     ReleaseCapture
            INVOKE     SplitBarProc, hSplitBar, WM_COMMAND, IDCANCEL, 0
               and     hSplitBar, 0
            INVOKE     GetClientRect, hWnd, addr rect
               mov     edx, rect.bottom
               shl     edx, 16
               mov     ecx, rect.right
               mov     dx, cx
            INVOKE     SendMessage, hWnd, WM_SIZE, 0, edx
         .endif

      .elseif wMsg == WM_TIMER
         .if wParam == ID_TIMER1                    ; Is it our timer?
              call     FmTime                       ; Format and display the time
         .endif

      .elseif wMsg == WM_PAINT && hColor
         INVOKE     PostMessage, hColor, WM_COMMAND, 200, 0
            jmp     DefWin

      .elseif wMsg == WM_CLOSE
            lea     eax, FileName
            mov     tci.pszText, eax                ; Pointer to string containing tab text
            mov     tci.cchTextMax, sizeof FileName
         INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
            dec     eax
            mov     Cnt, eax
            mov     ID, 1
         .while (Cnt)
               mov     eax, ID                      ; Current selected Tab
               mov     ecx, hTabSeL[eax*8]          ; Extract REdit handle
               mov     hREdit, ecx

            INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, ID, 0
            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, ID, addr tci
            INVOKE     lstrcpy, addr FileName, tci.pszText
            INVOKE     lstrcpy, addr PathName, tci.lParam
               mov     eax, hREdit
               mov     esi, hProjArray
               xor     edx, edx
               mov     ecx, ProjCnt
            .while (ecx)
               .if dword ptr[esi+edx] == eax
;                     mov     ecx, esi
;                     add     ecx, edx
;                     add     ecx, 10 ;9
;;                  INVOKE     lstrcpy, addr szProject, ecx
;                     mov     ebx, ProjGroup
;                     mov     bl, byte ptr[esi+edx+9]
;                  INVOKE     lstrcpy, ProjNamArray[ebx*4], ecx
                     mov     ecx, 1
                  .break
               .endif
                  add     edx, 36
                  dec     ecx
            .endw
            .if ecx
                  mov     ecx, 22035
                 call     DoBookmarks
            .endif

            INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
            .if eax != 0
                  mov     nmhdr.code, TCN_SELCHANGE
                  lea     eax, nmhdr
               INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
               INVOKE     MessageBox, NULL, addr szError2, addr AppName,
                          MB_YESNOCANCEL or MB_ICONEXCLAMATION or MB_SYSTEMMODAL
               .if eax == IDYES
                     and     SaveAs, 0
                    call     SaveFile
                  .if eax == IDCANCEL
                        jmp     Ret0
                  .endif
               .elseif eax == IDCANCEL
                     jmp     Ret0
               .endif
            .endif
               inc     ID
               dec     Cnt
         .endw
           call     RegSave

         .if hResParent
            INVOKE     LoadLibrary, addr LibNameR
            .if eax
                  mov     hLibR, eax
               INVOKE     GetProcAddress, hLibR, addr FuncNameWC
               .if eax
                     mov     ecx, 1
                    push     ecx
                    call     eax
                  INVOKE     FreeLibrary, hLibR
                     and     hLibR, 0
               .else
               .endif
            .else
            .endif
         .endif

         .if hCtrlParent
            INVOKE     LoadLibrary, addr LibNameCB
            .if eax
                  mov     hLibCB, eax
               INVOKE     GetProcAddress, hLibCB, addr FuncNameWC
               .if eax
                     mov     ecx, 1
                    push     ecx
                    call     eax
                  INVOKE     FreeLibrary, hLibCB
                     and     hLibCB, 0
               .else
               .endif
            .else
            .endif
         .endif

         INVOKE     DestroyWindow, hwnd

      .elseif wMsg == WM_DESTROY
         INVOKE     HeapFree, hDefHeap, 0, hPath
         INVOKE     HeapFree, hDefHeap, 0, hBuff
         INVOKE     HeapFree, hDefHeap, 0, hProjArray
         INVOKE     HeapFree, hDefHeap, 0, hOutPut
         INVOKE     HeapFree, hDefHeap, 0, hAccelArray
         INVOKE     HeapFree, hDefHeap, 0, hHead

         INVOKE     HeapFree, hDefHeap, 0, hApiABC
         INVOKE     HeapFree, hDefHeap, 0, hApiPointer
         INVOKE     HeapFree, hDefHeap, 0, hApiCall
         INVOKE     HeapFree, hDefHeap, 0, hMsgABC
         INVOKE     HeapFree, hDefHeap, 0, hMsgPointer
         INVOKE     HeapFree, hDefHeap, 0, hMsgCall

         INVOKE     HeapFree, hDefHeap, 0, hWord01ABC
         INVOKE     HeapFree, hDefHeap, 0, hWord01Pointer
         INVOKE     HeapFree, hDefHeap, 0, hWord01Call
         INVOKE     HeapFree, hDefHeap, 0, hWord02ABC
         INVOKE     HeapFree, hDefHeap, 0, hWord02Pointer
         INVOKE     HeapFree, hDefHeap, 0, hWord02Call
         INVOKE     HeapFree, hDefHeap, 0, hWord03ABC
         INVOKE     HeapFree, hDefHeap, 0, hWord03Pointer
         INVOKE     HeapFree, hDefHeap, 0, hWord03Call

         INVOKE     GetProcessHeap
         INVOKE     HeapFree, eax, HEAP_NO_SERIALIZE, hWordMem
         INVOKE     ImageList_Destroy, hImageList
         INVOKE     ImageList_Destroy, hImageListTL
         INVOKE     ImageList_Destroy, hImageListTree
         INVOKE     DestroyIcon, hIcon
         INVOKE     DeleteObject, hBR
         INVOKE     DeleteObject, hBRD
         INVOKE     DeleteObject, hBRS
         INVOKE     DeleteObject, hBrush
         INVOKE     DeleteObject, hSavBRM
         INVOKE     DeleteObject, hBmpS
         INVOKE     DeleteObject, hTBBmp
         INVOKE     DeleteObject, hTBBmpQ
         INVOKE     DeleteObject, hTBBmpU
         INVOKE     DeleteObject, hFont
         INVOKE     DeleteObject, hFontB
         INVOKE     DeleteObject, hFontC
         INVOKE     DeleteObject, hFontI
         INVOKE     DeleteObject, hFontBI
         INVOKE     DeleteObject, hFontL
         INVOKE     DeleteObject, hFontT
         INVOKE     DeleteObject, hFontTB
         INVOKE     DeleteObject, hFontButt
         INVOKE     KillTimer, hwnd, ID_TIMER1
         INVOKE     WinHelp, hwnd, addr szHelp, HELP_QUIT, 0

         INVOKE     PostQuitMessage, NULL

      .else

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

Ret0:
         xor    eax, eax
         ret
WndProc ENDP

;===================================================
; Initialization PROCEDURE
;===================================================
Initialize PROC uses ebx esi edi
LOCAL    hReg:DWORD, FirstFlg
LOCAL    szBuffer[1024]:BYTE

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hReg, addr lpdwDisp

         mov     AsmRootDir, 0
         and     NoSetup, 0
         mov     lpcbData, sizeof AsmRootDir
      INVOKE     RegQueryValueEx, hReg, addr rDEFr, 0, addr lpType, addr AsmRootDir, addr lpcbData
      .if AsmRootDir == ' ' || !AsmRootDir
            mov     NoSetup, 1
         INVOKE     lstrcpy, addr AsmRootDir, addr RootDir
         INVOKE     lstrcpy, addr szBuffer, addr AsmRootDir
         INVOKE     lstrcat, addr szBuffer, addr szRegistryDir
         INVOKE     CreateDirectory, addr szBuffer, NULL
      .endif

      INVOKE     RegQuery, addr szAuto, addr AutoSave
      INVOKE     RegQuery, addr szCloseOn, addr CloseBuild
      INVOKE     RegQuery, addr szFilterOn, addr FilterOn
      INVOKE     RegQuery, addr szFontZoomOn, addr FontZoomOn
      INVOKE     RegQuery, addr szItalicOn, addr ItalicOn
      INVOKE     RegQuery, addr szLeadingOn, addr LeadingOn
      INVOKE     RegQuery, addr szIndentOn, addr IndentOn
      INVOKE     RegQuery, addr szAutoRefOn, addr AutoRefOn
      INVOKE     RegQuery, addr szMaxWin, addr MaxWin
      INVOKE     RegQuery, addr szNoHiLiteBW, addr NoHiLiteBW
      INVOKE     RegQuery, addr szProjWnd, addr ProjOn
      INVOKE     RegQuery, addr szDrvWnd, addr DriveOn
      INVOKE     RegQuery, addr szCodeHelper, addr CodeHelperOn

      INVOKE     RegQuery, addr szBeepOn, addr BeepOn
      INVOKE     RegQuery, addr szSpaceAfter, addr SpaceAfter
      INVOKE     RegQuery, addr szRightAlign, addr RightAlign
      INVOKE     RegQuery, addr szMinMatch, addr MinMatch
      INVOKE     RegQuery, addr szIndent, addr Indent
      INVOKE     RegQuery, addr szOutdent, addr Outdent

      INVOKE     RegQuery, addr szQuick, addr QuickOn
      INVOKE     RegQuery, addr szUser, addr UserOn
      INVOKE     RegQuery, addr szSmoothOn, addr SmoothOn
      INVOKE     RegQuery, addr szSyntaxOn, addr SyntaxOn
      INVOKE     RegQuery, addr szShiftT, addr SHIFT
      INVOKE     RegQuery, addr szSpaceN, addr SPACE
      INVOKE     RegQuery, addr szSpeed, addr Speed
      INVOKE     RegQuery, addr szTabWth, addr TAB
      INVOKE     RegQuery, addr szLineWth, addr LineWth


      INVOKE     RegQuery, addr szWheelNum, addr WheelNum
      INVOKE     RegQuery, addr szProjGroup, addr ProjGroup
      INVOKE     RegQuery, addr szFilterGroup, addr FilterGroup

         mov     lpcbData, sizeof SplitH
      INVOKE     RegQuerySZ, addr szSplitterH, addr SplitH
         mov     lpcbData, sizeof SplitV
      INVOKE     RegQuerySZ, addr szSplitterV, addr SplitV

         mov     lpcbData, sizeof FontEdit
      INVOKE     RegQuerySZ, addr szFontEdit, addr FontEdit
         mov     lpcbData, sizeof FontLine
      INVOKE     RegQuerySZ, addr szFontLine, addr FontLine
         mov     lpcbData, sizeof FontTree
      INVOKE     RegQuerySZ, addr szFontTree, addr FontTree

         mov     lpcbData, sizeof Color
      INVOKE     RegQuerySZ, addr szColor, addr Color
         mov     lpcbData, sizeof Color01
      INVOKE     RegQuerySZ, addr szColor01, addr Color01
         mov     lpcbData, sizeof CustClrs
      INVOKE     RegQuerySZ, addr szCustClrs, addr CustClrs
      .if dword ptr CustClrs == 0 && dword ptr CustClrs[4] == 0
            lea     esi, DefCustColor
            lea     edi, CustClrs
            mov     ecx, 16
         .while (ecx)
               mov     eax, [esi]
               mov     [edi], eax
               add     esi, 4
               add     edi, 4
               dec     ecx
         .endw
      .endif

;         mov     lpcbData, sizeof szProject
;      INVOKE     RegQuerySZ, addr szProjN, addr szProject
;      .if !szProject
;         INVOKE     lstrcpy, addr szProject, addr szPgm02
;      .endif

         xor     ebx, ebx
         mov     esi, 6
      .while (esi)
            mov     lpcbData, sizeof szProject
         INVOKE     RegQuerySZ, ProjNArray[ebx*4], ProjNamArray[ebx*4]
            inc     ebx
            dec     esi
      .endw
      .if !szProject
         INVOKE     lstrcpy, addr szProject, addr szPgm02
      .endif

         mov     lpcbData, sizeof szLoadPathD
      INVOKE     RegQuerySZ, addr DrivePath, addr szLoadPathD
      .if !szLoadPathD || byte ptr szLoadPathD+1 != ':' || byte ptr szLoadPathD+2 != '\'
         INVOKE     lstrcpy, addr szLoadPathD, addr RootDir
      .endif

         mov     lpcbData, sizeof Userkeyw01
      INVOKE     RegQuerySZ, addr szKeywU01, addr Userkeyw01
;      .if !Userkeyw01
;         INVOKE     lstrcpy, addr Userkeyw01, addr keyw13
;      .endif
         mov     lpcbData, sizeof Userkeyw02
      INVOKE     RegQuerySZ, addr szKeywU02, addr Userkeyw02
;      .if !Userkeyw02
;         INVOKE     lstrcpy, addr Userkeyw02, addr keyw14
;      .endif

         mov     lpcbData, sizeof UserFilt01
      INVOKE     RegQuerySZ, addr szFiltU01, addr UserFilt01
      .if !UserFilt01
         INVOKE     lstrcpy, addr UserFilt01, addr Filter01
      .endif
         mov     lpcbData, sizeof UserFilt02
      INVOKE     RegQuerySZ, addr szFiltU02, addr UserFilt02
      .if !UserFilt02
         INVOKE     lstrcpy, addr UserFilt02, addr Filter02
      .endif

       MOVmd     SavSyntaxOn, SyntaxOn
      INVOKE     RegCloseKey, hReg

         xor    eax, eax
         ret
Initialize ENDP

;===================================================
; ScrollDataDlg Line Number Box Data PROCEDURE
;===================================================
ScrollDataDlg PROC  hdlg:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    hDC:DWORD
LOCAL    Clear[20]:BYTE

         cmp     wMsg, WM_INITDIALOG   ; If message is INITDIALOG then
         jne     NotInit               ; check wMsg
       MOVmd     hScrollData, hdlg
         jmp     DlgDone

NotInit:
         cmp     wMsg, WM_CTLCOLORDLG
          je     ColorDlg
         cmp     wMsg, WM_SETFOCUS
          je     OutPut
         cmp     wMsg, WM_MOUSEMOVE
          je     OutPut
         cmp     wMsg, WM_PAINT
          je     OutPut
         cmp     wMsg, WM_COMMAND      ; Is message a WM_COMMAND?
         mov     eax, wParam           ; Otherwise, see if it's OK or CANCEL
         cmp     eax, IDCANCEL         ; that was pressed
          je     CancleIt              ; and if not either of these
         jmp     DlgDone

ColorDlg:
      .if hBR
         INVOKE     DeleteObject, hBR
      .endif
;      INVOKE     GetSysColor, COLOR_INFOBK
      INVOKE     CreateSolidBrush, Color.EditBC
         mov     hBR, eax
         ret
 
OutPut:
      INVOKE     GetDC, hdlg
         mov     hDC, eax
      INVOKE     SelectObject, hDC, hFontT
      INVOKE     GetClientRect, hdlg, addr rect
         mov     rect.left, 2
         mov     rect.top, 1
         mov     rect.bottom, 16

      INVOKE     FillBuffer, addr Clear, sizeof Clear, ' ', 1
      INVOKE     SetBkColor, hDC, Color.EditBC
      INVOKE     SetTextColor, hDC, 0 ;TextC
      INVOKE     DrawText, hDC, addr Clear, 20, addr rect, DT_LEFT or DT_SINGLELINE
      INVOKE     DrawText, hDC, addr szLine, -1, addr rect, DT_LEFT or DT_SINGLELINE
      INVOKE     ReleaseDC, hdlg, hDC
         jmp     DlgDone

CancleIt:
      .if hBR
         INVOKE     DeleteObject, hBR
           and      hBR, 0
      .endif
         and     hScrollData, 0
      INVOKE     EndDialog, hdlg, wParam
         mov     eax, TRUE             ; Return
         jmp     DlgRet                ; with TRUE

DlgDone:
         mov     eax, FALSE            ; Return with FALSE

DlgRet:
         ret                           ; Return
ScrollDataDlg ENDP

;===================================================
; SubClass the Edit control procedure
;===================================================
RichEditProc PROC hwnd:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    cre:CHARRANGE
LOCAL    pt:POINT
LOCAL    szBuff[256]:BYTE

      .if wMsg == WM_RBUTTONDOWN && wParam == MK_RBUTTON
            jmp     PopUp

      .elseif wMsg == WM_RBUTTONUP

      .elseif wMsg == WM_SYSKEYDOWN
;            jmp     ThatsAll

;      .elseif wMsg == WM_LBUTTONDBLCLK
;         INVOKE     MoveWindow, hAPIPopup, 0, 0, 0, 0, TRUE

      .elseif wMsg == WM_LBUTTONDOWN
         INVOKE     SendMessage, hwnd, EM_LINEINDEX, -1, 0
         INVOKE     SendMessage, hwnd, EM_EXLINEFROMCHAR, 0, eax
            mov     LineNum, eax

;            mov     eax, StartPos
         .if ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm' ;&& SPos > eax
            INVOKE     WriteReadMem, 4, 8
            .if WorkBuff
               INVOKE     lstrcat, addr WorkBuff, addr szPROC
            .endif
            INVOKE     SendMessage, hWndStat, SB_SETTEXT, 2, addr WorkBuff
         .else
            INVOKE     SendMessage, hWndStat, SB_SETTEXT, 2, addr szNULL
         .endif

      .elseif wMsg == WM_LBUTTONUP

      .elseif wMsg == WM_KEYDOWN
         INVOKE     GetKeyState, VK_SHIFT
            and     eax, 80h
            mov     ShiftOn, eax
         INVOKE     GetFocus
           push     eax
         INVOKE     IsWindowVisible, hWndListBox
            pop     ecx
         .if CodeHelperOn && ecx != hWndListBox && eax && wParam != VK_DELETE
;            INVOKE     SendMessage, hWndListBox, LB_SETCURSEL, 0, 0
            INVOKE     CodeHelper, wMsg, wParam, lParam
               mov     eax, -1
               ret
         .endif

      .elseif wMsg == WM_CHAR
         .if CodeHelperOn
            INVOKE     CodeHelper, wMsg, wParam, lParam
;            INVOKE     GetProcAddress, hCodeHelper, addr FuncNameTA
;            .if !eax
;                  jmp     ThatsAll
;            .endif
;              push     lParam
;              push     wParam
;              push     wMsg
;              push     hREdit
;              call     eax
;               jmp     ThatsAll
         .endif
         .if wParam == 0dh
            INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cre
               mov     eax, cre.cpMin
            .if eax != cre.cpMax && hFRDlg
               INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_FINDNEXT, 0
                  mov     eax, -1
                  ret
            .endif
         .endif

      .elseif wMsg == WM_KEYUP
         .if CodeHelperOn
            INVOKE     CodeHelper, wMsg, wParam, lParam
;            INVOKE     GetProcAddress, hCodeHelper, addr FuncNameTA
;            .if !eax
;                  jmp     ThatsAll
;            .endif
;              push     lParam
;              push     wParam
;              push     wMsg
;              push     hREdit
;              call     eax
;               jmp     ThatsAll
         .endif

      .elseif wMsg == WM_MOUSEWHEEL && (wParam & MK_CONTROL)
         .if !FontZoomOn
               xor     eax, eax 
               ret
         .endif
            mov     eax, wParam
            shr     eax, 16
         .if eax < 7fffh
               inc     FontEdit.lfHeight
            .if FontEdit.lfHeight > -6
                  mov     FontEdit.lfHeight, -6
            .endif

         .else
               dec     FontEdit.lfHeight
            .if FontEdit.lfHeight < -40
                  mov     FontEdit.lfHeight, -40
            .endif

         .endif

         INVOKE     DeleteObject, hFont
         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFont, eax     ; Edit font
            mov     Font.hFont, eax
         INVOKE     SendMessage, hREdit, UM_SETFONTS, 0, addr Font
            xor     eax, eax 
            ret

;---------- [Scroll line box] ----------
      .elseif wMsg == WM_VSCROLL
            INVOKE     CallWindowProc, lpRichEdit, hwnd, wMsg, wParam, lParam
              push     eax
            INVOKE     SendMessage, hREdit, EM_GETFIRSTVISIBLELINE, 0, 0
               inc     eax
               mov     ecx, eax
               mov     eax, wParam
               and     eax, 0000ffffh
            .if eax != SB_ENDSCROLL
               INVOKE     BaseAscii, ecx, addr SLNum, 1, 10, 0, 1, 1
               .if !hScrollData
                  INVOKE     CreateDialogParam, hInst, IDD_SCROLLDATA, hWnd, offset ScrollDataDlg, 0
               .endif
               INVOKE     GetCursorPos, addr pt
               INVOKE     ScreenToClient, hWnd, addr pt
               INVOKE     GetWindowRect, hwnd, addr rect
                  mov     eax, rect.right
                  sub     eax, rect.left
                  add     eax, rect.left
                  sub     eax, 80
                  mov     pt.x, eax
                  mov     eax, rect.top
                  sub     eax, 30
                  add     pt.y, eax

               INVOKE     MoveWindow, hScrollData, pt.x, pt.y, 62, 15, 1
               INVOKE     SendMessage, hScrollData, WM_MOUSEMOVE, 0, 0

            .else
               .if hScrollData
                  INVOKE     ScrollDataDlg, hScrollData, WM_COMMAND, IDCANCEL, 0
                  INVOKE     SetFocus, hREdit
               .endif
            .endif
               pop     eax
               ret
      .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, 0 ;10 
         add     ecx, 0 ;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

;===================================================
; WorkArea PROCEDURE
;===================================================
WorkAreaProc PROC  hwnd:DWORD, wMsg, wParam, lParam

      .if wMsg == WM_SIZE
            mov     edx, hwnd
            mov     eax, lParam
            mov     ecx, eax
            shr     ecx, 16
            and     eax, 0ffffh

         .if edx == hWorkArea
            INVOKE     MoveWindow, hWEdit, 0, 0, eax, ecx, TRUE
         .elseif edx == hWorkAreaS
            INVOKE     MoveWindow, hWEditS, 0, 0, eax, ecx, TRUE
         .endif

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
           cwde                        ; Only low word contains command

      .else
         INVOKE     DefWindowProc, hwnd, wMsg, wParam, lParam
            ret
      .endif

         mov     eax, FALSE            ; Return with FALSE
         ret

WorkAreaProc ENDP

;===================================================
; Work Edit PROCEDURE - Work Edit is a SUB CLASS
;===================================================
WorkEditProc PROC  uses ebx hwnd, wMsg, wParam, lParam
LOCAL    rect:RECT

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

PopUp:
      INVOKE     GetWindowRect, hwnd, addr rect  ;hWorkArea
         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, 0 ;10 
         add     ecx, 0 ;20
      INVOKE     TrackPopupMenu, hWMenu, TPM_LEFTALIGN or TPM_LEFTBUTTON, ebx, ecx, 0, hWnd, addr rect
        jmp      ThatsAll

ThatsAll:
      INVOKE     CallWindowProc, lpWorkEdit, hwnd, wMsg, wParam, lParam

         ret
WorkEditProc ENDP

;===================================================
; Get the xBuild and yBuild for the build window PROCEDURE
;===================================================
GetXY PROC
LOCAL    rect:RECT
LOCAL    pt:POINT

      INVOKE     GetClientRect, hWnd, addr rect
        push     rect.left
         pop     pt.x
        push     rect.top
         pop     pt.y
      INVOKE     ClientToScreen, hWnd, addr pt
         mov     eax, rect.right
         sub     eax, rect.left
        push     eax
         mov     ebx, 332
         sub     ebx, 0
         pop     eax
         sub     eax, ebx
         add     eax, pt.x
         sub     eax, 17
         mov     ecx, 282
         sub     ecx, 0
         mov     edx, pt.y
         add     edx, 25
         mov     xBuild, eax
         mov     yBuild, edx

         ret
GetXY ENDP

;===================================================
; Resize the windows PROCEDURE
;===================================================
SetSize PROC
LOCAL    rect:RECT

         mov     eax, hREdit
         mov     Hand.hREdit, eax
      INVOKE     SendMessage, hREdit, UM_SETHANDLES, 0, addr Hand

      INVOKE     LockWindowUpdate, hWnd           ; Lock parent to avoid flicker
      INVOKE     GetClientRect, hWnd, addr rect
         mov     edx, rect.bottom
         shl     edx, 16
         mov     ecx, rect.right
         mov     dx, cx
      INVOKE     SendMessage, hWnd, WM_SIZE, 0, edx
      INVOKE     LockWindowUpdate, 0              ; Unock parent

         ret
SetSize ENDP

;===================================================
; Create Tab Control PROCEDURE
;===================================================
CreateTab PROC hwnd:DWORD

      INVOKE     HeapAlloc, hDefHeap, 0, 28160
         mov     hPath, eax

;TCS_FLATBUTTONS or TCS_SCROLLOPPOSITE
      INVOKE     CreateWindowEx, 0, addr TabClass, 0,\
                 WS_CHILD or WS_VISIBLE or TCS_BOTTOM or TCS_BUTTONS or\
                 TCS_RAGGEDRIGHT or TCS_OWNERDRAWFIXED or TCS_FOCUSNEVER or\
                 WS_CLIPSIBLINGS or WS_CLIPCHILDREN,\
                 0, 0, 0, 0, hwnd, 702, hInst, 0
         mov     hWndTab, eax

;      INVOKE     SendMessage, hWndTab, TCM_SETEXTENDEDSTYLE, TCS_EX_FLATSEPARATORS, 0

;---------- [Set the Tab Control Item structure] ----------
         mov     tci.imask, TCIF_TEXT or TCIF_PARAM   ; Text & Param
         mov     tci.lpReserved1, 0                ; Reserved
         mov     tci.lpReserved2, 0                ; Reserved
         mov     tci.iImage, -1                    ; Index to tab control's image 

         mov     TabSelect, 0
        call     CreateWinT
      INVOKE     ShowWindow, hREdit, SW_SHOWDEFAULT

         ret
CreateTab ENDP

;===================================================
; Setup for a new Tab PROCEDURE
;===================================================
NewTab PROC

      INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
      .if PathIDs > 109 || eax >= 32
; Do Message Max number reached
            ret
      .endif
         mov     eax, TabSelect                   ; Current selected Tab
         mov     ecx, hTabSeL[eax*8]             ; Extract current Edit handle
      INVOKE     ShowWindow, ecx, SW_HIDE         ; Hide its window

      .if hResParent && hResForm
         INVOKE     ShowWindow, hResForm, SW_HIDE
      .endif

      .if hCtrlParent && hCtrlForm
         INVOKE     ShowWindow, hCtrlForm, SW_HIDE
      .endif

      INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
         mov     TabSelect, eax
;DSPValue hWnd, eax, 1, 'm'
        call     CreateWinT
      INVOKE     ShowWindow, hREdit, SW_SHOWDEFAULT

         ret
NewTab ENDP

;===================================================
; Create the Tab and Edit Control PROCEDURE
;===================================================
CreateWinT PROC
LOCAL    SaveHandle:DWORD

         mov     eax, PathIDs                             ; Path ID
        imul     eax, 256
         mov     ecx, hPath
         add     ecx, eax
         mov     tci.lParam, ecx                          ; Path buffer address
         inc     PathIDs

      .if PathIDs == 1 || NewTabWnd                       ; First time Tab or new blank Window
         .if PathIDs == 1
               mov     tci.pszText, offset szLines
               mov     tci.cchTextMax, sizeof szLines
            INVOKE     lstrcpy, tci.lParam, addr szLines
            INVOKE     SendMessage, hWndTab, TCM_INSERTITEM, TabSelect, addr tci
               inc     TabSelect
         .endif
            add     byte ptr szUntitled+10, 1
            mov     tci.pszText, offset szUntitled     ; Pointer to string containing tab text
            mov     tci.cchTextMax, sizeof szUntitled  ; Size of szUntitled
         INVOKE     lstrcpy, tci.lParam, addr szUntitled
      .else
            mov     tci.pszText, offset FileName
            mov     tci.cchTextMax, sizeof FileName
         INVOKE     lstrcpy, tci.lParam, addr PathName
      .endif
      INVOKE     SendMessage, hWndTab, TCM_INSERTITEM, TabSelect, addr tci

;WS_EX_STATICEDGE WS_EX_CLIENTEDGE or WS_BORDER
      INVOKE     CreateWindowEx, WS_EX_STATICEDGE, addr RichEdit, NULL,\
                 WS_CHILD or WS_VISIBLE or ES_MULTILINE or WS_BORDER or\
                 ES_NOHIDESEL or ES_SAVESEL or WS_CLIPSIBLINGS or WS_CLIPCHILDREN,\
                 0, 0, 0, 0, hWndTab, 4444, hInst, NULL
         mov     hREdit, eax
         mov     eax, TabSelect
         mov     ecx, hREdit
         mov     hTabSeL[eax*8], ecx                 ; Save Edits handle

;      INVOKE     SetWindowLong, hREdit, GWL_WNDPROC, RichEditProc
INVOKE     SendMessage, hREdit, UM_SUBCLASSCTRL, 0, RichEditProc
         mov     lpRichEdit, eax
;      INVOKE     SendMessage, hREdit, EM_SETOPTIONS, ECOOP_XOR, ECO_SELECTIONBAR
      INVOKE     SendMessage, hREdit, EM_EXLIMITTEXT, 0, 8000000

      INVOKE     SendMessage, hREdit, UM_HTMLCOLOR, 0, addr Color01+64
      INVOKE     SendMessage, hREdit, UM_SETFONTS, 0, addr Font
      INVOKE     SendMessage, hREdit, UM_SETCOLORS, 0, addr Color
      INVOKE     SendMessage, hREdit, UM_TABWIDTH, TAB, 0
      INVOKE     SendMessage, hREdit, UM_ITALIC, ItalicOn, 0
      .if !SyntaxOn
         INVOKE     SendMessage, hREdit, UM_HILIGHT, STATE_NOHILITE, 0
      .endif
      .if NoHiLiteBW
         INVOKE     SendMessage, hREdit, UM_BLACKWHITE, STATE_BLACKWHITE, 0
      .endif

      INVOKE     SetFocus, hREdit
;DSPValue hWnd, TabSelect, 1, 't'
;DSPValue hWnd, hREdit, 1, 'm'

;      INVOKE     SendMessage, hREdit, EM_SETEVENTMASK, 0, ENM_CHANGE or ENM_SELCHANGE or ENM_MOUSEEVENTS or\
;                 ENM_KEYEVENTS or ENM_DROPFILES ;or ENM_REQUESTRESIZE

;      INVOKE     DragAcceptFiles, hREdit, TRUE
;      INVOKE     WriteReadMem, 0, PropCode ;New

      INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, TabSelect, 0

         ret
CreateWinT ENDP

;===============================================================
; Set title PROCEDURE
;===============================================================
SetTitle PROC
LOCAL    szBuff[256]:BYTE

      INVOKE     lstrcpy, addr szBuff, addr AppName
      .if PathName
         INVOKE     lstrcat, addr szBuff, addr PathName
      .else
         INVOKE     lstrcat, addr szBuff, addr szUntitled
      .endif
      INVOKE     SetWindowText, hWnd, addr szBuff
         ret

SetTitle ENDP

;===============================================================
; Open file PROCEDURE
;===============================================================
OpenFileA PROC uses ebx esi edi
LOCAL    ofn:OPENFILENAME
LOCAL    EditS:EDITSTREAM
LOCAL    hFile:DWORD, ID, Cnt, FileType
LOCAL    szFileName[64]:BYTE, SavPath[256]:BYTE

         and     FileType, 0

;---------- [Zero out the structures] ----------
      INVOKE     RtlZeroMemory, addr ofn, sizeof ofn
         cmp     OA, 1
          je     OpenAssoc
      .if OpenFlg1 != 3
         mov     byte ptr PathName, 0
      .endif
;---------- [Set the OPENFILENAME attributes] ----------
         mov     ofn.lStructSize, sizeof ofn
         mov     eax, hWnd
         mov     ofn.hwndOwner, eax
         mov     eax, hInst
         mov     ofn.hInstance, eax
         mov     ofn.lpstrFilter, offset szFilter
         mov     ofn.lpstrFile, offset PathName
         mov     ofn.nMaxFile, lengthof PathName
         mov     ofn.lpstrFileTitle, offset FileName
         mov     ofn.nMaxFileTitle, lengthof FileName
         mov     ofn.lpstrTitle, offset szOpenTitle
         mov     ofn.Flags, OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST
      INVOKE     GetOpenFileName, addr ofn
      .if !eax                       ; Cancel'ed or error occurred
            mov     eax, -1
            jmp     OpenError ;GetOut
      .endif
      .if OpenFlg1 == 9              ; Open Hex
            mov     FileType, 2
            jmp     ChkTab
      .endif

OpenAssoc:
      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?
         jne     opcrok

      INVOKE     CreateFile, addr PathName,\
                 GENERIC_READ, FILE_SHARE_READ,\
                 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
         cmp     eax, -1             ; Error?
         jne     opcrok

operr:
; Do message
;---------- [Delete the list file name
      .if OpenFlg1 == 1                   ; From menu file list
         INVOKE     ProcessMRUFiles, hWnd, 1, MenuCnt, addr PathName, addr szRedit, 0
         INVOKE     lstrcpy, addr PathName, addr WorkBuff
      .endif
         jmp     EndOpen

opcrok:
         mov     hFile, eax
         mov     EditS.dwCookie, eax
         mov     EditS.dwError, 0
         mov     EditS.pfnCallback, offset EditStreamRead
      INVOKE     GetFileTime, hFile, addr FTimeOC, 0, addr FTimeOM

      .if OpenFlg1 == 1  ; From MRU, Registry, Asm Drop, need the filename for print
           call     GetFileName
      .endif



ChkTab:
      INVOKE     LockWindowUpdate, hWnd           ; Lock parent to avoid flicker
;DSPValue hWnd, TabSelect, 1, 'm'
;___________________________________________________________________________________________
         lea     eax, szFileName
         mov     tci.pszText, eax                 ; Pointer to string containing tab text
         mov     tci.cchTextMax, sizeof szFileName
      INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
         mov     Cnt, eax
      INVOKE     SendMessage,  hWndTab, TCM_GETITEM, TabSelect, addr tci

         mov     eax, TabSelect                   ; Tab ID
         mov     ecx, hTabSeL[eax*8]              ; Extract Tabs handle
         mov     hREdit, ecx

      INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
      .if byte ptr szFileName == '(' && eax < 3 && Cnt < 3
            jmp     UseExsisting                  ; From new projects
      .endif

      .if byte ptr szFileName != '(' || byte ptr szFileName == '(' && Cnt > 1 ||\
          byte ptr szFileName == '(' && eax

;---------- [Check to see if file is already opened] ----------
            mov     ID, 1 ;0
            dec     Cnt
         .while (Cnt)
            INVOKE     SendMessage,  hWndTab, TCM_GETITEM, ID, addr tci

            INVOKE     lstrcpyn, addr szFileName, tci.lParam, 4

            INVOKE     lstrcmpi, tci.lParam, addr PathName
            .if !eax                              ; Files already opened
               .if OpenFlg1 == 2                  ; Undo tabstop convert
                     jmp     Restore
               .endif
               INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, ID, 0
                  mov     nmhdr.code, TCN_SELCHANGE
                  lea     eax, nmhdr
               INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
               INVOKE     CloseHandle, hFile
                  jmp     EndOpen

            .elseif byte ptr szFileName == '('
                  mov     eax, ID                   ; Tab ID
                  mov     ecx, hTabSeL[eax*8]             ; Extract Tabs handle
               INVOKE     SendMessage, ecx, WM_GETTEXTLENGTH, 0, 0
               .if !eax
                   MOVmd     TabSelect, ID
                     mov     tci.pszText, offset FileName     ; Pointer to string containing tab text
                     mov     tci.cchTextMax, 0
                  INVOKE     lstrcpy, tci.lParam, addr PathName
                  INVOKE     SendMessage, hWndTab, TCM_SETITEM, TabSelect, addr tci
                  INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, TabSelect, 0
                     mov     nmhdr.code, TCN_SELCHANGE
                     lea     eax, nmhdr
                  INVOKE     SendMessage, hWnd, WM_NOTIFY, 0, eax
                     jmp     NewWin
               .endif
            .endif
               inc     ID
               dec     Cnt
         .endw

;---------- [Create a new Tab] ----------
           call     NewTab
         INVOKE     SendMessage, hWndTab, TCM_SETCURSEL, TabSelect, 0
            jmp     NewWin
      .endif

UseExsisting:                                     ; (Untitled)
;---------- [First file] ----------
         mov     tci.pszText, offset FileName     ; Pointer to string containing tab text
         mov     tci.cchTextMax, 0
      INVOKE     lstrcpy, tci.lParam, addr PathName
      INVOKE     SendMessage, hWndTab, TCM_SETITEM, TabSelect, addr tci

NewWin:
        call     LoadOpenItems

Restore:
      .if OpenFlg1 == 9  ; Hex
           call     SetTitle
            jmp     EndOpen
      .endif
;DSPValue hWnd, hREdit, 1, 'm'

      INVOKE     SendMessage, hREdit, EM_STREAMIN, SF_TEXT, addr EditS
         mov     BytesRead, eax

      INVOKE     CloseHandle, hFile
        call     SetTitle
      INVOKE     SendMessage,  hREdit, EM_SETMODIFY, FALSE, 0

.if OpenFlg1 == 2
   INVOKE     LockWindowUpdate, 0
      jmp     FromRestore
.endif

        call     GetExtent

EndOpen:
      INVOKE     LockWindowUpdate, 0
        call     SetSize

NoSetSize:
      .if ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm' ||\
          ExtType == '.' && ExtType + 1 == 'r' && ExtType + 2 == 'c' ||\
          ExtType == 'i' && ExtType + 1 == 'n' && ExtType + 2 == 'c' ||\
          ExtType == 'r' && ExtType + 1 == 'c'

;---------- [Extract or load Project structure array] ----------
            mov     eax, hREdit
            mov     esi, hProjArray
            xor     edi, edi
            mov     ecx, ProjCnt
         .while (ecx)
            .if dword ptr[esi+edi] == eax
                  mov     ecx, esi
                  add     ecx, edi
                  add     ecx, 10 ;9
;               INVOKE     lstrcpy, addr szProject, ecx
                  mov     ebx, ProjGroup
               INVOKE     lstrcpy, ProjNamArray[ebx*4], ecx
                  mov     ecx, 1
               .break
            .endif
               add     edi, 36
               dec     ecx
         .endw
         .if !ecx
              call     GetFolderName  ; 08-11-2003
;            INVOKE     lstrcmpi, addr szProject, addr szFolder  ; 08-11-2003
               mov     ebx, ProjGroup
            INVOKE     lstrcmpi, ProjNamArray[ebx*4], addr szFolder  ; 08-11-2003
            .if eax != 0  ; 08-11-2003
                  and     hItem, 0  ; 08-11-2003
            .endif  ; 08-11-2003
;            INVOKE     lstrcpy, addr szProject, addr szFolder  ; 08-11-2003
            INVOKE     lstrcpy, ProjNamArray[ebx*4], addr szFolder  ; 08-11-2003
               mov     eax, hREdit
               mov     edi, ProjCnt
              imul     edi, 36                    ; Project structure size
               mov     dword ptr[esi+edi], eax
               inc     ProjCnt
               mov     eax, hItem
.if !OA
;               xor     eax, eax  ; 08-11-2003
;               mov     szProject, 0  ; 08-11-2003
.endif
               mov     ecx, ProjGroup
               mov     dword ptr[esi+edi+4], eax ;0
               mov     byte ptr[esi+edi+8], 1 ;0
               mov     byte ptr[esi+edi+9], cl
            .if OA == 1 ;&& w9 == 0
                  mov     dword ptr[esi+edi+4], eax
                  mov     byte ptr[esi+edi+8], 1
            .endif
               mov     ecx, esi
               add     ecx, edi
               add     ecx, 10 ;9
;            INVOKE     lstrcpy, ecx, addr szProject
               mov     ebx, ProjGroup
            INVOKE     lstrcpy, ecx, ProjNamArray[ebx*4]
         .endif
      .endif

      .if OpenFlg1 == 9  ; Hex
            jmp     GetOut
      .endif

FromRestore:
      INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
         mov     BytesRead, eax
      INVOKE     BaseAscii, BytesRead, addr Fsize, 0, 10, 1, 0, 1
      INVOKE     lstrcpy, addr szFileSize, addr szSize
      INVOKE     lstrcat, addr szFileSize, addr Fsize
      INVOKE     SendMessage, hWndStat, SB_SETTEXT, 0, addr szFileSize
;      INVOKE     SendMessage, hWndStat, SB_SETTEXT, 2, addr szProject
         mov     ebx, ProjGroup
      INVOKE     SendMessage, hWndStat, SB_SETTEXT, 2, ProjNamArray[ebx*4]
      INVOKE     SetFocus, hREdit

      INVOKE     SendMessage, hREdit, UM_GETLONGESTLINE, 0, 0
      .if OpenFlg1 == 2                                 ; 2 = From restore tabs
            jmp     GetOut
      .endif
      .if OpenFlg1 != 6                                 ; 6 = From assmb
         INVOKE     ProcessMRUFiles, hWnd, 0, MenuCnt, addr PathName, addr szRedit, 0
      .endif

      INVOKE     IsWindowVisible, hBuild
      .if eax
         INVOKE     ShowWindow, hBuild, SW_HIDE
      .endif

      INVOKE     SendMessage, hREdit, UM_GETUNICODE, 0, 0
      .if eax
            mov     FileType, 8
            jmp     GetOut
      .endif

      .if ExtType == 'h' && ExtType + 1 == 't' && ExtType + 2 == 'm'
            mov     FileType, 3
      .endif
      .if ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm' ||\
          ExtType == '.' && ExtType + 1 == 'r' && ExtType + 2 == 'c' ||\
          ExtType == 'i' && ExtType + 1 == 'n' && ExtType + 2 == 'c' ||\
          ExtType == 'r' && ExtType + 1 == 'c'
            mov     FileType, 1
      .else
            jmp     GetOut
      .endif
         mov     ecx, 22036
        call     DoBookmarks

      .if BytesRead && AutoSave
         INVOKE     lstrcpy, addr SavPath, addr PathName
         INVOKE     lstrlen, addr PathName
           push     eax
         INVOKE     lstrlen, addr FileName
            pop     ecx
            sub     ecx, eax
            inc     ecx
         INVOKE     lstrcpyn, addr PathName, addr PathName, ecx
         INVOKE     lstrcat, addr PathName, addr szBackUp
         INVOKE     CreateDirectory, addr PathName, NULL
         INVOKE     lstrcat, addr PathName, addr FileName
            mov     SaveFlg1, 44
           call     SaveFile
         INVOKE     lstrcpy, addr PathName, addr SavPath
      .endif

GetOut:
        push     eax
         mov     ebx, TabSelect                   ; Current selected Tab
         mov     ecx, FileType
         mov     hTabSeL[ebx*8+4], ecx

      .if SavSyntaxOn
         .if SyntaxOn && FileType != 1 || !SyntaxOn && FileType == 1
            .if SyntaxOn
                  and     SyntaxOn, 0

            .else
                  mov     SyntaxOn, 1
            .endif
            INVOKE     SetValues, UM_HILIGHT, STATE_NOHILITE, 0
         .endif
      .endif
      .if FileType == 3
         INVOKE     SendMessage, hREdit, UM_HTML, 1, 0
;         INVOKE     SetValues, UM_HILIGHT, STATE_NOHILITE, 0
;            mov     SyntaxOn, 1
      .endif
      .if PropOn
         INVOKE     WriteReadMem, 1, PropCode
      .endif
      INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
         mov     LineCount, eax
        call     CheckState
         pop     eax

OpenError:
         and     OA, 0
         and     OpenFlg1, 0
         ret

OpenFileA  ENDP

;===============================================================
; Edit Stream Read Callback PROCEDURE
;===============================================================
EditStreamRead PROC dwCookie:DWORD, pbBuff, cb, pcb

      INVOKE     ReadFile, dwCookie, pbBuff, cb, pcb, 0
         mov     eax, 0              ; Return 0
         ret

EditStreamRead ENDP

;===============================================================
; Save file PROCEDURE
;===============================================================
SaveFile PROC
LOCAL    ofn:OPENFILENAME
LOCAL    EditS:EDITSTREAM
LOCAL    hFile:DWORD, Incr, Cnt, SavCnt, hTemp, FileCnt
LOCAL    SavPath[256]:BYTE, NewPath[256]:BYTE, CntF:BYTE

      INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
      .if !eax
            jmp     EndSave
      .endif
      .if SaveFlg1 == 44                 ; From OpenFile AutoSave
            and     FileCnt, 0
            and     hFile, 0
         INVOKE     lstrcpy, addr SavPath, addr PathName
         INVOKE     lstrlen, addr PathName
            sub     eax, 2
         .if ExtType == 'r' && ExtType+1 == 'c'
         .else
               dec     eax
         .endif
         INVOKE     lstrcpyn, addr PathName, addr SavPath, eax
            mov     byte ptr szIncr+1, '0'
         INVOKE     lstrcat, addr PathName, addr szIncr
         INVOKE     lstrcat, addr PathName, addr szPer
         INVOKE     lstrcat, addr PathName, addr ExtType
            jmp     crFile
      .endif

      .if !SaveAs
            jmp     crFile
      .endif

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

;---------- [Set the OPENFILENAME attributes] ----------
         mov     ofn.lStructSize, sizeof ofn
         mov     eax, hWnd
         mov     ofn.hwndOwner, eax
         mov     eax, hInst
         mov     ofn.hInstance, eax
         mov     ofn.lpstrFilter, offset szFilter
         mov     ofn.lpstrFile, offset PathName
         mov     ofn.nMaxFile, lengthof PathName
         mov     ofn.lpstrFileTitle, offset FileName
         mov     ofn.nMaxFileTitle, lengthof FileName
         mov     ofn.lpstrTitle, offset szSaveTitle
         mov     ofn.Flags, OFN_OVERWRITEPROMPT or OFN_CREATEPROMPT or\
                 OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST
      INVOKE     GetSaveFileName, addr ofn
      .if !eax                       ; Cancel'ed or error occurred
            mov     eax, IDCANCEL
            jmp     EndSave
      .endif
      .if SaveFlg1 == 5              ; From assembly copy output, hex, or unicode
            mov     ecx, hBuff
         INVOKE     lstrcpy, ecx, addr PathName
           call     WriteF
         INVOKE     SendMessage,  hREdit, EM_SETMODIFY, FALSE, 0
           call     CheckState
            jmp     EndSave
      .endif

crFile:
         mov     ecx, CREATE_ALWAYS
      .if SaveFlg1 == 44                       ; Backup files
            inc     FileCnt
         INVOKE     CreateFile, addr PathName,\
                    GENERIC_READ or GENERIC_WRITE ,\
                    FILE_SHARE_READ or FILE_SHARE_WRITE,\
                    NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL
         .if eax != -1                    ; No File or Error?
               mov     hTemp, eax
            INVOKE     GetFileTime, hTemp, addr FTimeSC, 0, addr FTimeSM
            INVOKE     CloseHandle, hTemp
            INVOKE     CompareFileTime, addr FTimeSM, addr FTimeOM
            .if eax == 0
               INVOKE     lstrcpy, addr PathName, addr SavPath
                  jmp     EndSave
            .endif
         .endif

            mov     ecx, CREATE_NEW
      .endif

      INVOKE     CreateFile, addr PathName,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 NULL, ecx, FILE_ATTRIBUTE_NORMAL, NULL
      .if eax != -1                      ; Error?
            jmp     SaveCFok

;---------- [Create bacxkup files] ----------
      .elseif SaveFlg1 == 44
         INVOKE     lstrlen, addr PathName
            sub     eax, 5
         .if ExtType == 'r' && ExtType+1 == 'c'
         .else
               dec     eax
         .endif
            inc     byte ptr PathName[eax]
            mov     Incr, eax

;---------- [Rollover saved files] ----------
         .if byte ptr PathName[eax] == 3ah
            INVOKE     lstrcpy, addr NewPath, addr PathName
               mov     CntF, '1'
               mov     Cnt, 9
            .while (Cnt)
                  mov     eax, Incr
                  xor     ecx, ecx
                  mov     cl, CntF
                  mov     byte ptr PathName[eax], cl
                  dec     ecx
                  mov     byte ptr NewPath[eax], cl
               INVOKE     DeleteFile, addr NewPath
               INVOKE     MoveFile, addr PathName, addr NewPath
                  inc     CntF
                  dec     Cnt
            .endw
               mov     eax, Incr
               mov     byte ptr PathName[eax], '9'
            INVOKE     DeleteFile, addr PathName
               jmp     crFile
         .endif
            jmp     crFile
      .endif

SaveErr:
         jmp     EndSave

SaveCFok:
         mov     hFile, eax
         mov     EditS.dwCookie, eax
         mov     EditS.dwError, 0
         mov     EditS.pfnCallback, offset EditStreamWrite

      INVOKE     SendMessage, hREdit, EM_STREAMOUT, SF_TEXT, addr EditS
         mov     BytesRead, eax

      .if SaveFlg1 == 44
         INVOKE     GetFileTime, hFile, addr FTimeSC, addr FTimeSA, addr FTimeSM
         INVOKE     SetFileTime, hFile, addr FTimeSC, addr FTimeSA, addr FTimeOM
      .endif
      INVOKE     CloseHandle, hFile
      INVOKE     SendMessage,  hREdit, EM_SETMODIFY, FALSE, 0

      .if SaveAs
            mov     tci.pszText, offset FileName       ; Pointer to string containing tab text
            mov     tci.cchTextMax, 0
         INVOKE     lstrcpy, tci.lParam, addr PathName
         INVOKE     SendMessage, hWndTab, TCM_SETITEM, TabSelect, addr tci
           call     SetTitle
      .endif

      INVOKE     BaseAscii, BytesRead, addr Fsize, 0, 10, 1, 0, 1
      INVOKE     lstrcpy, addr szFileSize, addr szSize
      INVOKE     lstrcat, addr szFileSize, addr Fsize
      INVOKE     SendMessage, hWndStat, SB_SETTEXT, 0, addr szFileSize

EndSave:
         and     SaveFlg1, 0
         ret

SaveFile ENDP

;===============================================================
; Edit Stream Save Callback PROCEDURE
;===============================================================
EditStreamWrite PROC  dwCookie:DWORD, pbBuff, cb, pcb
      INVOKE     WriteFile, dwCookie, pbBuff, cb, pcb, 0
         mov     eax, 0              ; File completely read
         ret
EditStreamWrite ENDP

;===============================================================
; DoBookmarks PROCEDURE
;===============================================================
DoBookmarks PROC uses esi edi
LOCAL    BookID:DWORD, Cnt, Incr, ID, SavID, Lnum, SavLnum
LOCAL    szWork[32]:BYTE, szBuff[32]:BYTE, szBuff1[256]:BYTE

         mov     BookID, ecx

;---------- [Set Bookmark] ----------
      .if ecx > 22000 && ecx < 22011
         INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_EXLINEFROMCHAR, 0, cr.cpMin
            mov     ecx, BookID
            sub     ecx, 22000
         INVOKE     SendMessage, hREdit, UM_SETBOOKMARK, eax, ecx

ResetBooks:
; MIIM_TYPE MIIM_FTYPE or  or MIIM_BITMAP
            mov     mii.fMask, MIIM_ID or MIIM_STATE or\
                               MIIM_CHECKMARKS or MIIM_FTYPE

            mov     ID, 22001
            mov     Cnt, 10
         .while (Cnt)
            INVOKE     GetMenuItemInfo, hMenu, ID, FALSE, addr mii
               mov     eax, ID
               mov     mii.wID, eax
            .if (mii.fState & MFS_CHECKED) && eax != BookID
                  mov     mii.fType, MFT_RADIOCHECK
                  mov     mii.fState, MFS_CHECKED

            .elseif eax == BookID
                  mov     mii.fType, 0
                  mov     mii.fState, MFS_CHECKED

            .else
                  jmp     NoChg01
            .endif

               INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
               INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii
                  add     mii.wID, 10
               INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
               INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii

NoChg01:
               inc     ID
               dec     Cnt
         .endw

;---------- [Goto Bookmark] ----------
      .elseif ecx > 22010 && ecx < 22021

GotoBookMark:
            sub     ecx, 22010
         INVOKE     SendMessage, hREdit, UM_FINDBOOKMARK, ecx, 0
         .if eax == -1
               ret
         .endif
;DSPValue hWnd, eax, 1, 'm'
         INVOKE     SendMessage, hREdit, EM_LINEINDEX, eax, 0
            mov     cr.cpMin, eax
            mov     cr.cpMax, eax
         INVOKE     LockWindowUpdate, hWnd           ; Lock parent to avoid flicker
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_SCROLLCARET, 0, 0
         INVOKE     LockWindowUpdate, 0              ; Unock parent
         INVOKE     CenterSel, 0
            sub     BookID, 10
            jmp     ResetBooks



;---------- [Goto next Bookmark] ----------
      .elseif ecx == 22030
         INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_EXLINEFROMCHAR, 0, cr.cpMin
         INVOKE     SendMessage, hREdit, UM_NEXTBOOKMARK, eax, 3
         .if eax == -1
               ret
         .endif
            mov     ecx, eax
            add     ecx, 22010
            mov     BookID, ecx
            jmp     GotoBookMark

;---------- [Goto previous Bookmark] ----------
      .elseif ecx == 22031
         INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_EXLINEFROMCHAR, 0, cr.cpMin
         INVOKE     SendMessage, hREdit, UM_PREVBOOKMARK, eax, 3
         .if eax == -1
               ret
         .endif
            mov     ecx, eax
            add     ecx, 22010
            mov     BookID, ecx
            jmp     GotoBookMark

;---------- [Clear Bookmark] ----------
      .elseif ecx == 22032
         INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_EXLINEFROMCHAR, 0, cr.cpMin
           push     eax
         INVOKE     SendMessage, hREdit, UM_GETBOOKMARK, eax, 0
            pop     ecx
           push     eax
         INVOKE     SendMessage, hREdit, UM_SETBOOKMARK, ecx, 0
            pop     eax
            add     eax, 22000
            mov     mii.wID, eax
            mov     mii.fType, 0 ;MFT_BITMAP
            mov     mii.fState, MFS_UNCHECKED
         INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
         INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii
            add     mii.wID, 10
         INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
         INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii

;---------- [Clear all Bookmarks] ----------
      .elseif ecx == 22033
         INVOKE     SendMessage, hREdit, UM_CLRBOOKMARKS, 0, 3
            lea     esi, BookArray
            and     Incr, 0
            mov     Cnt, 22
         .while (Cnt)
               mov     ecx, Incr
               mov     dword ptr[esi+ecx], 0
               add     Incr, 4
               dec     Cnt
         .endw

            mov     ID, 22001
            mov     Cnt, 10
         .while (Cnt)
               mov     eax, ID
               mov     mii.wID, eax
               mov     mii.fType, 0 ;MFT_BITMAP
               mov     mii.fState, MFS_UNCHECKED
            INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
            INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii
               add     mii.wID, 10
            INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
            INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii
               inc     ID
               dec     Cnt
         .endw
            jmp     SaveAllBookmarks

;---------- [Get all Bookmarks] ----------
      .elseif ecx == 22034

GetBookmarks:
            mov     ID, 22001
            mov     Cnt, 10
         .while (Cnt)
               mov     eax, ID
               mov     mii.wID, eax
               mov     mii.fType, 0
               mov     mii.fState, MFS_UNCHECKED
;mov     mii.fType, MFT_RADIOCHECK ;or MFT_BITMAP
;mov     mii.fState, MFS_CHECKED
            INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
            INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii
               add     mii.wID, 10
            INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
            INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii
               inc     ID
               dec     Cnt
         .endw

            lea     esi, BookArray
            and     Incr, 0
            mov     Cnt, 11
         .while (Cnt)
               mov     ecx, Incr
               mov     dword ptr[esi+ecx], 0
               mov     dword ptr[esi+ecx+4], 0
               add     Incr, 8 ;4
               dec     Cnt
         .endw

         INVOKE     SendMessage, hREdit, UM_GETALLBOOKMARKS, 0, addr BookArray
         INVOKE     SendMessage, hREdit, UM_GETCURBOOKMARK, 0, 0
            add     eax, 22000
            mov     BookID, eax
            and     Incr, 0
            mov     Cnt, 10
         .while (Cnt)
               lea     esi, BookArray
               mov     ecx, Incr
               mov     eax, [esi+ecx]
            .if !eax
               .break
            .endif
               add     eax, 22000
               mov     mii.wID, eax
               mov     mii.fType, MFT_RADIOCHECK
            .if eax == BookID
                  mov     mii.fType, 0
            .endif
               mov     mii.fState, MFS_CHECKED
            INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
            INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii
               add     mii.wID, 10
            INVOKE     SetMenuItemInfo, hMenu, mii.wID, FALSE, addr mii
            INVOKE     SetMenuItemInfo, hSMenu, mii.wID, FALSE, addr mii
               add     Incr, 8 ;4
               dec     Cnt
         .endw

;---------- [Save all Bookmarks to save file] ----------
      .elseif ecx == 22035

SaveAllBookmarks:
         INVOKE     lstrcpy, addr szBuffP, addr AsmRootDir
;         INVOKE     lstrcat, addr szBuffP, addr szPointer

      .if ProjGroup
         INVOKE     lstrcat, addr szBuffP, addr szPointUser
      .endif
         mov     ecx, ProjGroup
      INVOKE     lstrcat, addr szBuffP, PtrArray[ecx*4]

;         INVOKE     lstrcat, addr szBuffP, addr szProject
            mov     eax, ProjGroup
         INVOKE     lstrcat, addr szBuffP, ProjNamArray[eax*4]
         INVOKE     lstrcat, addr szBuffP, addr szPer
         INVOKE     lstrcat, addr szBuffP, addr szPtr
         INVOKE     GetFileAttributes, addr szBuffP
         .if eax == -1
               jmp     NoFile
         .endif

;---------- [Get the folder name] ----------
           call     GetFolderName
;         INVOKE     lstrcmpi, addr szFolder, addr szProject
            mov     eax, ProjGroup
         INVOKE     lstrcmpi, addr szFolder, ProjNamArray[eax*4]
         .if eax != 0
               jmp     NoFile
         .endif

         .if ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm' ||\
             ExtType == '.' && ExtType + 1 == 'r' && ExtType + 2 == 'c' ||\
             ExtType == 'i' && ExtType + 1 == 'n' && ExtType + 2 == 'c' ||\
             ExtType == 'r' && ExtType + 1 == 'c'
         .else
               jmp     NoFile
         .endif

         .if byte ptr FileName == '(' || byte ptr FileName == ' ' || byte ptr FileName == 0
               jmp     NoFile
         .endif

            lea     esi, BookArray
            and     Incr, 0
            mov     Cnt, 11
         .while (Cnt)
               mov     ecx, Incr
               mov     dword ptr[esi+ecx], 0
               mov     dword ptr[esi+ecx+4], 0
               add     Incr, 8
               dec     Cnt
         .endw

         INVOKE     SendMessage, hREdit, UM_GETALLBOOKMARKS, 0, addr BookArray

            lea     esi, BookArray
            mov     eax, dword ptr[esi+80]
            mov     BookID, eax

            mov     byte ptr szBuff1, 0
            and     ID, 0
            and     Incr, 0
            mov     Cnt, 11
         .while (Cnt)
               inc     ID
               mov     edx, Incr
               mov     ecx, dword ptr[esi+edx]
            .while (Cnt && ID < ecx)
               INVOKE     lstrcat, addr szBuff1, addr szBookFill
                  mov     edx, Incr
                  mov     ecx, dword ptr[esi+edx]
                  inc     ID
                  dec     Cnt
            .endw
            .if !Cnt
               .break
            .endif
               mov     ecx, dword ptr[esi+edx+4]
            INVOKE     BaseAscii, ecx, addr szWork, 8, 10, 0, 1, 1
            INVOKE     lstrcat, addr szBuff1, addr szWork
            INVOKE     lstrcat, addr szBuff1, addr szCom
               add     Incr, 8
               dec     Cnt
         .endw
            mov     ecx, BookID
         INVOKE     BaseAscii, ecx, addr szWork, 8, 10, 0, 1, 1
         INVOKE     lstrcpyn, addr szBuff1+90, addr szWork, 9
         INVOKE     WritePrivateProfileString, addr szBookMarks, addr FileName, addr szBuff1, addr szBuffP


;---------- [Load all Bookmarks from save file] ----------
      .elseif ecx == 22036
         INVOKE     lstrcpy, addr szBuffP, addr AsmRootDir
;         INVOKE     lstrcat, addr szBuffP, addr szPointer

      .if ProjGroup
         INVOKE     lstrcat, addr szBuffP, addr szPointUser
      .endif
         mov     eax, ProjGroup
      INVOKE     lstrcat, addr szBuffP, PtrArray[eax*4]

;         INVOKE     lstrcat, addr szBuffP, addr szProject
            mov     eax, ProjGroup
         INVOKE     lstrcat, addr szBuffP, ProjNamArray[eax*4]
         INVOKE     lstrcat, addr szBuffP, addr szPer
         INVOKE     lstrcat, addr szBuffP, addr szPtr
         INVOKE     GetFileAttributes, addr szBuffP
         .if eax == -1
               jmp     NoFile
         .endif

;---------- [Get the folder name] ----------
           call     GetFolderName
;         INVOKE     lstrcmpi, addr szFolder, addr szProject
            mov     eax, ProjGroup
         INVOKE     lstrcmpi, addr szFolder, ProjNamArray[eax*4]
         .if eax != 0
               jmp     NoFile
         .endif

         INVOKE     GetPrivateProfileString, addr szBookMarks, addr FileName, addr szNULL,\
                    addr szBuff1, 255, addr szBuffP
         .if eax == 0 || eax == 1
               jmp     NoFile
         .endif
;INVOKE     MessageBox, NULL, addr szBuff1, addr AppName, MB_OK

         INVOKE     lstrcpyn, addr szWork, addr szBuff1+90, 9
         INVOKE     AsciiBase, addr szWork, addr SavID, 10
            and     SavLnum, 0

            xor     esi, esi
            lea     edi, BookArray
            and     ID, 0
            mov     Cnt, 10
         .while (Cnt)
               inc     ID
            INVOKE     lstrcpyn, addr szWork, addr szBuff1[esi], 9
            INVOKE     AsciiBase, addr szWork, addr Lnum, 10
            .if Lnum
                  mov     eax, ID
               .if eax == SavID
                   MOVmd     SavLnum, Lnum
               .endif
               INVOKE     SendMessage, hREdit, UM_SETBOOKMARK, Lnum, ID
            .endif
               add     esi, 9
               dec     Cnt
         .endw
         .if SavLnum
;---------- [Set current
            INVOKE     SendMessage, hREdit, UM_SETBOOKMARK, SavLnum, SavID
         .endif
            jmp     GetBookmarks
      .endif

NoFile:
         ret

DoBookmarks ENDP

;===============================================================
; DoMenus PROCEDURE
;===============================================================
DoMenus PROC uses ebx esi wParam:DWORD, lParam
LOCAL    w4:DWORD, w6
LOCAL    szWork[20]:BYTE

      INVOKE     GetMenuPath, addr szRedit, wParam, lParam
      .if lParam == 1
            jmp     idmbuildmenu
      .elseif lParam == 2
            jmp     idmaddinmenu
      .elseif lParam == 3
            jmp     idmtoolsmenu
      .elseif lParam == 4
            jmp     idmhelpmenu
      .endif
         jmp     Ret0

idmbuildmenu:
;      INVOKE     GetMenuPath, addr szRedit, wParam, 1
         jmp     DoExecute

idmaddinmenu:
;      INVOKE     GetMenuPath, addr szRedit, wParam, 2 ;3
      .if szBuffP
         INVOKE     lstrlen, addr szBuffP
         .if szBuffP[eax-3] == 'e'
            INVOKE     ShellExecute, hWnd, addr szOpen, addr szBuffP, NULL, NULL, SW_SHOWNORMAL
               jmp     Ret0
         .endif

          MOVmd     MenuID, wParam

;---------- [Extract the return wParam and lParam values] ----------
         INVOKE     lstrlen, addr szBuffW
            mov     ecx, eax
            xor     eax, eax
         .while (ecx)
            .if byte ptr szBuffW[eax] == ','
                  inc     eax
                 push     eax
               INVOKE     lstrcpyn, addr szWork, addr szBuffW, eax
                  pop     eax
               INVOKE     lstrcpy, addr szBuffW, addr szBuffW[eax]
               .break
            .endif
               inc     eax
               dec     ecx
         .endw

         INVOKE     AsciiBase, addr szWork, addr w5, 10
         INVOKE     AsciiBase, addr szBuffW, addr w6, 10
         INVOKE     LoadLibrary, addr szBuffP
         .if eax
mov     Test4, eax
               mov     ebx, eax
               xor     eax, eax
               mov     ecx, 64
            .while (ecx)
               .if ebx == hAddins[eax*4]
                  .break
               .endif
                  inc     eax
                  dec     ecx
            .endw
            .if !ecx
                  xor     eax, eax
                  mov     ecx, 64
               .while (ecx)
                  .if !hAddins[eax*4]
                        mov     hAddins[eax*4], ebx
                     .break
                  .endif
                     inc     eax
                     dec     ecx
               .endw
            .endif
            .if !ecx  ; Array is FULL!
               INVOKE     FreeLibrary, ebx
                  jmp     Ret0
            .endif
            INVOKE     GetProcAddress, ebx, addr szBuffF ;w4
            .if eax
                 push     w6
                 push     w5
                 push     WM_COMMAND
                 push     hWnd
                 call     eax
            .else
            .endif
            INVOKE     FreeLibrary, Test4
         .else
            INVOKE     MessageBox, NULL, addr szError5, addr szBuffP, MB_OK or MB_ICONERROR

         .endif
      .endif
         jmp     Ret0

idmtoolsmenu:
;      INVOKE     GetMenuPath, addr szRedit, wParam, 3
DoExecute:
      INVOKE     lstrlen, addr szBuffP
      .if szBuffP[eax-5] == '.'
            dec     eax
      .endif
      INVOKE     lstrcpy, addr szWork, addr szBuffP[eax-3]
         mov     ecx, 3
         lea     esi, szWork
        call     LowerCase                                        ; Convert to lowercase
      .if byte ptr szWork == 'e' && byte ptr szWork+1 == 'x' && byte ptr szWork+2 == 'e' ||\      ; .exe
              byte ptr szWork == 'c' && byte ptr szWork+1 == 'o' && byte ptr szWork+2 == 'm' ||\  ; .com
              byte ptr szWork == 'b' && byte ptr szWork+1 == 'a' && byte ptr szWork+2 == 't'      ; .bat
         INVOKE     ShellExecute, hWnd, addr szOpen, addr szBuffP, NULL, NULL, SW_SHOWNORMAL
      .endif
         jmp     Ret0

idmhelpmenu:
;      INVOKE     GetMenuPath, addr szRedit, wParam, 4 ;1
      INVOKE     lstrlen, addr szBuffP
      .if szBuffP[eax-5] == '.'
            dec     eax
      .endif
      INVOKE     lstrcpy, addr szWork, addr szBuffP[eax-3]
         mov     ecx, 3
         lea     esi, szWork
        call     LowerCase                                        ; Convert to lowercase
      .if byte ptr szWork == 'h' && byte ptr szWork+1 == 'l' && byte ptr szWork+2 == 'p'
         INVOKE     WinHelp, hWnd, addr szBuffP, HELP_CONTENTS, 0 ; Open a help file
      .elseif byte ptr szWork == 'e' && byte ptr szWork+1 == 'x' && byte ptr szWork+2 == 'e'  ; .exe
         INVOKE     ShellExecute, hWnd, addr szOpen, addr szBuffP, NULL, NULL, SW_SHOWNORMAL
      .else                                                       ; Text file
         INVOKE     lstrcpy, addr WorkBuff, addr PathName
         INVOKE     lstrcpy, addr PathName, addr szBuffP
            mov     OA, 1
            mov     OpenFlg1, 1
           call     OpenFileA
         INVOKE     lstrcpy, addr PathName, addr WorkBuff
      .endif
         jmp     Ret0

Ret0:
         xor     eax, eax
         ret

DoMenus ENDP

;===============================================================
; Set preferences PROCEDURE
;===============================================================
SetPreferences PROC uses ebx esi hdlg:DWORD, wMsg, wParam, lParam
LOCAL    ofn:OPENFILENAME
LOCAL    Cnt:DWORD, Len, Hold, hTemp, Incr, hReg
LOCAL    LBuff[32]:BYTE, szBuff0[256]:BYTE

      .if wMsg == WM_INITDIALOG              ; If message is INITDIALOG then
         INVOKE     GetDlgItem, hdlg, 201
            mov     hListT, eax
         INVOKE     GetDlgItem, hdlg, 202
            mov     hListS, eax
         INVOKE     GetDlgItem, hdlg, 205
            mov     hListL, eax
         INVOKE     GetDlgItem, hdlg, 206
            mov     hListW, eax
         INVOKE     GetDlgItem, hdlg, 41
            mov     h41, eax
         INVOKE     GetDlgItem, hdlg, 42
            mov     h42, eax
         INVOKE     GetDlgItem, hdlg, 43
            mov     h43, eax
         INVOKE     GetDlgItem, hdlg, 44
            mov     h44, eax
         INVOKE     GetDlgItem, hdlg, 45
            mov     h45, eax
         INVOKE     GetDlgItem, hdlg, 509            ; Get the handle of the Update
            mov     hUpdate, eax                     ; Save it
         INVOKE     GetDlgItem, hdlg, IDCANCEL       ; Get the handle of the IDCANCEL
            mov     hCancel, eax                     ; Save it

         INVOKE     SendMessage, hUpdate, WM_SETFONT, hFontButt, TRUE
         INVOKE     SendMessage, hCancel, WM_SETFONT, hFontButt, TRUE

         INVOKE     SendMessage, hListS, WM_SETFONT, hFontTL, TRUE
         INVOKE     SendMessage, hListT, WM_SETFONT, hFontTL, TRUE
         INVOKE     SendMessage, hListL, WM_SETFONT, hFontTL, TRUE
         INVOKE     SendMessage, hListW, WM_SETFONT, hFontTL, TRUE

            and     Cnt, 0
         .while (Cnt < 30)
               inc     Cnt
            INVOKE     BaseAscii, Cnt, addr LBuff, 3, 10, 0, 1, 1
            INVOKE     SendMessage, hListT, LB_ADDSTRING, 0, addr LBuff
         .endw
            mov     edx, 3
         INVOKE     BaseAscii, edx, addr LBuff, 3, 10, 0, 1, 1
         INVOKE     SetDlgItemText, hdlg, 701, addr LBuff
         INVOKE     BaseAscii, TAB, addr LBuff, 3, 10, 0, 1, 1
         INVOKE     SendMessage, hListT, LB_FINDSTRINGEXACT, -1, addr LBuff
         INVOKE     SendMessage, hListT, LB_SETCURSEL, eax, 0
         INVOKE     SendMessage, hListT, LB_SETCURSEL, -1, 0

            mov     esi, offset NumRangeS
            xor     eax, eax
            xor     ebx, ebx
            and     Cnt, 0

Getlen:
         .if byte ptr[esi+eax] == 2ch
               mov     Len, eax
               inc     Len
               inc     Cnt
            .if Cnt > 0
               INVOKE     lstrcpyn, addr LBuff, esi, Len
               INVOKE     SendMessage, hListS, LB_ADDSTRING, 0, addr LBuff
               INVOKE     AsciiBase, addr LBuff, addr Hold, 10
                  mov     eax, Hold
                  mov     dword ptr SpeedRange[ebx], eax
                  add     ebx, 4
            .endif
               add     esi, Len
               xor     eax, eax
               jmp     Getlen

         .elseif byte ptr[esi+eax] == 0h
;  1,2,4,6,8,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,120,150,200,250,300
            INVOKE     SendMessage, hREdit, UM_GETSCROLLSPEED, 0, 0
               xor     edx, edx
               mov     ecx, 1000000
               div     ecx
               xor     ebx, ebx
               xor     edx, edx
               mov     ecx, 32
            .while (ecx)
               .if eax <= dword ptr SpeedRange[ebx]
                  .break
               .endif
                  inc     edx
                  add     ebx, 4
                  dec     ecx
            .endw
               mov     edx, dword ptr SpeedRange[ebx]
            INVOKE     BaseAscii, Speed, addr LBuff, 3, 10, 0, 1, 1
            INVOKE     SendMessage, hListS, LB_FINDSTRINGEXACT, -1, addr LBuff
            INVOKE     SendMessage, hListS, LB_SETCURSEL, eax, 0
            INVOKE     SendMessage, hListS, LB_SETCURSEL, -1, 0
            INVOKE     GetDlgItem, hdlg, 702
               mov     edx, dword ptr SpeedRange[ebx]
            INVOKE     BaseAscii, edx, addr LBuff, 3, 10, 0, 1, 1
            INVOKE     SetDlgItemText, hdlg, 702, addr LBuff
            INVOKE     SetFocus, hListS
               jmp     Continue
         .endif
            inc     eax
            jmp     Getlen

Continue:
            mov     Cnt, 34
         .while (Cnt < 50)
               inc     Cnt
            INVOKE     BaseAscii, Cnt, addr LBuff, 3, 10, 0, 1, 1
            INVOKE     SendMessage, hListL, LB_ADDSTRING, 0, addr LBuff
         .endw
         INVOKE     BaseAscii, 37, addr LBuff, 3, 10, 0, 1, 1
         INVOKE     SetDlgItemText, hdlg, 705, addr LBuff
         INVOKE     BaseAscii, LineWth, addr LBuff, 3, 10, 0, 1, 1
         INVOKE     SendMessage, hListL, LB_FINDSTRINGEXACT, -1, addr LBuff
         INVOKE     SendMessage, hListL, LB_SETCURSEL, eax, 0
         INVOKE     SendMessage, hListL, LB_SETCURSEL, -1, 0

            and     Cnt, 0
         .while (Cnt < 20)
               inc     Cnt
            INVOKE     BaseAscii, Cnt, addr LBuff, 3, 10, 0, 1, 1
            INVOKE     SendMessage, hListW, LB_ADDSTRING, 0, addr LBuff
         .endw
         INVOKE     BaseAscii, 44, addr LBuff, 3, 10, 0, 1, 1
         INVOKE     SendMessage, hListW, LB_ADDSTRING, 0, addr LBuff
         INVOKE     BaseAscii, 3, addr LBuff, 2, 10, 0, 1, 1
         INVOKE     SetDlgItemText, hdlg, 706, addr LBuff
         INVOKE     BaseAscii, WheelNum, addr LBuff, 3, 10, 0, 1, 1
         INVOKE     SendMessage, hListW, LB_FINDSTRINGEXACT, -1, addr LBuff
         INVOKE     SendMessage, hListW, LB_SETCURSEL, eax, 0
         INVOKE     SendMessage, hListW, LB_SETCURSEL, -1, 0

         INVOKE     SetDlgItemInt, hdlg, 203, SPACE, FALSE
         INVOKE     SetDlgItemInt, hdlg, 204, SHIFT, FALSE
         INVOKE     SendDlgItemMessage, hdlg, 301, BM_SETCHECK, FontZoomOn, 0
         INVOKE     SendDlgItemMessage, hdlg, 302, BM_SETCHECK, SmoothOn, 0
         INVOKE     SendDlgItemMessage, hdlg, 303, BM_SETCHECK, ItalicOn, 0
         INVOKE     SendDlgItemMessage, hdlg, 304, BM_SETCHECK, NoHiLiteBW, 0
         INVOKE     SendDlgItemMessage, hdlg, 305, BM_SETCHECK, CloseBuild, 0
         INVOKE     SendDlgItemMessage, hdlg, 306, BM_SETCHECK, AutoSave, 0


;---------- [Load the paths
            mov     Incr, 401
            xor     esi, esi
         .while (Incr < 409)
               mov     lpcbData, 250
               mov     szBuff0, 0
            INVOKE     RegQuerySZ, addr rDEFr[esi], addr szBuff0
            .if eax == ERROR_SUCCESS
               INVOKE     SetDlgItemText, hdlg, Incr, addr szBuff0
            .endif
               add     esi, 19
               inc     Incr
         .endw

      .elseif wMsg == WM_CTLCOLORDLG 
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLORSTATIC
            mov     eax, lParam
         .if eax == h41 || eax == h42 || eax == h43 || eax == h44 || eax == h45
            INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
            INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is blue
            INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background

         .else
            INVOKE     SetBkColor, wParam, Color.DialogBC
            INVOKE     SetTextColor, wParam, 00000000h
               mov     eax, hBRD
         .endif
            ret

      .elseif wMsg == WM_CTLCOLORLISTBOX || wMsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_CLOSE
            jmp     CloseIt

      .elseif wMsg == WM_COMMAND
            mov     ebx, wParam
            mov     eax, ebx
            and     eax, 0ffffh
            shr     ebx, 16

         .if ebx == BN_CLICKED
            INVOKE     GetFocus
            INVOKE     GetDlgCtrlID, eax
         .endif

         .if ebx == CBN_SELCHANGE
               jmp     SetChange

         .elseif eax > 500 && eax < 509
               mov     Incr, eax
               sub     Incr, 100
            INVOKE     GetDlgItemText, hdlg, Incr, addr szBuff0, sizeof szBuff0
            .if Incr != 408
               INVOKE     lstrcat, addr szBuff0, addr szAll
            .endif
            INVOKE     RtlZeroMemory, addr ofn, sizeof ofn

;---------- [Set the OPENFILENAME attributes] ----------
               mov     ofn.lStructSize, sizeof ofn
               mov     eax, hWnd
               mov     ofn.hwndOwner, eax
               mov     eax, hInst
               mov     ofn.hInstance, eax
               mov     ofn.lpstrFilter, offset szFilter
               lea     eax, szBuff0
               mov     ofn.lpstrFile, eax
               mov     ofn.nMaxFile, lengthof szBuff0
               mov     ofn.lpstrFileTitle, 0 ;offset szAll
               mov     ofn.nMaxFileTitle, 0 ;lengthof szAll
               lea     eax, szBuff0
               mov     ofn.lpstrInitialDir, eax
               mov     ofn.lpstrTitle, offset szOpenTitle
               mov     ofn.Flags, OFN_NOVALIDATE
            INVOKE     GetOpenFileName, addr ofn
            .if !eax                       ; Cancel'ed or error occurred
                  jmp     SetPrefDone
            .endif
               sub     wParam, 100
            .if wParam == 408
               INVOKE     SetDlgItemText, hdlg, wParam, ofn.lpstrFile
                  jmp     SetPrefDone
            .else
                  xor     eax, eax
                  mov     ax, ofn.nFileOffset
                  inc     eax
               INVOKE     lstrcpyn, addr szBuff0, ofn.lpstrFile, eax
               INVOKE     SetDlgItemText, hdlg, wParam, addr szBuff0
                  jmp     SetPrefDone
            .endif

         .elseif eax == 302
            INVOKE     SendDlgItemMessage, hdlg, 302, BM_GETCHECK, 0, 0
            INVOKE     SendMessage, hREdit, UM_SMOOTHSCROLL, 0, eax
            INVOKE     GetDlgItem, hdlg, 302
            INVOKE     SetFocus, eax

         .elseif eax == 303
            INVOKE     SendDlgItemMessage, hdlg, 303, BM_GETCHECK, 0, 0
            INVOKE     SetValues, UM_ITALIC, eax, 0
            INVOKE     GetDlgItem, hdlg, 303
            INVOKE     SetFocus, eax


         .elseif eax == 304
            INVOKE     SetValues, UM_BLACKWHITE, STATE_BLACKWHITE, 0
            INVOKE     GetDlgItem, hdlg, 304
            INVOKE     SetFocus, eax

         .elseif eax == 509
            INVOKE     GetDlgItemInt, hdlg, 203, NULL, FALSE
               mov     SPACE, eax
            INVOKE     GetDlgItemInt, hdlg, 204, NULL, FALSE
               mov     SHIFT, eax
            INVOKE     SendDlgItemMessage, hdlg, 301, BM_GETCHECK, 0, 0
               mov     FontZoomOn, eax
            INVOKE     SendDlgItemMessage, hdlg, 302, BM_GETCHECK, 0, 0
               mov     SmoothOn, eax
            INVOKE     SendDlgItemMessage, hdlg, 303, BM_GETCHECK, 0, 0
               mov     ItalicOn, eax
            INVOKE     SendDlgItemMessage, hdlg, 304, BM_GETCHECK, 0, 0
               mov     NoHiLiteBW, eax
            INVOKE     SendDlgItemMessage, hdlg, 305, BM_GETCHECK, 0, 0
               mov     CloseBuild, eax
            INVOKE     SendDlgItemMessage, hdlg, 306, BM_GETCHECK, 0, 0
               mov     AutoSave, eax

            INVOKE     SendMessage, hListT, LB_GETTOPINDEX, 0, 0
               mov     ecx, eax
            INVOKE     SendMessage, hListT, LB_GETTEXT, ecx, addr LBuff
            INVOKE     AsciiBase, addr LBuff, addr TAB, 10
            INVOKE     SendMessage, hREdit, UM_TABWIDTH, TAB, 0

            INVOKE     SendMessage, hListS, LB_GETTOPINDEX, 0, 0
               mov     ecx, eax
            INVOKE     SendMessage, hListS, LB_GETTEXT, ecx, addr LBuff
            INVOKE     AsciiBase, addr LBuff, addr Speed, 10
               mov     eax, Speed
              imul     eax, 1000000
            INVOKE     SendMessage, hREdit, UM_SETSCROLLSPEED, 0, eax

            INVOKE     SendMessage, hListL, LB_GETTOPINDEX, 0, 0
               mov     ecx, eax

            INVOKE     SendMessage, hListL, LB_GETTEXT, ecx, addr LBuff
            INVOKE     AsciiBase, addr LBuff, addr LineWth, 10
            INVOKE     SendMessage, hREdit, UM_LINENUMWIDTH, LineWth, 0

            INVOKE     SendMessage, hListW, LB_GETTOPINDEX, 0, 0
               mov     ecx, eax
            INVOKE     SendMessage, hListW, LB_GETTEXT, ecx, addr LBuff
            INVOKE     AsciiBase, addr LBuff, addr WheelNum, 10
            INVOKE     SendMessage, hREdit, UM_MOUSEWHEEL, WheelNum, 0

;---------- [Save the paths
            mov     Incr, 401
            xor     esi, esi
         .while (Incr < 409)
            INVOKE     GetDlgItemText, hdlg, Incr, addr szBuff0, sizeof szBuff0
            .if eax < 4
                  mov     szBuff0, 0
            .endif
               INVOKE     lstrlen, addr szBuff0
                  mov     lpcbData, eax
               INVOKE     RegSetSZ, addr rDEFr[esi], addr szBuff0
               add     esi, 19
               inc     Incr
         .endw
           call     CheckState
            jmp     CloseIt

         .elseif eax == IDCANCEL
               jmp     CloseIt

         .elseif eax == 702 ;302
            INVOKE     SetFocus, hListS
         .endif

      .endif
         jmp     SetPrefDone

SetChange:
         mov     eax, lParam
      .if eax == hListT
         INVOKE     SendMessage, hListT, LB_GETCURSEL, 0, 0
         .if eax == LB_ERR
               jmp     SetPrefDone
         .endif
            mov     ecx, eax
         INVOKE     SendMessage, hListT, LB_GETTEXT, ecx, addr LBuff
         INVOKE     AsciiBase, addr LBuff, addr TAB, 10
         INVOKE     SendMessage, hREdit, UM_TABWIDTH, TAB, 0

      .elseif eax == hListS
         INVOKE     SendMessage, hListS, LB_GETCURSEL, 0, 0
         .if eax == LB_ERR
               jmp     SetPrefDone
         .endif
            mov     ecx, eax
         INVOKE     SendMessage, hListS, LB_GETTEXT, ecx, addr LBuff
         INVOKE     AsciiBase, addr LBuff, addr Speed, 10
            mov     eax, Speed
           imul     eax, 1000000
         INVOKE     SendMessage, hREdit, UM_SETSCROLLSPEED, 0, eax

      .elseif eax == hListL
         INVOKE     SendMessage, hListL, LB_GETCURSEL, 0, 0
         .if eax == LB_ERR
               jmp     SetPrefDone
         .endif
            mov     ecx, eax
         INVOKE     SendMessage, hListL, LB_GETTEXT, ecx, addr LBuff
         INVOKE     AsciiBase, addr LBuff, addr LineWth, 10
         INVOKE     SendMessage, hREdit, UM_LINENUMWIDTH, LineWth, 0

      .elseif eax == hListW
         INVOKE     SendMessage, hListW, LB_GETCURSEL, 0, 0
         .if eax == LB_ERR
               jmp     SetPrefDone
         .endif
            mov     ecx, eax
         INVOKE     SendMessage, hListW, LB_GETTEXT, ecx, addr LBuff
         INVOKE     AsciiBase, addr LBuff, addr WheelNum, 10
         INVOKE     SendMessage, hREdit, UM_MOUSEWHEEL, WheelNum, 0

      .endif
         jmp     SetPrefDone

CloseIt:
         and     hPref, 0
         and     hWndDlg, 0
      INVOKE     SetFocus, hREdit
      INVOKE     DestroyWindow, hdlg     ; End the dialog
         mov     eax, TRUE               ; Return
         jmp     SetPrefRet              ; with TRUE

SetPrefDone:
         mov     eax, FALSE              ; Return with FALSE

SetPrefRet:
         ret

SetPreferences ENDP

;===============================================================
; SetCodeHelper PROCEDURE
;===============================================================
SetCodeHelper PROC uses ebx hdlg:DWORD, wMsg, wParam, lParam

      .if wMsg == WM_INITDIALOG              ; If message is INITDIALOG then
            mov     eax, hdlg
            mov     hType, eax
            mov     hWndDlg, eax
         INVOKE     GetDlgItem, hdlg, 509            ; Get the handle of the Update
            mov     hUpdate, eax                     ; Save it
         INVOKE     GetDlgItem, hdlg, IDCANCEL       ; Get the handle of the IDCANCEL
            mov     hCancel, eax                     ; Save it
         INVOKE     SendDlgItemMessage, hdlg, 101, BM_SETCHECK, CodeHelperOn, 0
         INVOKE     SendDlgItemMessage, hdlg, 102, BM_SETCHECK, BeepOn, 0
         INVOKE     SendDlgItemMessage, hdlg, 103, BM_SETCHECK, SpaceAfter, 0
         INVOKE     SendDlgItemMessage, hdlg, 104, BM_SETCHECK, RightAlign, 0
         INVOKE     SetDlgItemInt, hdlg, 201, MinMatch, FALSE
         INVOKE     SetDlgItemInt, hdlg, 202, Indent, FALSE
         INVOKE     SetDlgItemInt, hdlg, 203, Outdent, FALSE

      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
           cwde

         .if eax == 509
               jmp     Update
         .elseif eax == IDCANCEL
               jmp     CloseIt
         .endif

      .elseif wMsg == WM_CLOSE
            jmp     CloseIt
      .endif
         jmp     TypeDone

Update:
      INVOKE     SendDlgItemMessage, hdlg, 101, BM_GETCHECK, 0, 0
         mov     CodeHelperOn, eax
      INVOKE     SendDlgItemMessage, hdlg, 102, BM_GETCHECK, 0, 0
         mov     BeepOn, eax
      INVOKE     SendDlgItemMessage, hdlg, 103, BM_GETCHECK, 0, 0
         mov     SpaceAfter, eax
      INVOKE     SendDlgItemMessage, hdlg, 104, BM_GETCHECK, 0, 0
         mov     RightAlign, eax
      INVOKE     GetDlgItemInt, hdlg, 201, NULL, FALSE
         mov     MinMatch, eax
      INVOKE     GetDlgItemInt, hdlg, 202, NULL, FALSE
         mov     Indent, eax
      INVOKE     GetDlgItemInt, hdlg, 203, NULL, FALSE
         mov     Outdent, eax
        call     CheckState

CloseIt:
      INVOKE     EndDialog, hdlg, wParam
         and     hType, 0
         and     hWndDlg, 0
      INVOKE     SetFocus, hREdit
;      INVOKE     DestroyWindow, hdlg     ; End the dialog
         mov     eax, TRUE
         jmp     SetTypeRet

TypeDone:
         mov     eax, FALSE

SetTypeRet:
         ret

SetCodeHelper ENDP

;===============================================================
; GotoLineProc PROCEDURE
;===============================================================
GotoLineProc PROC uses ebx hdlg:DWORD, wMsg, wParam, lParam

      .if wMsg == WM_INITDIALOG              ; If message is INITDIALOG then
            mov     eax, hdlg
            mov     hGoto, eax
            mov     hWndDlg, eax
         INVOKE     GetDlgItem, hdlg, 401
         INVOKE     SetFocus, eax
         INVOKE     GetDlgItem, hdlg, 601
            mov     hCombo01, eax
         INVOKE     GetDlgItem, hdlg, 501            ; Get the handle of the Go
            mov     h42, eax                         ; Save it
         INVOKE     GetDlgItem, hdlg, IDCANCEL       ; Get the handle of the IDCANCEL
            mov     h43, eax                         ; Save it

         INVOKE     SendMessage, hCombo01, WM_SETFONT, hFontC, 1
         INVOKE     SendMessage, hCombo01, CB_SETITEMHEIGHT, -1, 14       ; Selection field
         INVOKE     SendMessage, hCombo01, CB_SETITEMHEIGHT, 0, 13        ; List items

         .if PathName && ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm'
            INVOKE     WriteReadMem, 4, 4 ;0, 0
            INVOKE     SendMessage, hCombo01, CB_SETCURSEL, 0, 0

         .else
               jmp     GotoDone            ; Go and return
         .endif

      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLORLISTBOX || wMsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
           cwde
            mov     ebx, wParam
            shr     ebx, 16

         .if ebx == BN_CLICKED
            INVOKE     GetFocus
            INVOKE     GetDlgCtrlID, eax
         .endif

         .if ebx == CBN_SELCHANGE
               jmp     GotoProc
         .elseif eax == 501 || eax == 401 && wParam == 1
               jmp     GotoLine
         .elseif eax == IDCANCEL
               jmp     CloseIt
         .endif

      .elseif wMsg == WM_CLOSE
            jmp     CloseIt
      .endif
         jmp     GotoDone

GotoLine:
      INVOKE     GetDlgItemInt, hdlg, 401, 0, 0
         dec     eax
      INVOKE     SendMessage, hREdit, EM_LINEINDEX, eax, 0

SetLine:
         mov     cr.cpMin, eax
;inc     eax
         mov     cr.cpMax, eax
      INVOKE     LockWindowUpdate, hWnd           ; Lock parent to avoid flicker
      INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
      INVOKE     SendMessage, hREdit, EM_SCROLLCARET, 0, 0
      INVOKE     LockWindowUpdate, 0              ; Unock parent
      INVOKE     CenterSel, 0
.if ebx == CBN_SELCHANGE && osv.dwMajorVersion == 4 && osv.dwMinorVersion == 0  ; NT 4.0
      jmp     GotoDone  ; ??????????????
.endif
         jmp     CloseIt

GotoProc:
;---------- [Check for proc selection] ----------
      INVOKE     SendMessage, hCombo01, CB_GETCURSEL, 0, 0
      INVOKE     SendMessage, hCombo01, CB_GETITEMDATA, eax, 0
         dec     eax
      INVOKE     SendMessage, hREdit, EM_LINEINDEX, eax, 0
         jmp     SetLine

CloseIt:
         and     hGoto, 0
         and     hWndDlg, 0
      INVOKE     SetFocus, hREdit
;      INVOKE     EndDialog, hdlg, wParam ; End the dialog with wParam as return
      INVOKE     DestroyWindow, hdlg     ; End the dialog
         mov     eax, TRUE               ; Return
         jmp     GotoRet                 ; with TRUE

GotoDone:
         mov     eax, FALSE              ; Return with FALSE

GotoRet:
         ret                             ; Return
GotoLineProc ENDP

;===============================================================
; Scroll selection to center PROCEDURE
;===============================================================
CenterSel PROC Bypass:DWORD
LOCAL    tm:TEXTMETRIC
LOCAL    pt:POINT
LOCAL    Srect:RECT
LOCAL    hDC:DWORD, FontHgt, NScrL, TopLine, CurLine, CenLine, w1

      INVOKE     GetDC, hREdit
         mov     hDC, eax
      INVOKE     SelectObject, hDC, hFont
        push     eax
      INVOKE     GetTextMetrics,hDC, addr tm
jmp     Pass
;DSPValue hWnd, tm.tmHeight, 1, 'm'
;DSPValue hWnd, tm.tmAscent, 1, 'm'
;DSPValue hWnd, tm.tmDescent, 1, 'm'
;DSPValue hWnd, tm.tmInternalLeading, 1, 'm'
;DSPValue hWnd, tm.tmExternalLeading, 1, 'm'
;DSPValue hWnd, tm.tmDigitizedAspectY, 1, 'm'
Pass:
      INVOKE     GetTextExtentPoint32, hDC, addr szX, 1, addr pt
         mov     eax, pt.y
         mov     FontHgt, eax
         mov     w1, 2
       finit
        fild     w1
        fild     FontHgt
        fdiv     ST(0), ST(1)
       fistp     w1
         pop     eax
      INVOKE     SelectObject, hDC, eax
      INVOKE     ReleaseDC, hREdit, hDC
      INVOKE     GetClientRect, hREdit, addr Srect
         xor     edx, edx
         mov     eax, Srect.bottom
         sub     eax, 16                          ; Scroll bar height
         mov     ecx, FontHgt
         div     ecx
         mov     NScrL, eax
      INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
      .if eax <= NScrL
            jmp     NoCenter
      .endif
      INVOKE     LockWindowUpdate, hWnd           ; Lock parent to avoid flicker
      INVOKE     SendMessage, hREdit, EM_GETFIRSTVISIBLELINE, 0, 0
         mov     TopLine, eax
         mov     CenLine, eax
      INVOKE     SendMessage, hREdit, EM_LINEINDEX, -1, 0
      INVOKE     SendMessage, hREdit, EM_EXLINEFROMCHAR, 0, eax
         mov     CurLine, eax
         mov     LineNum, eax
         mov     ecx, NScrL
         shr     ecx, 1
         add     CenLine, ecx
         mov     edx, CurLine
         sub     edx, CenLine
      INVOKE     SendMessage, hREdit, EM_LINESCROLL, 0, edx
      INVOKE     LockWindowUpdate, 0              ; Unlock parent
      INVOKE     SetFocus, hREdit
      .if Bypass
            ret
      .endif

NoCenter:
      INVOKE     SendMessage, hREdit, EM_LINEINDEX, -1, 0
      INVOKE     SendMessage, hREdit, EM_POSFROMCHAR, addr pt, eax
      INVOKE     GetClientRect, hREdit, addr Srect
         mov     eax, pt.y
         add     eax, w1
         sub     eax, 4                           ; 1/2 height of hSel
         add     Srect.top, eax
      .if LineOn
            add     Srect.left, 37 ;40
      .endif
;         mov     SelOn, 1
      INVOKE     SetParent, hSel, hREdit
      INVOKE     MoveWindow, hSel, Srect.left, Srect.top, 9, 9, TRUE

      .if ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm' ;&& SPos > eax
         INVOKE     WriteReadMem, 4, 8
         .if WorkBuff
            INVOKE     lstrcat, addr WorkBuff, addr szPROC
         .endif
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 2, addr WorkBuff
      .else
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 2, addr szNULL
      .endif

         ret
CenterSel  ENDP

;==============================================================
; Change Font PROCEDURE
;==============================================================
ChgFont  PROC
LOCAL    cf:CHOOSEFONT
LOCAL    pt:POINT
LOCAL    Cnt:DWORD, ID, hDC
LOCAL    szBuff[256]:BYTE, szWork[2]:BYTE 

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

      .if FontCode == 1
            mov     ecx, Color.EditTC
      .elseif FontCode == 2
            mov     ecx, Color.LinebarTC
      .elseif FontCode == 3
            mov     ecx, Color.TreeListTC
      .else
            mov     ecx, Color.EditTC
      .endif

;---------- [Set the CHOOSEFONT attributes] ----------
         mov     cf.lStructSize, sizeof cf
         mov     eax, hWnd
         mov     cf.hwndOwner, eax
         mov     eax, hInst
         mov     cf.hInstance, eax
         xor     edx, edx
      .if FontCode == 1
            mov     cf.lpLogFont, offset FontEdit
      .elseif FontCode == 2
            mov     cf.lpLogFont, offset FontLine
      .elseif FontCode == 3
            mov     cf.lpLogFont, offset FontTree
      .else
            mov     cf.lpLogFont, offset FontPrint
            mov     cf.nSizeMin, 6
            mov     cf.nSizeMax, 32
            mov     edx, CF_LIMITSIZE
      .endif
         mov     cf.Flags, CF_SCREENFONTS or CF_INITTOLOGFONTSTRUCT or\
                 CF_FORCEFONTEXIST or CF_EFFECTS
          or     cf.Flags, edx
         mov     cf.rgbColors, ecx
      INVOKE     ChooseFont, addr cf   ; INVOKE common ChooseFont dialog
         cmp     eax, FALSE
          je     FontRet
      INVOKE     MoveWindow, hSel, 0, 0, 0, 0, TRUE
         mov     ecx, cf.rgbColors

;---------- [Create a Font] ----------
      .if FontCode == 1
            mov     Color.EditTC, ecx
         INVOKE     DeleteObject, hFont
         INVOKE     DeleteObject, hFontB
         INVOKE     DeleteObject, hFontI
         INVOKE     DeleteObject, hFontBI

           push     FontEdit.lfWeight
            mov     FontEdit.lfWeight, 600
         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFontB, eax
            mov     Font.hFontB, eax

          movzx     eax, byte ptr FontEdit.lfItalic
           push     eax
            mov     FontEdit.lfItalic, TRUE
         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFontBI, eax
            mov     Font.hFontBI, eax
            pop     eax
            mov     FontEdit.lfItalic, al
            pop     FontEdit.lfWeight

          movzx     eax, byte ptr FontEdit.lfItalic
           push     eax
            mov     FontEdit.lfItalic, TRUE
         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFontI, eax
            mov     Font.hFontI, eax
            pop     eax
            mov     FontEdit.lfItalic, al

         INVOKE     CreateFontIndirect, addr FontEdit
            mov     hFont, eax
            mov     Font.hFont, eax

      .elseif FontCode == 2
;            mov     Color.LinebarTC, ecx
         INVOKE     DeleteObject, hFontL
         INVOKE     CreateFontIndirect, addr FontLine
            mov     hFontL, eax
            mov     Font.hFontL, eax
      .elseif FontCode == 3
            mov     Color.TreeListTC, ecx
         INVOKE     DeleteObject, hFontTL
         INVOKE     CreateFontIndirect, addr FontTree
            mov     hFontTL, eax
         INVOKE     SendMessage, hWndTree, WM_SETFONT, hFontTL, TRUE
         INVOKE     SendMessage, hWndList, WM_SETFONT, hFontTL, TRUE
      .else
         .if FontPrint.lfWeight == 700
               mov     FontPrint.lfWeight, 600
         .endif
         .if sdword ptr FontPrint.lfHeight < -9
               inc     FontPrint.lfHeight
         .endif
      .endif
      INVOKE     SetValues, UM_SETFONTS, 0, addr Font
      INVOKE     SetValues, UM_SETCOLORS, 0, addr Color
      INVOKE     SendMessage, hEdit, UM_SETCOLORS, 0, addr Color
      INVOKE     SendMessage, hWndTree, TVM_SETTEXTCOLOR, 0, Color.TreeListTC
      INVOKE     SendMessage, hWndList, LVM_SETTEXTCOLOR, 0, Color.TreeListTC
      INVOKE     RedrawWindow, hWndList, 0, 0, RDW_ERASE or RDW_INVALIDATE

FontRet:

      INVOKE     SetFocus, hREdit
         ret

ChgFont    ENDP

;===================================================
; Keyword maint Dialog PROCEDURE
;===================================================
KeywordMaint PROC uses ebx esi hdlg:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    Len:DWORD, Cnt, Incr
LOCAL    szBuff0[64]:BYTE

      .if wMsg == WM_INITDIALOG
          MOVmd     hKeywordMaint, hdlg
          MOVmd     TempCode, lParam
         INVOKE     GetDlgItem, hdlg, 201
            mov     hListBox01, eax
         INVOKE     GetDlgItem, hdlg, 202
            mov     hListBox02, eax

         .if TempCode
            INVOKE     SetWindowText, hdlg, addr szFiltMaint
            INVOKE     SendDlgItemMessage, hdlg, 102, WM_SETTEXT, 0, addr szUF01
            INVOKE     SendDlgItemMessage, hdlg, 104, WM_SETTEXT, 0, addr szUF02
            INVOKE     SendMessage, hListBox01, WM_SETFONT, hFontBLD, TRUE
            INVOKE     SendMessage, hListBox02, WM_SETFONT, hFontBLD, TRUE
            INVOKE     GetWindowRect, hREdit, addr rect
               add     rect.left, 2
               add     rect.top, 2
            INVOKE     SetWindowPos, hdlg, HWND_NOTOPMOST, rect.left, rect.top, 0, 0,\
                       SWP_NOSIZE or SWP_NOZORDER
         .endif

         INVOKE     GetDlgItem, hdlg, 401
            mov     h51, eax
         INVOKE     GetDlgItem, hdlg, 402
            mov     h52, eax
         INVOKE     GetDlgItem, hdlg, 403
            mov     h53, eax
         INVOKE     GetDlgItem, hdlg, 404
            mov     h54, eax
         INVOKE     GetDlgItem, hdlg, 501
            mov     h55, eax
         INVOKE     GetDlgItem, hdlg, IDCANCEL
            mov     h56, eax

         INVOKE     EnableWindow, h52, 0
         INVOKE     EnableWindow, h54, 0

         .if TempCode
               lea     esi, offset UserFilt01
         .else
               lea     esi, offset Userkeyw01
         .endif
            xor     eax, eax

Getlen01:
         .if byte ptr[esi+eax] == 2ch
               mov     Len, eax
               inc     Len 
            INVOKE     lstrcpyn, addr szBuff0, esi, Len
            INVOKE     SendMessage, hListBox01, LB_ADDSTRING, 0, addr szBuff0
               add     esi, Len
               xor     eax, eax
               jmp     Getlen01
         .elseif byte ptr[esi+eax] == 0h
            INVOKE     SendMessage, hListBox01, LB_SETSEL, TRUE, 0
               jmp     Loaded02
         .endif
            inc     eax
            jmp     Getlen01

Loaded02:
         .if TempCode
               lea     esi, offset UserFilt02
         .else
               lea     esi, offset Userkeyw02
         .endif
            xor     eax, eax

Getlen02:
         .if byte ptr[esi+eax] == 2ch
               mov     Len, eax
               inc     Len 
            INVOKE     lstrcpyn, addr szBuff0, esi, Len
            INVOKE     SendMessage, hListBox02, LB_ADDSTRING, 0, addr szBuff0
               add     esi, Len
               xor     eax, eax
               jmp     Getlen02
         .elseif byte ptr[esi+eax] == 0h
            INVOKE     SendMessage, hListBox02, LB_SETSEL, TRUE, 0
               jmp     LoadDone
         .endif
            inc     eax
            jmp     Getlen02

LoadDone:
      .elseif wMsg == WM_CTLCOLORDLG
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLORLISTBOX || wMsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
            mov     ebx, eax
            shr     ebx, 16
           cwde

         .if ebx == BN_CLICKED
            INVOKE     GetFocus
            INVOKE     GetDlgCtrlID, eax
         .endif

;---------- [For Catagory files] ----------
         .if eax == 201 && ebx == LBN_SELCHANGE
            INVOKE     SendMessage, hListBox01, LB_GETCURSEL, 0, 0
            .if eax != LB_ERR
                  mov     ecx, eax
               INVOKE     SendMessage, hListBox01, LB_GETTEXT, ecx, addr szBuff0
               INVOKE     SetDlgItemText, hdlg, 301, addr szBuff0
               INVOKE     EnableWindow, h52, 1
            .endif

         .elseif eax == 202 && ebx == LBN_SELCHANGE
            INVOKE     SendMessage, hListBox02, LB_GETCURSEL, 0, 0
            .if eax != LB_ERR
                  mov     ecx, eax
               INVOKE     SendMessage, hListBox02, LB_GETTEXT, ecx, addr szBuff0
               INVOKE     SetDlgItemText, hdlg, 302, addr szBuff0
               INVOKE     EnableWindow, h54, 1
            .endif

         .elseif eax == 301
            INVOKE     GetDlgItemText, hdlg, 301, addr szBuff0, sizeof szBuff0
            .if !eax
               INVOKE     EnableWindow, h52, 0
               INVOKE     SendMessage, hListBox01, LB_SETCURSEL, -1, 0
            .endif

         .elseif eax == 302
            INVOKE     GetDlgItemText, hdlg, 302, addr szBuff0, sizeof szBuff0
            .if !eax
               INVOKE     EnableWindow, h54, 0
               INVOKE     SendMessage, hListBox02, LB_SETCURSEL, -1, 0
            .endif

         .elseif eax == 401          ; Add 01
            INVOKE     GetDlgItemText, hdlg, 301, addr szBuff0, sizeof szBuff0
            .if eax
               INVOKE     SendMessage, hListBox01, LB_FINDSTRING, -1, addr szBuff0
               .if eax == LB_ERR
                  INVOKE     SendMessage, hListBox01, LB_ADDSTRING, 0, addr szBuff0
               .endif
                  mov     szBuff0, 0
               INVOKE     SetDlgItemText, hdlg, 301, addr szBuff0
               INVOKE     EnableWindow, h52, 0
            .endif

         .elseif eax == 402          ; Delete 01
            INVOKE     GetDlgItemText, hdlg, 301, addr szBuff0, sizeof szBuff0
            INVOKE     SendMessage, hListBox01, LB_FINDSTRING, -1, addr szBuff0
            .if eax != LB_ERR
               INVOKE     SendMessage, hListBox01, LB_DELETESTRING, eax, 0
                  mov     szBuff0, 0
               INVOKE     SetDlgItemText, hdlg, 301, addr szBuff0
               INVOKE     EnableWindow, h52, 0
            .endif

         .elseif eax == 403          ; Add 02
            INVOKE     GetDlgItemText, hdlg, 302, addr szBuff0, sizeof szBuff0
            .if eax
               INVOKE     SendMessage, hListBox02, LB_FINDSTRING, -1, addr szBuff0
               .if eax == LB_ERR
                  INVOKE     SendMessage, hListBox02, LB_ADDSTRING, 0, addr szBuff0
               .endif
                  mov     szBuff0, 0
               INVOKE     SetDlgItemText, hdlg, 302, addr szBuff0
               INVOKE     EnableWindow, h54, 0
            .endif

         .elseif eax == 404          ; Delete 02

            INVOKE     GetDlgItemText, hdlg, 302, addr szBuff0, sizeof szBuff0
            INVOKE     SendMessage, hListBox02, LB_FINDSTRING, -1, addr szBuff0
            .if eax != LB_ERR
               INVOKE     SendMessage, hListBox02, LB_DELETESTRING, eax, 0
                  mov     szBuff0, 0
               INVOKE     SetDlgItemText, hdlg, 302, addr szBuff0
               INVOKE     EnableWindow, h54, 0
            .endif

         .elseif eax == 501
            INVOKE     SendMessage, hListBox01, LB_GETCOUNT, 0, 0
            .if eax != LB_ERR
               .if TempCode
                     mov     UserFilt01, 0
               .else
                     mov     Userkeyw01, 0
               .endif
                  and     Incr, 0
                  mov     Cnt, eax






               .while (Cnt)
                  INVOKE     SendMessage, hListBox01, LB_GETTEXT, Incr, addr szBuff0
                  .if TempCode
                     INVOKE     lstrcat, addr UserFilt01, addr szBuff0
                     INVOKE     lstrcat, addr UserFilt01, addr szCom
                  .else
                     INVOKE     lstrcat, addr Userkeyw01, addr szBuff0
                     INVOKE     lstrcat, addr Userkeyw01, addr szCom
                  .endif
                     inc     Incr
                     dec     Cnt
               .endw
            .endif

            INVOKE     SendMessage, hListBox02, LB_GETCOUNT, 0, 0
            .if eax != LB_ERR
               .if TempCode
                     mov     UserFilt02, 0
               .else
                     mov     Userkeyw02, 0
               .endif
                  and     Incr, 0
                  mov     Cnt, eax
               .while (Cnt)
                  INVOKE     SendMessage, hListBox02, LB_GETTEXT, Incr, addr szBuff0
                  .if TempCode
                     INVOKE     lstrcat, addr UserFilt02, addr szBuff0
                     INVOKE     lstrcat, addr UserFilt02, addr szCom
                  .else
                     INVOKE     lstrcat, addr Userkeyw02, addr szBuff0
                     INVOKE     lstrcat, addr Userkeyw02, addr szCom
                  .endif
                     inc     Incr
                     dec     Cnt
               .endw
            .endif
               jmp     GetOut

         .elseif eax == IDCANCEL
               jmp     GetOut
         .endif

      .elseif wMsg == WM_CLOSE

GetOut:
            and     hKeywordMaint, 0
         INVOKE     EndDialog, hdlg, 0
            mov     eax, TRUE
            ret
      .endif

Ret0:
         xor     eax, eax
         ret

KeywordMaint ENDP

;===============================================================

; Color PROCEDURE
;===============================================================
ChgColor PROC uses ebx esi edi hdlg:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    cc:CHOOSECOLOR
LOCAL    hDC:DWORD, Ctrl, Incr, hNewBrush, Cnt, Len, hTemp
LOCAL    szBuff0[1024]: BYTE

      .if wMsg == WM_INITDIALOG              ; If message is INITDIALOG then
         INVOKE     GetDlgItem, hdlg, 901
            mov     hEdit, eax
         INVOKE     SendMessage, hEdit, UM_HTMLCOLOR, 0, addr Color01+64
         INVOKE     SendMessage, hEdit, UM_SETFONTS, 0, addr Font
         INVOKE     SendMessage, hEdit, UM_SHOWLINES, 1, 0
         INVOKE     SendMessage, hEdit, UM_ITALIC, ItalicOn, 0
            and     SaveCode, 0
         INVOKE     GetDlgItem, hdlg, 802
            mov     hTemp, eax
         INVOKE     EnableWindow, hTemp, 0

         INVOKE     GetDlgItem, hdlg, 801
            mov     h47, eax
         INVOKE     GetDlgItem, hdlg, 802
            mov     h48, eax
         INVOKE     GetDlgItem, hdlg, 803
            mov     h49, eax
         INVOKE     GetDlgItem, hdlg, 804
            mov     h50, eax

      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_PAINT || wMsg == WM_MOVE
         INVOKE     PostMessage, hColor, WM_COMMAND, 200, 0
         .if PropOn
            INVOKE     ShowWindow, hWndFunct, SW_HIDE
            INVOKE     ShowWindow, hWndFunct, SW_SHOWDEFAULT
         .endif

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
            and     eax, 0ffffh
            mov     wParam, eax
            mov     ebx, wParam
            shr     ebx, 16

         .if wParam >= 201 && wParam <= 361 ;352 ;342
            INVOKE     SetFocus, lParam
         .endif

         .if ebx == BN_CLICKED && wParam != 200
            INVOKE     GetFocus
            INVOKE     GetDlgCtrlID, eax
            .if !eax
                  mov     eax, wParam
            .endif
         .endif

         .if eax == 200
              call     PaintColors

         .elseif eax > 200 && eax < 227
               and     SaveText, 0
               mov     SaveCode, eax
               sub     eax, 201
               mov     edi, eax
               mov     esi, Color.EditBC[eax*4]
              call     DoColor
            .if SaveCode == 207 ; or RDW_INTERNALPAINT
               INVOKE     RedrawWindow, hdlg, 0, 0, RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW
                 call     PaintColors
            .else
               INVOKE     SendMessage, hEdit, UM_HTML, 0, 0
               INVOKE     SendMessage, hEdit, WM_SETTEXT, 0, addr szTestTxt
            .endif

         .elseif eax > 242 && eax < 261
               and     SaveText, 0
               mov     SaveCode, eax
               sub     eax, 227
               mov     edi, eax
               mov     esi, Color01[eax*4]
              call     DoColor
            INVOKE     SendMessage, hEdit, UM_HTML, 1, 0
            INVOKE     SendMessage, hEdit, WM_SETTEXT, 0, addr szTestHtml

         .elseif eax > 226 && eax < 243
               and     SaveText, 0
               mov     SaveCode, eax
               sub     eax, 227
               mov     edi, eax
               mov     esi, Color01[eax*4]
              call     DoColor

ResetChg:
            INVOKE     SendMessage, hEdit, UM_HTMLCOLOR, 0, addr Color01+64
               xor     esi, esi
               mov     Cnt, 16
            .while (Cnt)
                  mov     ecx, Color01[esi*4]
                  mov     edx, KeyArray[esi*4]
               INVOKE     SendMessage, hREdit, UM_SETSYNTAXWORDS, ecx, edx
                  inc     esi
                  dec     Cnt
            .endw

DisplayTxt:
               mov     esi, KeyArray[edi*4]
               lea     edi,  szBuff0
               and     Cnt, 0
            INVOKE     lstrlen, esi
               mov     ecx, eax ;1023
            .while (ecx)
                  inc     Cnt
                  mov     al, byte ptr[esi]
                  mov     byte ptr[edi], al
               .if Cnt > 25 && al == ','
                     mov     byte ptr[edi], 0dh
                     and     Cnt, 0
               .endif
                  inc     esi
                  inc     edi
                  dec     ecx
            .endw

               mov     dword ptr[edi-1], 00000a0dh
            INVOKE     SendMessage, hEdit, UM_HTML, 0, 0
            INVOKE     SendMessage, hEdit, WM_SETTEXT, 0, addr szBuff0

         .elseif eax > 300 && eax < 327
               and     SaveText, 0
            .if eax != 307
               INVOKE     SendMessage, hEdit, UM_HTML, 0, 0
               INVOKE     SendMessage, hEdit, WM_SETTEXT, 0, addr szTestTxt
            .endif
            .if wParam > 311 && wParam < 317
                  sub     wParam, 311
               INVOKE     SendMessage, hEdit, UM_SETHILITELINE, 2, wParam
            .endif
            .if wParam == 302 || wParam == 309
               INVOKE     SendMessage, hEdit, EM_LINEINDEX, 2, 0
                  mov     cr.cpMin, eax
                  add     eax, 20
                  mov     cr.cpMax, eax
               INVOKE     SendMessage, hEdit, EM_EXSETSEL, 0, addr cr
            .endif
            .if wParam == 307
               INVOKE     RedrawWindow, hdlg, 0, 0, RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW
                 call     PaintColors
            .endif

         .elseif eax > 326 && eax < 343
               mov     SaveText, eax
               sub     eax, 327
               mov     edi, eax
               jmp     DisplayTxt

         .elseif eax > 342 && eax < 361
               and     SaveText, 0
            INVOKE     SendMessage, hEdit, UM_HTML, 1, 0
            INVOKE     SendMessage, hEdit, WM_SETTEXT, 0, addr szTestHtml

         .elseif eax == 801                 ; Defaults
            INVOKE     SendMessage, hEdit, WM_SETTEXT, 0, addr szNULL
               lea     esi, DefColor
               lea     edi, Color.EditBC
               mov     ecx, 28
            .while (ecx)
                  mov     eax, dword ptr[esi]
                  mov     dword ptr[edi], eax
                  add     esi, 4
                  add     edi, 4
                  dec     ecx
            .endw
               lea     esi, DefColor01
               lea     edi, Color01
               mov     ecx, 34 ;26 ;16
            .while (ecx)
                  mov     eax, dword ptr[esi]
                  mov     dword ptr[edi], eax
                  add     esi, 4
                  add     edi, 4
                  dec     ecx


            .endw
               lea     esi, DefCustColor
               lea     edi, CustClrs
               mov     ecx, 16
            .while (ecx)
                  mov     eax, [esi]
                  mov     [edi], eax
                  add     esi, 4
                  add     edi, 4
                  dec     ecx
            .endw
            INVOKE     SendMessage, hEdit, UM_HTMLCOLOR, 0, addr Color01+64
               xor     esi, esi
               mov     Cnt, 16
            .while (Cnt)
                  mov     ecx, Color01[esi*4]
                  mov     edx, KeyArray[esi*4]
               INVOKE     SendMessage, hREdit, UM_SETSYNTAXWORDS, ecx, edx
                  inc     esi
                  dec     Cnt
            .endw

              call     SetColors
;            INVOKE     RedrawWindow, hdlg, 0, 0, RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW
              call     PaintColors

         .elseif eax == 802 && SaveCode     ; Undo last change
               mov     esi, ColorRes
               mov     edi, IncrRes
               mov     eax, SaveCode
               mov     wParam, eax
               and     SaveCode, 0
            INVOKE     GetDlgItem, hdlg, 802
               mov     hTemp, eax
            INVOKE     EnableWindow, hTemp, 0
              call     UndoChg
            .if wParam > 225 && wParam < 238
                  jmp     ResetChg
            .endif

         .elseif eax == 803                 ; Close
               jmp     CloseIt

         .elseif eax == 804
            INVOKE     DialogBoxParam, hInst, IDD_KWMAINT, hColor, addr KeywordMaint, 0
            .if SaveText == 341 || SaveText == 342
                  mov     edi, SaveText
                  sub     edi, 327
;                  and     SaveText, 0
                  jmp     DisplayTxt
            .endif
         .endif

      .elseif wMsg == WM_CLOSE
            jmp     CloseIt
      .endif
         jmp     ColorDone

PaintColors:
         xor     esi, esi
         mov     Ctrl, 201
         mov     Cnt, 60 ;52 ;42 ;40 ;37
      .while (Cnt)
         INVOKE     GetDlgItem, hdlg, Ctrl
            mov     hTemp, eax
         INVOKE     GetDC, hTemp
            mov     hDC, eax
         .if Cnt > 34 ;26 ;16 ;14
            INVOKE     CreateSolidBrush, Color.EditBC[esi]
         .else
            INVOKE     CreateSolidBrush, Color01[esi]
         .endif
            mov     hNewBrush, eax
         INVOKE     GetClientRect, hTemp, addr rect
         INVOKE     FillRect, hDC, addr rect, hNewBrush
         INVOKE     DeleteObject, hNewBrush
         INVOKE     DeleteDC, hDC
            add     esi, 4
         .if Cnt == 35 ;27 ;17 ;15
               xor     esi, esi
         .endif
            inc     Ctrl
            dec     Cnt
      .endw
      INVOKE     UpdateWindow, hColor
        retn

DoColor:
;---------- [Set the CHOOSECOLOR attributes] ----------
      .if SaveCode
         INVOKE     GetDlgItem, hdlg, 802
            mov     hTemp, eax
         INVOKE     EnableWindow, hTemp, 1
      .endif
         mov     ColorRes, esi
         mov     IncrRes, edi
         mov     edx, esi
         and     esi, 00ffffffh
         and     edx, 0ff000000h
        push     edx
         mov     cc.lStructSize, sizeof cc
         mov     eax, hWnd
         mov     cc.hwndOwner, eax
         mov     eax, hInst
         mov     cc.hInstance, eax
         mov     cc.rgbResult, esi
         mov     cc.lpCustColors, offset CustClrs
         mov     cc.Flags, CC_FULLOPEN or CC_RGBINIT
      INVOKE     ChooseColor, addr cc
         pop     edx
      .if !eax                                ; Cancel'ed or error occurred
         INVOKE     SetFocus, hColor
            jmp     ColorRet
      .endif
         mov     esi, cc.rgbResult
         add     esi, edx

UndoChg:
      .if wParam < 226
            mov     Color.EditBC[edi*4], esi
      .else
            mov     Color01[edi*4], esi
      .endif

SetColors:
      INVOKE     DeleteObject, hSavBRM
      INVOKE     CreateSolidBrush, Color.TreeListBC
         mov     hSavBRM, eax
      INVOKE     DeleteObject, hBRD
      INVOKE     CreateSolidBrush, Color.DialogBC
         mov     hBRD, eax
;;      INVOKE     SendMessage, hREdit, UM_SETCOLORS, 0, addr Color
      INVOKE     SetValues, UM_SETCOLORS, 0, addr Color
      INVOKE     SendMessage, hEdit, UM_HTMLCOLOR, 0, addr Color01+64
      INVOKE     SendMessage, hEdit, UM_SETCOLORS, 0, addr Color
      INVOKE     SendMessage, hWndTree, TVM_SETTEXTCOLOR, 0, Color.TreeListTC
      INVOKE     SendMessage, hWndTree, TVM_SETBKCOLOR, 0, Color.TreeListBC
      INVOKE     SendMessage, hWndList, LVM_SETTEXTCOLOR, 0, Color.TreeListTC
      INVOKE     SendMessage, hWndList, LVM_SETTEXTBKCOLOR, 0, Color.TreeListBC
      INVOKE     SendMessage, hWndList, LVM_SETBKCOLOR, 0, Color.TreeListBC
      INVOKE     RedrawWindow, hWndList, 0, 0, RDW_ERASE or RDW_INVALIDATE
      INVOKE     RedrawWindow, hColor, 0, 0, RDW_INVALIDATE or RDW_INTERNALPAINT
      INVOKE     UpdateWindow, hColor
      INVOKE     SetFocus, hColor
        retn

CloseIt:
         and     hColor, 0
         and     hWndDlg, 0
         and     SaveCode, 0
         and     SaveText, 0
      INVOKE     SetFocus, hREdit
      INVOKE     DestroyWindow, hdlg     ; End the dialog
         mov     eax, TRUE               ; Return
         jmp     ColorRet                ; with TRUE

ColorDone:
         mov     eax, FALSE              ; Return with FALSE

ColorRet:
         ret

ChgColor ENDP

;===================================================
; Check for special key   CR, LF, etc.
;===================================================
ChkKey PROC

      .if dwwParam == 08h
            mov     word ptr szAscii, 'SB'
            mov     szAscii+2, 0
      .elseif dwwParam == 09h
            mov     word ptr szAscii, 'TH'
            mov     szAscii+2, 0
      .elseif dwwParam == 0ah
            mov     word ptr szAscii, 'FL'
            mov     szAscii+2, 0
      .elseif dwwParam == 0dh
            mov     word ptr szAscii, 'RC'
            mov     szAscii+2, 0
      .elseif dwwParam == 10h
            mov     dword ptr szAscii, ' FHS'
            mov     szAscii+3, 0
      .elseif dwwParam == 11h
            mov     dword ptr szAscii, ' LTC'
            mov     szAscii+3, 0
      .elseif dwwParam == 14h
            mov     dword ptr szAscii, ' L/C'
            mov     szAscii+3, 0
      .elseif dwwParam == 1bh
            mov     dword ptr szAscii, ' CSE'
            mov     szAscii+3, 0
      .elseif dwwParam == 20h
            mov     word ptr szAscii, 'PS'
            mov     szAscii+2, 0
      .elseif dwwParam == 21h
            mov     dword ptr szAscii, ' PUP'
            mov     szAscii+3, 0
      .elseif dwwParam == 22h
            mov     dword ptr szAscii, ' NDP'
            mov     szAscii+3, 0
      .elseif dwwParam == 23h
            mov     dword ptr szAscii, ' DNE'
            mov     szAscii+3, 0
      .elseif dwwParam == 24h
            mov     dword ptr szAscii, ' MOH'
            mov     szAscii+3, 0
      .elseif dwwParam == 25h
            mov     dword ptr szAscii, ' TLL'
            mov     szAscii+3, 0
      .elseif dwwParam == 26h
            mov     dword ptr szAscii, ' PUL'
            mov     szAscii+3, 0
      .elseif dwwParam == 27h
            mov     dword ptr szAscii, ' TRL'
            mov     szAscii+3, 0
      .elseif dwwParam == 28h
            mov     dword ptr szAscii, ' NDL'
            mov     szAscii+3, 0
      .elseif dwwParam == 2dh && dwlParam != 4ah
            mov     dword ptr szAscii, ' SNI'
            mov     szAscii+3, 0
      .elseif dwwParam == 2eh
            mov     dword ptr szAscii, 'LEDD'
            mov     szAscii+4, 0
      .elseif dwlParam == 145h && dwwParam == 90h
            mov     dword ptr szAscii, ' L/N'
            mov     szAscii+4, 0
      .elseif dwlParam == 46h && dwwParam == 91h
            mov     dword ptr szAscii, ' L/S'
            mov     szAscii+4, 0
      .elseif dwlParam == 45h && dwwParam == 13h
            mov     dword ptr szAscii, ' B/P'
            mov     szAscii+4, 0
      .endif
         ret

ChkKey ENDP

;===================================================
; Ascii sub class PROCEDURE
;===================================================
AsciiProc PROC hwnd:DWORD, wMsg, wParam, lParam

      .if wMsg == WM_CHAR || wMsg == WM_KEYDOWN
          MOVmd     dwMsg, wMsg
          MOVmd     dwwParam, wParam
         INVOKE     BaseAscii, wParam, addr szDec, 0, 10, 0, 0, 1
         INVOKE     BaseAscii, wParam, addr szHex, 0, 16, 0, 0, 1
            mov     eax, hwnd
         .if eax == hAsciiBox
               mov     szAscii, 0
               mov     eax, lParam
               shr     eax, 16
               mov     dwlParam, eax
              push     eax
            .if eax >= 47h && eax <= 53h || eax >= 147h && eax <= 153h || eax == 1ch || eax == 11ch ||\
                dwlParam == 145h && dwwParam == 90h || dwlParam == 46h && dwwParam == 91h ||\
                dwlParam == 45h && dwwParam == 13h || dwwParam == 8h || dwwParam == 9h || dwwParam == 20h
                 call     ChkKey
            .elseif dwlParam == 2ah && dwwParam == 10h || dwlParam == 36h && dwwParam == 10h ||\
                dwlParam == 1dh && dwwParam == 11h || dwlParam == 11dh && dwwParam == 11h ||\
                dwlParam == 1h && dwwParam == 1bh || dwlParam == 3ah && dwwParam == 14h
                 call     ChkKey
            .endif
               pop     eax
            .if wParam == 2dh && eax != 152h
;                  mov     szAscii, 0
            .endif
            .if szAscii
               INVOKE     SendMessage, hAsciiBox, WM_SETTEXT, NULL, addr szAscii
                  mov     dwMsg, 0
                  jmp     EndIt
            .endif
         .endif
         INVOKE     SendMessage, hAsciiBox, EM_SETSEL, 0, -1
      .endif

EndIt:
       INVOKE        CallWindowProc, lpAsciiBox, hwnd, wMsg, wParam, lParam
         ret
AsciiProc ENDP

;===================================================
; Alt + Num Pad PROCEDURE
;===================================================
AltNumPad PROC uses ebx hwnd:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    szWork[10]:BYTE

      .if wMsg == WM_RBUTTONDOWN
            jmp     PopUp

      .elseif wMsg == WM_SYSKEYDOWN
         .if wParam == 12h
               and     w5, 0
               mov     szAscii, 0
               mov     szUnicode, 0
         .endif
         .if wParam != 12h && wParam >= 60h && wParam <= 69h
            INVOKE     BaseAscii, wParam, addr szWork, 2, 16, 0, 1, 1
            INVOKE     lstrcat, addr szAscii, addr szWork
            INVOKE     SendMessage, hOutput, WM_SETTEXT, NULL, addr szAscii
               mov     ecx, wParam
               sub     ecx, 60h
            INVOKE     BaseAscii, ecx, addr szWork, 1, 16, 0, 1, 1
            INVOKE     lstrcat, addr szUnicode, addr szWork
            INVOKE     SendMessage, hUnicode, WM_SETTEXT, NULL, addr szUnicode
            INVOKE     SendMessage, hUnicode, WM_GETTEXT, sizeof szWork, addr szWork
            INVOKE     AsciiBase, addr szWork, addr w5, 16
         .endif

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
           cwde
         .if eax == 601
            INVOKE     SendMessage, hALT, WM_CUT, 0 ,0

         .elseif eax == 602
            INVOKE     SendMessage, hALT, WM_COPY, 0 ,0
      INVOKE     OpenClipboard, hALT
      INVOKE     GetClipboardData, CF_TEXT ;CF_UNICODETEXT
         mov     ebx, eax
      INVOKE     CloseClipboard
      INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, ebx

jmp     Pass
xor     edx, edx
mov     cl, [ebx+edx]
;DSPValue hWnd, ecx, 1, 'm'
inc     edx
mov     cl, [ebx+edx]
;DSPValue hWnd, ecx, 1, 'm'
inc     edx
mov     cl, [ebx+edx]
;DSPValue hWnd, ecx, 1, 'm'
inc     edx
mov     cl, [ebx+edx]
;DSPValue hWnd, ecx, 1, 'm'
inc     edx

;MultiByteToWideChar
;INVOKE     WideCharToMultiByte, CP_ACP, 0, ecx, -1, addr szWork, 9, 0, 0
Pass:

         .elseif eax == 603
            INVOKE     SendMessage, hALT, WM_PASTE, 0 ,0

         .elseif eax == 604
            INVOKE     SendMessage, hALT, EM_SETSEL, 0, -1

         .elseif eax == 605
            INVOKE     SendMessage, hALT, WM_SETTEXT, 0, offset szCR
         .endif
      .endif
         jmp     ThatsAll

PopUp:
      INVOKE     GetWindowRect, hwnd, addr rect  ;hWorkArea
         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, 0 ;10 
         add     ecx, 0 ;20
      INVOKE     TrackPopupMenu, hWMenu, TPM_LEFTALIGN or TPM_LEFTBUTTON, ebx, ecx, 0, hALT, addr rect
        jmp      ThatsAll

ThatsAll:
       INVOKE        CallWindowProc, lpALT, hwnd, wMsg, wParam, lParam
         ret
AltNumPad ENDP

;===================================================
; Translate PROCEDURE
;===================================================
Translate PROC  uses ebx esi hdlg:DWORD, wMsg, wParam, lParam
LOCAL    Num:DWORD, dwStyle, Var1, Var2
LOCAL    szWork[10]:BYTE

      .if wMsg == WM_INITDIALOG      ; If message is INITDIALOG then
         INVOKE     CheckDlgButton, hdlg, 31, BST_CHECKED   ; Sets Hex type
         INVOKE     GetDlgItem, hdlg, 401
            mov     hAsciiBox, eax
         INVOKE     GetDlgItem, hdlg, 402
            mov     hInput, eax
         INVOKE     GetDlgItem, hdlg, 405
            mov     hALT, eax
         INVOKE     GetDlgItem, hdlg, 406
            mov     hOutput, eax
         INVOKE     GetDlgItem, hdlg, 407
            mov     hUnicode, eax
         INVOKE     SetWindowLong, hAsciiBox, GWL_WNDPROC, AsciiProc
            mov     lpAsciiBox, eax
         INVOKE     SetWindowLong, hInput, GWL_WNDPROC, AsciiProc
            mov     lpAsciiBox, eax
         INVOKE     SetWindowLong, hALT, GWL_WNDPROC, AltNumPad
            mov     lpALT, eax
         INVOKE     SendMessage, hALT, EM_LIMITTEXT, 1, 0
         INVOKE     SendMessage, hAsciiBox, WM_SETFONT, hFontTB, TRUE
         INVOKE     SendMessage, hInput, WM_SETFONT, hFontTB, TRUE
            mov     HexDec, 16
         INVOKE     SetFocus, hAsciiBox

      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
           cwde
         .if eax == 31 || eax == 32
               mov     dwStyle, WS_CHILD or WS_VISIBLE or ES_UPPERCASE or ES_CENTER
               mov     Var1, 2
               mov     Var2, 404
            .if eax == 31
                  mov     HexDec, 16
            .else
                  mov     HexDec, 10
                   or     dwStyle, ES_NUMBER
                  mov     Var1, 3
                  mov     Var2, 403
            .endif
            INVOKE     SetWindowLong, hInput, GWL_STYLE, dwStyle
            INVOKE     SendMessage, hInput, EM_LIMITTEXT, Var1, 0 ; Limit text size
            INVOKE     GetDlgItemText, hdlg, Var2, addr szWork, sizeof szWork
              push     eax
            INVOKE     SetDlgItemText, hdlg, 402, addr szWork
               pop     eax
            INVOKE     SendMessage, hInput, EM_SETSEL, eax, eax
            INVOKE     SetFocus, hInput

         .elseif eax == 401 && dwMsg == WM_CHAR || eax == 401 && dwMsg == WM_KEYDOWN
            INVOKE     SetDlgItemText, hdlg, 403, addr szDec
            INVOKE     SetDlgItemText, hdlg, 404, addr szHex
               mov     szHex, 0
            INVOKE     SetDlgItemText, hdlg, 402, addr szHex

         .elseif eax == 402 && dwMsg == WM_CHAR || eax == 402 && dwMsg == WM_KEYDOWN
            INVOKE     GetDlgItemText, hdlg, 402, addr szWork, sizeof szWork

;---------- [Validate the user input characters] ----------
               mov     Num, eax
               cmp     HexDec, 10
                je     NoValidate
               xor     esi, esi
            .while (eax)
                  mov     bl, byte ptr szWork[esi]
               .if bl > 2fh && bl < 3ah || bl > 40h && bl < 47h || bl > 60h && bl < 67h
                     jmp     HexOK
               .else

ReSet:
                     mov     eax, Num
                     mov     ebx, eax
                     dec     eax
                     mov     szAscii, 0
                  INVOKE     SendMessage, hInput, EM_SETSEL, eax, ebx
                  INVOKE     SendMessage, hInput, EM_REPLACESEL, FALSE, addr szAscii
                     jmp     ConvertErr
               .endif

HexOK:
                  inc     esi
                  dec     eax
            .endw
   
NoValidate:
            INVOKE     GetDlgItemText, hdlg, 402, addr szWork, sizeof szWork
               mov     Num, eax
            INVOKE     lstrcpy, addr szAscii, addr szWork
            .if HexDec == 16
               .if Num == 1
                     mov     ax, word ptr szAscii
                     mov     szAscii+1, al
                     mov     szAscii+2, ah
                     mov     byte ptr szAscii, '0'
               .endif
                  mov     Var1, 404
                  mov     Var2, 403
            .else
                  mov     Var1, 403
                  mov     Var2, 404
            .endif
            INVOKE     AsciiBase, addr szWork, addr dwwParam, HexDec
            .if dwwParam > 255
                  jmp     ReSet
            .endif
            INVOKE     SetDlgItemText, hdlg, Var1, addr szAscii
            .if HexDec == 16
               INVOKE     BaseAscii, dwwParam, addr szAscii, 0, 10, 0, 0, 1
            .else
               INVOKE     BaseAscii, dwwParam, addr szAscii, 2, 16, 0, 1, 1
            .endif
            INVOKE     SetDlgItemText, hdlg, Var2, addr szAscii
               mov     szAscii, 0
              call     ChkKey
            .if !szAscii
                   MOVmb     szAscii, dwwParam
                     mov     szAscii+1, 0
            .endif
            .if byte ptr szAscii == 'D' && byte ptr szAscii+1 == 'D'
               INVOKE     lstrcpy, addr szAscii, addr szAscii+1
            .endif
            .if byte ptr szAscii == 'I' && byte ptr szAscii+1 == 'N'
                  mov     word ptr szAscii, 002dh
            .endif

            INVOKE     SendMessage, hAsciiBox, WM_SETTEXT, NULL, addr szAscii
               jmp     TranslateDone
         .endif
   
      .elseif wMsg == WM_CLOSE
            jmp     CloseIt
      .endif
         jmp     TranslateDone

CloseIt:
      INVOKE     SetFocus, hREdit
      INVOKE     DestroyWindow, hdlg     ; End the dialog
         mov     eax, TRUE               ; Return
         jmp     TranslateRet            ; with TRUE
   
ConvertErr:
      INVOKE     MessageBeep, MB_OK

TranslateDone:
         and     dwMsg, 0
         mov     eax, FALSE

TranslateRet:
         ret
Translate ENDP

;=========================================================================
; Find / Replace PROCEDURE
;=========================================================================
FindReplace PROC uses ebx hdlg:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    szBuff[10]:BYTE

      .if wMsg == WM_INITDIALOG              ; If message is INITDIALOG then
            mov     eax, hdlg
            mov     hFRDlg, eax
         INVOKE     GetDlgItem, hdlg, 441 ;401
            mov     h41, eax
         INVOKE     GetDlgItem, hdlg, 402
            mov     h42, eax
         INVOKE     GetDlgItem, hdlg, 403
            mov     h43, eax
         INVOKE     GetDlgItem, hdlg, 404
            mov     ecx, eax
         INVOKE     SendMessage, ecx, WM_SETFONT, hFontT, TRUE

         INVOKE     GetDlgItem, hdlg, IDCANCEL
            mov     hCancel, eax

         INVOKE     GetWindowRect, hFRDlg, addr rect
            mov     eax, 10
         .if LineOn
               add     eax, LineWth
         .endif
            add     rect.left, eax
         .if lParam == 4902
               add     rect.top, 94
         .endif
         INVOKE     SetWindowPos, hFRDlg, HWND_NOTOPMOST,\
                    rect.left, rect.top, 0, 0, SWP_NOSIZE or SWP_NOZORDER

         INVOKE     GetDlgItem, hdlg, 101    ; Get handle of edit box
           push     eax                      ; Save handle of edit1
         INVOKE     SetFocus, eax            ; Set focus to this field
            pop     eax
         INVOKE     SendMessage, eax, EM_LIMITTEXT, 100, 0 ; Limit text size
         INVOKE     GetDlgItem, hdlg, 102
         INVOKE     SendMessage, eax, EM_LIMITTEXT, 100, 0 ; Limit text size
         INVOKE     lstrlen, addr szFind
         .if eax == 1 && szFind == ' '
;               mov     szFind, 0
         .endif
         INVOKE     SetDlgItemText, hdlg, 101, addr szFind
         INVOKE     SetDlgItemText, hdlg, 102, addr szRep
         INVOKE     GetDlgItem, hdlg, 302    ; Get search down check
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0 ; Sets find down to checked
         INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr ft.chrgText
            jmp     FRDone

      .elseif wMsg == WM_COMMAND
         .if wParam == 401 || wParam == 402 || wParam == 403 ; Find - Replace - ReplaceAll
               jmp     FRText

         .elseif wParam == 404
            INVOKE     GetDlgItemText, hdlg, 102, addr szRep, 100
               mov     word ptr szBuff, 000dh
            INVOKE     lstrcat, addr szRep, addr szBuff
            INVOKE     SetDlgItemText, hdlg, 102, addr szRep
            INVOKE     GetDlgItem, hdlg, 102    ; Get handle of edit box
               mov     ebx, eax
            INVOKE     SetFocus, ebx            ; Set focus to this field
            INVOKE     lstrlen, addr szRep
            INVOKE     SendMessage, ebx, EM_SETSEL, eax, eax

         .elseif wParam == IDCANCEL
               jmp     CloseIt
         .endif
      .endif
         jmp     FRDone

FRText:
         and     FRFlags, 0
      INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr ft.chrgText
      INVOKE     GetDlgItemText, hdlg, 101, addr szFind, 100
         mov     TxtLen, eax
        push     ft.chrgText.cpMin
         pop     ft.chrg.cpMin
         mov     ft.chrg.cpMax, -1
         lea     eax, offset szFind
         mov     ft.lpstrText, eax
         mov     eax, ft.chrgText.cpMax
         sub     eax, ft.chrgText.cpMin
         mov     SelLen, eax

      INVOKE     IsDlgButtonChecked, hdlg, 201  ; Whole word
      .if eax
             or     FRFlags, FR_WHOLEWORD
      .endif
      INVOKE     IsDlgButtonChecked, hdlg, 202  ; Match case
      .if eax
             or     FRFlags, FR_MATCHCASE
      .endif
      INVOKE     IsDlgButtonChecked, hdlg, 301  ; Up
      .if eax
            mov     Prev, 1
            mov     ft.chrg.cpMax, 0
      .endif
      INVOKE     IsDlgButtonChecked, hdlg, 302  ; Down
      .if eax
            mov     Prev, 0
             or     FRFlags, FR_DOWN
      .endif

      .if wParam == 402 || wParam == 403
         INVOKE     GetDlgItemText, hdlg, 102, addr szRep, 100
      .endif

      .if wParam == 401                         ; Find button
         INVOKE     Find, hWnd, 0, FRFlags, ft.lpstrText, Prev
;         INVOKE     SetFocus, h41

      .elseif wParam == 402                     ; Replace button

         INVOKE     GetDlgItemText, hdlg, 102, addr szRep, 100
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szRep
            mov     eax, ft.chrgText.cpMin
            mov     ft.chrgText.cpMax, eax
         INVOKE     lstrlen, addr szRep
            add     ft.chrgText.cpMax, eax
           push     eax
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr ft.chrgText
            pop     eax
         .if Prev
               sub     ft.chrg.cpMin, eax
         .else
               add     ft.chrg.cpMin, eax
         .endif
         INVOKE     Find, hWnd, 0, FRFlags, ft.lpstrText, Prev
         .if eax != 1
               jmp     FRDone
         .endif 

      .elseif wParam == 403                     ; Replace all button
         .if RetCode == -1
               jmp     SetIt
         .endif
         .while RetCode != -1

SetIt:
               mov     eax, BN_CLICKED
               shl     eax, 16
                or     eax, 402
            INVOKE     SendMessage, hdlg, WM_COMMAND, eax, 0

         .endw
      .endif
         jmp     FRDone

CloseIt:
      INVOKE     SetFocus, hREdit
      INVOKE     EndDialog, hdlg, wParam
;      INVOKE     DestroyWindow, hdlg     ; End the dialog
         mov     eax, TRUE               ; Return
         and     hFRDlg, 0
         jmp     FRRet                   ; with TRUE

FRDone:
         mov     eax, FALSE              ; Return with FALSE
FRRet:
         ret                             ; Return
FindReplace  ENDP

;=========================================================================
; FindProc returns TRUE or FALSE based on finding FText
;=========================================================================
Find    PROC     hwnd:DWORD, Next, Flags, FText, Up

Loop1:
      INVOKE     SendMessage, hREdit, EM_FINDTEXTEX, FRFlags, offset ft
         mov     RetCode, eax
         cmp     eax, -1                 ; Nothing found?
         jne     FoundIt
      .if Up == 0
         INVOKE     lstrcpyn, offset TopBot, offset Top, 9
      .else
         INVOKE     lstrcpyn, offset TopBot, offset Bot, 9
      .endif
      INVOKE     MessageBox, NULL, offset FindEnd, offset szFR, MB_YESNO or\
                 MB_ICONQUESTION or MB_TASKMODAL
         cmp     eax, IDNO
          je     Find0
      .if Up == 0
         INVOKE     SendMessage, hREdit, EM_SETSEL, 0, 0
            mov     ft.chrg.cpMin, 0
            mov     ft.chrg.cpMax, -1
      .else
         INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
            mov     ft.chrg.cpMin, eax
            mov     ft.chrg.cpMax, 0
      .endif
         jmp     Loop1

FoundIt:
         mov     ecx, SelLen
      .if eax == ft.chrg.cpMin && eax != ft.chrg.cpMax && Up == 0 && ecx == TxtLen
            inc     ft.chrg.cpMin
            jmp     Loop1
      .endif

      INVOKE     LockWindowUpdate, hWnd           ; Lock parent to avoid flicker
      INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr ft.chrgText
      INVOKE     SendMessage, hREdit, EM_SCROLLCARET, 0, 0
      INVOKE     LockWindowUpdate, 0              ; Unlock parent
      INVOKE     CenterSel, 0
         mov     eax, TRUE
         ret

Find0:
        mov     eax, FALSE
        ret
Find    ENDP

;==============================================================
; CheckState PROCEDURE
;==============================================================
HiliteSelection PROC ColorNum:DWORD

      INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
         mov     eax, cr.cpMin

      .if eax > cr.cpMax
           xchg     eax, cr.cpMax
            mov     cr.cpMin, eax
      .endif

      INVOKE     SendMessage, hREdit, EM_EXLINEFROMCHAR, 0, cr.cpMin
         mov     LineNum, eax
      .while (TRUE)
         INVOKE     SendMessage, hREdit, UM_SETHILITELINE, LineNum, ColorNum
            inc     LineNum
         INVOKE     SendMessage, hREdit, EM_LINEINDEX, LineNum, 0
         .break .if eax >= cr.cpMax || eax <= cr.cpMin
         INVOKE     SendMessage, hREdit, EM_EXLINEFROMCHAR, 0, eax
         .break .if eax < LineNum
      .endw
         ret

HiliteSelection ENDP

;==============================================================
; CheckState PROCEDURE
;==============================================================
CheckState PROC uses ebx esi
LOCAL    TempWord:DWORD

      INVOKE     EnableMenuItem, hMenu, IDM_UNDOREDO, MF_GRAYED
      INVOKE     SendMessage, hREdit, EM_CANUNDO, 0, 0
      .if eax
            mov     TempWord, MF_ENABLED
         INVOKE     EnableMenuItem, hMenu, IDM_UNDOREDO, TempWord
      .else
            mov     TempWord, MF_GRAYED
      .endif
      INVOKE     EnableMenuItem, hMenu, IDM_UNDO, TempWord
      INVOKE     EnableMenuItem, hSMenu, IDM_UNDO, TempWord
         xor     TempWord, 1
      INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_UNDO, TempWord

      INVOKE     SendMessage, hREdit, EM_CANREDO, 0, 0
      .if eax
            mov     TempWord, MF_ENABLED
         INVOKE     EnableMenuItem, hMenu, IDM_UNDOREDO, TempWord
      .else
            mov     TempWord, MF_GRAYED
      .endif
      INVOKE     EnableMenuItem, hMenu, IDM_REDO, TempWord
      INVOKE     EnableMenuItem, hSMenu, IDM_REDO, TempWord
         xor     TempWord, 1
      INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_REDO, TempWord

      INVOKE     IsClipboardFormatAvailable, CF_TEXT
      .if eax
            mov     TempWord, MF_ENABLED
      .else
            mov     TempWord, MF_GRAYED
      .endif
      INVOKE     EnableMenuItem, hMenu, IDM_PASTE, TempWord
      INVOKE     EnableMenuItem, hMenu, IDM_CLRCLIP, TempWord
      INVOKE     EnableMenuItem, hSMenu, IDM_PASTE, TempWord
         xor     TempWord, 1
      INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_PASTE, TempWord

;      INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
;         mov     eax, cr.cpMin
      .if SelectOn ;eax != cr.cpMax
            mov     TempWord, MF_ENABLED
      .else
            mov     TempWord, MF_GRAYED
      .endif
      INVOKE     EnableMenuItem, hMenu, IDM_CUT, TempWord
      INVOKE     EnableMenuItem, hSMenu, IDM_CUT, TempWord
      INVOKE     EnableMenuItem, hMenu, IDM_COPY, TempWord
      INVOKE     EnableMenuItem, hSMenu, IDM_COPY, TempWord
      INVOKE     EnableMenuItem, hMenu, IDM_DELETE, TempWord
      INVOKE     EnableMenuItem, hSMenu, IDM_DELETE, TempWord
      INVOKE     EnableMenuItem, hMenu, IDM_FINDNEXT, TempWord
      INVOKE     EnableMenuItem, hMenu, IDM_FINDPREV, TempWord

         xor     TempWord, 1
      INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_CUT, TempWord
      INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_COPY, TempWord
      INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_DELETE, TempWord
      INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_FINDNEXT, TempWord
      INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_FINDPREV, TempWord

      .if SyntaxOn
         INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_SYNTAX, 21
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_SYNTAX, MF_CHECKED or MF_BYCOMMAND
      .else
         INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_SYNTAX, 27
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_SYNTAX, MF_UNCHECKED or MF_BYCOMMAND
      .endif

;      .if ItalicOn
;         INVOKE     CheckMenuItem, hMenu, IDM_ITALIC, MF_CHECKED
;      .else
;         INVOKE     CheckMenuItem, hMenu, IDM_ITALIC, MF_UNCHECKED
;      .endif

;      .if NoHiLiteBW
;         INVOKE     CheckMenuItem, hMenu, IDM_HILITEBW, MF_CHECKED
;      .else
;         INVOKE     CheckMenuItem, hMenu, IDM_HILITEBW, MF_UNCHECKED
;      .endif

      .if FilterOn
         INVOKE     SendMessage, hWndTool2, TB_CHECKBUTTON, 1091, MF_CHECKED or MF_BYCOMMAND
         INVOKE     SendMessage, hWndTool2, TB_CHECKBUTTON, 1092, MF_UNCHECKED or MF_BYCOMMAND
      .else
         INVOKE     SendMessage, hWndTool2, TB_CHECKBUTTON, 1091, MF_UNCHECKED or MF_BYCOMMAND
         INVOKE     SendMessage, hWndTool2, TB_CHECKBUTTON, 1092, MF_CHECKED or MF_BYCOMMAND
      .endif

      INVOKE     CheckMenuItem, hMenu, IDM_PROJECTDEF, MF_UNCHECKED
      INVOKE     CheckMenuItem, hMenu, IDM_PROJECT01, MF_UNCHECKED
      INVOKE     CheckMenuItem, hMenu, IDM_PROJECT02, MF_UNCHECKED
      INVOKE     CheckMenuItem, hMenu, IDM_PROJECT03, MF_UNCHECKED
      INVOKE     CheckMenuItem, hMenu, IDM_PROJECT04, MF_UNCHECKED
      INVOKE     CheckMenuItem, hMenu, IDM_PROJECT05, MF_UNCHECKED
         mov     ecx, IDM_PROJECTDEF
         add     ecx, ProjGroup
      INVOKE     CheckMenuItem, hMenu, ecx, MF_CHECKED

      INVOKE     CheckMenuItem, hMenu, IDM_FILTERDEF, MF_UNCHECKED
      INVOKE     CheckMenuItem, hMenu, IDM_FILTER01, MF_UNCHECKED
      INVOKE     CheckMenuItem, hMenu, IDM_FILTER02, MF_UNCHECKED
         mov     ecx, IDM_FILTERDEF
         add     ecx, FilterGroup
      INVOKE     CheckMenuItem, hMenu, ecx, MF_CHECKED

      INVOKE     GetMenuItemCount, hSubMenuW
      .if eax != -1
            mov     esi, 9401
            mov     ebx, eax
         .while (ebx)
            INVOKE     CheckMenuItem, hSubMenuW, esi, MF_UNCHECKED
               inc     esi
               dec     ebx
         .endw
      .endif

         mov     ecx, 9400
         add     ecx, TabSelect
      INVOKE     CheckMenuItem, hSubMenuW, ecx, MF_CHECKED


      .if CloseBuild
         INVOKE     CheckMenuItem, hMenu, IDM_CLOSEBUILD, MF_CHECKED
      .else
         INVOKE     CheckMenuItem, hMenu, IDM_CLOSEBUILD, MF_UNCHECKED
      .endif

      .if IndentOn
         INVOKE     ModifyMenu, hMenu, IDM_INDENT, MF_BYCOMMAND or MF_STRING, IDM_INDENT, addr szShowI
      .else
         INVOKE     ModifyMenu, hMenu, IDM_INDENT, MF_BYCOMMAND or MF_STRING, IDM_INDENT, addr szHideI
      .endif

      .if LeadingOn
         INVOKE     ModifyMenu, hMenu, IDM_LEADING, MF_BYCOMMAND or MF_STRING, IDM_LEADING, addr szShowL
      .else
         INVOKE     ModifyMenu, hMenu, IDM_LEADING, MF_BYCOMMAND or MF_STRING, IDM_LEADING, addr szHideL
      .endif

      .if ConstrainOn
         INVOKE     ModifyMenu, hMenu, IDM_CONSTR, MF_BYCOMMAND or MF_STRING, IDM_CONSTR, addr szShowC
      .else
         INVOKE     ModifyMenu, hMenu, IDM_CONSTR, MF_BYCOMMAND or MF_STRING, IDM_CONSTR, addr szHideC
      .endif

      .if ColumnOn
         INVOKE     ModifyMenu, hMenu, IDM_COLUMN, MF_BYCOMMAND or MF_STRING, IDM_COLUMN, addr szShowS
      .else
         INVOKE     ModifyMenu, hMenu, IDM_COLUMN, MF_BYCOMMAND or MF_STRING, IDM_COLUMN, addr szHideS
      .endif

      .if CodeHelperOn
         INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_CODEH, 23
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_CODEH, MF_CHECKED or MF_BYCOMMAND
      .else
         INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_CODEH, 14
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_CODEH, MF_UNCHECKED or MF_BYCOMMAND
      .endif

      .if QuickOn
         INVOKE     ModifyMenu, hMenu, IDM_QUICKC, MF_BYCOMMAND or MF_STRING, IDM_QUICKC, addr szHideQ
         INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_QUICKC, 24
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_QUICKC, MF_CHECKED or MF_BYCOMMAND
      .else
         INVOKE     ModifyMenu, hMenu, IDM_QUICKC, MF_BYCOMMAND or MF_STRING, IDM_QUICKC, addr szShowQ
         INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_QUICKC, 15
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_QUICKC, MF_UNCHECKED or MF_BYCOMMAND
      .endif

      .if UserOn
         INVOKE     ModifyMenu, hMenu, IDM_USERC, MF_BYCOMMAND or MF_STRING, IDM_USERC, addr szHideU
         INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_USERC, 25
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_USERC, MF_CHECKED or MF_BYCOMMAND
      .else
         INVOKE     ModifyMenu, hMenu, IDM_USERC, MF_BYCOMMAND or MF_STRING, IDM_USERC, addr szShowU
         INVOKE     SendMessage, hWndTool, TB_CHANGEBITMAP, IDM_USERC, 16
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, IDM_USERC, MF_UNCHECKED or MF_BYCOMMAND
      .endif

      .if ProjOn
         INVOKE     ModifyMenu, hMenu, IDM_PROJECTS, MF_BYCOMMAND or MF_STRING, IDM_PROJECTS, addr szHideP
         INVOKE     SendMessage, hWndToolB, TB_INDETERMINATE, IDM_PROJECTS, 0
      .else
         INVOKE     ModifyMenu, hMenu, IDM_PROJECTS, MF_BYCOMMAND or MF_STRING, IDM_PROJECTS, addr szShowP
         INVOKE     SendMessage, hWndToolB, TB_INDETERMINATE, IDM_PROJECTS, 1
      .endif

      .if DriveOn
         INVOKE     ModifyMenu, hMenu, IDM_DRIVES, MF_BYCOMMAND or MF_STRING, IDM_DRIVES, addr szHideD

         INVOKE     SendMessage, hWndToolB, TB_INDETERMINATE, IDM_PROJECTS, 1
      .else
         INVOKE     ModifyMenu, hMenu, IDM_DRIVES, MF_BYCOMMAND or MF_STRING, IDM_DRIVES, addr szShowD

;         INVOKE     SendMessage, hWndToolB, TB_INDETERMINATE, IDM_PROJECTS, 1
      .endif

      .if PropOn
         INVOKE     ModifyMenu, hMenu, IDM_FUNCT, MF_BYCOMMAND or MF_STRING, IDM_FUNCT, addr szHideF
      .else
         INVOKE     ModifyMenu, hMenu, IDM_FUNCT, MF_BYCOMMAND or MF_STRING, IDM_FUNCT, addr szShowF
      .endif

      .if AutoRefOn
         INVOKE     CheckMenuItem, hMenu, IDM_AUTOR, MF_CHECKED or MF_BYCOMMAND
      .else
         INVOKE     CheckMenuItem, hMenu, IDM_AUTOR, MF_UNCHECKED or MF_BYCOMMAND
      .endif

      INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
         mov     ebx, eax
         mov     ecx, TabSelect                   ; Current selected Tab
         mov     edx, hTabSeL+[ecx*8+4]           ; Extract current Tabs code   ;handle
      .if edx == 2                                ; Open Hex
            mov     TempWord, MF_GRAYED
         INVOKE     EnableMenuItem, hMenu, IDM_SAVE, TempWord
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEAS, TempWord
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEALL, TempWord
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEUNIAS, TempWord
            xor     TempWord, 1
         INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_SAVE, TempWord
         INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_SAVEALL, TempWord
         INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
         .if ebx != 0
               mov     TempWord, MF_ENABLED
         .else
               mov     TempWord, MF_GRAYED
         .endif
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEHEXAS, TempWord

      .elseif edx == 8                            ; Open Unicode
            mov     TempWord, MF_GRAYED
         INVOKE     EnableMenuItem, hMenu, IDM_SAVE, TempWord
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEALL, TempWord
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEHEXAS, TempWord
            xor     TempWord, 1
         INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_SAVE, TempWord
         INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_SAVEALL, TempWord
         INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
;         .if ebx != 0
               mov     TempWord, MF_ENABLED
;         .else
;               mov     TempWord, MF_GRAYED
;         .endif
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEAS, TempWord
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEUNIAS, TempWord

      .else
            mov     TempWord, MF_GRAYED
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEHEXAS, TempWord
         INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
         .if eax
               mov     TempWord, MF_ENABLED
         .endif
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEAS, TempWord
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEALL, TempWord
         INVOKE     EnableMenuItem, hMenu, IDM_SAVEUNIAS, TempWord
            xor     TempWord, 1
         INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_SAVEALL, TempWord
         INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
         .if ebx != 0
               mov     TempWord, MF_ENABLED
         .else
               mov     TempWord, MF_GRAYED
         .endif
         INVOKE     EnableMenuItem, hMenu, IDM_SAVE, TempWord
            xor     TempWord, 1
         INVOKE     SendMessage, hWndTool, TB_ENABLEBUTTON, IDM_SAVE, TempWord
      .endif
        call     SetDrawTab

      .if PropOn && AutoRefOn ;&& sw5 != 9  ; sw5 = 9 is from the Filename Listview 
         INVOKE     SendMessage, hREdit, EM_GETLINECOUNT, 0, 0
         .if eax != LineCount
            .if PathName
                  mov     LineCount, eax
               INVOKE     WriteReadMem, 1, PropCode
            .endif
         .endif

;      .elseif PropOn && ExtType == 'a' && ExtType + 1 == 's' && ExtType + 2 == 'm'
;         INVOKE     SendMessage, hWndFunct, LB_RESETCONTENT, 0, 0
      .endif

         ret
CheckState ENDP

;===================================================
; Fill the DRAWITEM structure
;===================================================
SetDrawTab PROC
LOCAL    rect:RECT

         mov     dis.CtlType, ODT_TAB
         mov     dis.CtlID, 702
       MOVmd     dis.itemID, TabSelect
         mov     dis.itemAction, ODA_SELECT
         mov     dis.itemState, ODS_SELECTED
         mov     eax, TabSelect                  ; Current selected Tab
         mov     edx, hTabSeL[eax*8]            ; Extract current Tabs handle
         mov     dis.hwndItem, edx
      INVOKE     GetDC, hWndTab
         mov     dis.hdc, eax
      INVOKE     SelectObject, dis.hdc, hFontT
      INVOKE     SendMessage, hWndTab, TCM_GETITEMRECT, TabSelect, addr rect
         add     rect.left, 2
         sub     rect.right, 2
         add     rect.top, 2
         sub     rect.bottom, 2
       MOVmd     dis.rcItem.left, rect.left
       MOVmd     dis.rcItem.top, rect.top
       MOVmd     dis.rcItem.right, rect.right
       MOVmd     dis.rcItem.bottom, rect.bottom
         mov     dis.itemData, 0
      INVOKE     SendMessage, hWnd, WM_DRAWITEM, 702, addr dis
      INVOKE     ReleaseDC, hWndTab, dis.hdc
         ret
SetDrawTab ENDP

;===================================================
; Convert Tab Stops PROCEDURE
;===================================================
ConvTabs PROC uses ebx hdlg:DWORD, wMsg, wParam, lParam
LOCAL    Cnt:DWORD
LOCAL    Clear[256]:BYTE, szFills[100]:BYTE, szWork[25]:BYTE, szBuff0[256]:BYTE

      .if wMsg == WM_INITDIALOG              ; If message is INITDIALOG then
         INVOKE     GetDlgItem, hdlg, 401
            mov     h41, eax
         INVOKE     GetDlgItem, hdlg, 402
            mov     h42, eax
         INVOKE     GetDlgItem, hdlg, 403
            mov     h43, eax
         INVOKE     GetDlgItem, hdlg, 30
         INVOKE     SetFocus, eax

      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
            and     eax, 0ffffh
            mov     ebx, wParam
            shr     ebx, 16

         .if ebx == BN_CLICKED
            INVOKE     GetFocus
            INVOKE     GetDlgCtrlID, eax
         .endif

         .if eax == 401
               jmp     Convit
         .elseif eax == 402
               jmp     Undo
         .elseif eax == 403
               jmp     Close
         .endif

      .elseif wMsg == WM_CLOSE
            jmp     Close
      .endif
         jmp     ConvTabsDone

Convit:
      INVOKE     LoadCursor, 0, IDC_WAIT
      INVOKE     SetCursor, eax
         and     Cnt, 0
      INVOKE     FillBuffer, addr Clear, sizeof Clear, ' ', 1
;         mov     eax, TAB
;         inc     eax
;      INVOKE     lstrcpyn, addr szFills, addr Clear, eax
         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
         lea     eax, offset szHT
         mov     ft.lpstrText, eax

FindLoop:
      INVOKE     SendMessage, hREdit, EM_FINDTEXTEX, FR_DOWN, offset ft
      .if eax == -1
            mov     cr.cpMin, 0
            mov     cr.cpMax, 0
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_SCROLLCARET, 0, 0
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
         INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
            mov     BytesRead, eax
         INVOKE     BaseAscii, Cnt, addr szWork, 0, 10, 0, 0, 1
         INVOKE     SetDlgItemText, hdlg, 501, addr szWork
         INVOKE     BaseAscii, BytesRead, addr Fsize, 0, 10, 1, 0, 1
         INVOKE     lstrcpy, addr szFileSize, addr szSize
         INVOKE     lstrcat, addr szFileSize, addr Fsize
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 0, addr szFileSize
            jmp     ConvTabsDone
      .endif
      INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr ft.chrgText

      INVOKE     SendMessage, hREdit, EM_LINEINDEX, -1, 0
         mov     ecx, ft.chrgText.cpMin
         sub     ecx, eax
         mov     eax, TAB
      .while (ecx >= eax)
            add     eax, TAB
      .endw
         sub     eax, ecx
         inc     eax
      INVOKE     lstrcpyn, addr szFills, addr Clear, eax

      INVOKE     CenterSel, 1
      INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szFills
         mov     eax, ft.chrgText.cpMin
         inc     eax
         mov     ft.chrg.cpMin, eax
         inc     Cnt
         jmp     FindLoop

Undo:
         and     Cnt, 0
      INVOKE     BaseAscii, Cnt, addr szWork, 0, 10, 0, 0, 1
      INVOKE     SetDlgItemText, hdlg, 501, addr szWork
         mov     OA, 1
         mov     OpenFlg1, 2
      INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, offset szCR
        call     OpenFileA
         jmp     ConvTabsDone

Close:
         and     hWndDlg, 0
      INVOKE     SetFocus, hREdit
      INVOKE     DestroyWindow, hdlg     ; End the dialog
         mov     eax, TRUE               ; Return
         jmp     ConvTabsRet             ; with TRUE

ConvTabsDone:
         xor     eax, eax

ConvTabsRet:
         ret

ConvTabs ENDP

;=====================================================================
; Converts a Dec, Hex, Oct or Bin ascii string to a 32 bit num value.
;=====================================================================
AsciiBase PROC Input:DWORD, Output, Base
      pushad
         mov     esi, Input
         mov     edi, Output
         and     dword ptr[edi], 0
      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     dword ptr[edi], eax    ; Accumulate output
           imul     ebx, Base
            dec     esi
            dec     ecx 
      .endw
       popad
          ret
AsciiBase ENDP

;=========================================================================
;  Converts a 32 bit num value to a Dec, Hex, Oct or Bin ascii string.
;=========================================================================
;INVOKE     BaseAscii, cnt, offset num, 2, 10, 0, 1, 0
BaseAscii PROC InPut:DWORD, OutPut, LEN, Base, Comma, Fill, TermA
LOCAL    LBuff[32]: BYTE

      pushad
         xor     esi, esi
         mov     eax, InPut                ; Input
         mov     ebx, OutPut
         mov     byte ptr [ebx], '0'
      .while (eax)
            xor     edx, edx
            div     Base                   ; Base 10, 16, 8, 2
         .if dl > 9h
               add     dl, 37h             ; Convert to hex ASCII
         .else
               add     dl, 30h             ; Convert to dec ASCII
         .endif
            mov     LBuff[esi], dl
            inc     esi
         .if Comma == 1 && Base == 10 && eax > 0
            .if esi == 3 || esi == 7 || esi == 11
                  mov     LBuff[esi], 2ch  ; Insert commas
                  inc     esi
            .endif
         .endif
      .endw
         xor     edi, edi
         mov     ecx, esi
      .if LEN > ecx && Fill == 1           ; Zero fill
            xor     eax, eax
         .while (eax < LEN)
               mov     byte ptr [ebx+eax], '0'
               inc     eax
         .endw
            sub     LEN, ecx
            add     edi, LEN
      .endif
      .while (ecx)
            mov     al, byte ptr LBuff[esi-1]
            mov     byte ptr [ebx+edi], al
            inc     edi
            dec     esi
            dec     ecx
      .endw
      .if TermA
         mov     byte ptr [ebx+edi], 0h
      .endif
       popad
         ret
BaseAscii ENDP

;===================================================
; Fills a buffer with a character.
;===================================================
FillBuffer PROC uses esi edi Input:DWORD, SizeB:DWORD, Fill:BYTE, TermA:DWORD
         mov     esi, Input
         mov     edi, esi           ; Dest = Source
         mov     ecx, SizeB         ; Size to fill
         mov     al, Fill           ; Fill character

FillBuff:
       stosb                        ; Store al
        loop     FillBuff           ; for length of string
      .if TermA                     ; Write a terminating char
            dec     edi
            mov     byte ptr[edi], 0
      .endif
         ret
FillBuffer ENDP

;===================================================
; Format the time and send it to the status bar
;===================================================
FmTime   PROC  uses ebx
LOCAL    Clear[256]:BYTE, szBuff1[100]:BYTE, DateBuff[11]:BYTE, TimeBuff[12]:BYTE

      INVOKE     FillBuffer, addr Clear, sizeof Clear, ' ', 1
      INVOKE     GetDateFormat, NULL, NULL, NULL, addr DatePict, addr DateBuff, 11
      ;INVOKE     GetTimeFormat, NULL, TIME_FORCE24HOURFORMAT, NULL, addr TimePict, addr TimeBuff, 12
      INVOKE     GetTimeFormat, NULL, NULL, NULL, addr TimePict, addr TimeBuff, 12

      INVOKE     lstrcpyn, addr szBuff1, addr Clear, 4
      INVOKE     lstrcpy, addr szBuff1+2, addr TimeBuff
      INVOKE     lstrcat, addr szBuff1, addr Clear
      INVOKE     lstrcpy, addr szBuff1+16, addr DateBuff
      INVOKE     SendMessage, hWndStat, SB_SETTEXT, 3, addr szBuff1
         ret
FmTime   ENDP

;===================================================
; Shift line, comment PROCEDURE
;===================================================
ShiftLine PROC uses ebx edi OperType:DWORD, TabOn
LOCAL	    Ocr:CHARRANGE
LOCAL     Chg:DWORD, Cnt, Len, SPos1, EPos1, SavPos, Single, sw1, hScroll
LOCAL     szWork1[1024]:BYTE, szWork2[1024]:BYTE, Clear[1024]:BYTE

;      INVOKE     SendMessage, hREdit, EM_GETMODIFY, 0, 0
;         mov     Chg, eax

      INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
         mov     eax, cr.cpMin
      .if eax == cr.cpMax && OperType > 3
            ret
      .endif
       MOVmd     SPos1, cr.cpMin
       MOVmd     EPos1, cr.cpMax

      INVOKE     SendMessage, hREdit, UM_NOHORZSCROLL, 0, TRUE
      INVOKE     FillBuffer, addr Clear, lengthof Clear, ' ', 1
      INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr Ocr
      INVOKE     LockWindowUpdate, hREdit
      INVOKE     SendMessage, hREdit, EM_HIDESELECTION, 1, 0
      INVOKE     SendMessage, hREdit, EM_LINEFROMCHAR, SPos1, 0
         mov     ebx, eax
      INVOKE     SendMessage, hREdit, EM_LINEFROMCHAR, EPos1, 0
         mov     Cnt, eax
         sub     Cnt, ebx
         and     Len, 0
         and     Single, 0
      .if !Cnt
            mov     Single, 1
            inc     Cnt
      .endif

jmp     Pass
      INVOKE     SendMessage, hREdit, UM_GETSELECT, 0, 0
         mov     ebx, eax
         shr     ebx, 16
         and     eax, 0ffffh
      .if ebx > eax
           xchg     eax, ebx
      .endif
         mov     ecx, eax
         sub     ecx, ebx
         inc     ecx
         mov     Cnt, ecx
Pass:

      .while (Cnt)
         .if !Single
            INVOKE     SendMessage, hREdit, EM_LINEINDEX, ebx, 0
               mov     SPos1, eax
         .endif
          MOVmd     SavPos, SPos1
            and     sw1, 0

Again:
         INVOKE     SendMessage, hREdit, EM_LINELENGTH, SPos1, 0
            inc     eax
         .if eax > 1000 && OperType == 1
               jmp     GetOut
         .endif
          MOVmd     EPos1, SPos1
            add     EPos1, eax
          MOVmd     cr.cpMin, SPos1
          MOVmd     cr.cpMax, EPos1
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_GETSELTEXT, 0, addr szWork2
          MOVmd     cr.cpMin, SPos1
          MOVmd     cr.cpMax, SPos1
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
            mov     al, 0dh               ; Carrage return
            lea     edx, szWork2          ; Start address in input buffer
            mov     edi, edx
            mov     ecx, EPos1
            cld                           ; Increment edi
          repnz     scasb                 ; Repeat until byte = al(13)
            mov     ecx, edi
            lea     edx, szWork2
            sub     ecx, edx
            mov     EPos1, ecx
            mov     Len, ecx
           push     ecx
         INVOKE     lstrcpyn, addr szWork1, addr szWork2, ecx
            pop     ecx

         .if OperType == 1 && TabOn && Single && Len == 1
               inc     Ocr.cpMax
             MOVmd     cr.cpMin, SPos1
             MOVmd     cr.cpMax, SPos1
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               mov     word ptr szWork2, 0009h     ; Tab0
               jmp     Replace

         .elseif OperType == 4
               inc     Ocr.cpMax
             MOVmd     cr.cpMin, SPos1
             MOVmd     cr.cpMax, SPos1
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               mov     word ptr szWork2, 003bh     ; ;0
               jmp     Replace
         .elseif OperType == 5
               dec     Ocr.cpMax
             MOVmd     cr.cpMin, SPos1
             MOVmd     cr.cpMax, SPos1
               inc     cr.cpMax
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               mov     byte ptr szWork2, 00h       ; 0
               jmp     Replace
         .endif
         .if sw1 == 1
               jmp     ShiftL
         .endif
         .if OperType == 3
               mov     eax, SHIFT
               mov     ecx, CurPos
            .if eax > ecx
               .if byte ptr szWork1 == ' ' || byte ptr szWork1 == 09h
                    push     ecx
                  INVOKE     lstrlen, addr szWork1
                     pop     ecx

                     lea     edi, szWork1    ; Start address in input buffer
                  .while (eax)
                     .if byte ptr[edi] == ' ' || byte ptr[edi] == 09h
                           inc     edi
                           inc     SPos1
                           inc     ecx
                           dec     eax
                     .else
                           mov     CurPos, ecx
                           jmp     Again
                     .endif
                  .endw
               .endif
                  sub     eax, ecx
                  jmp     ShiftR
            .else
                  sub     ecx, eax
                  sub     SPos1, ecx
                  mov     CurPos, eax
                  mov     sw1, 1
                  jmp     Again 

            .endif
         .endif
         .if OperType == 1                    ; Outdent
            .if !TabOn
                  mov     eax, SPACE          ; Increments
            .else
                  mov     eax, TAB            ; Increments
            .endif

ShiftR:
               add     Ocr.cpMax, eax
               inc     eax
            .if !TabOn || OperType == 3
               INVOKE     lstrcpyn, addr szWork2, addr Clear, eax
            .else
                  mov     eax, 09h
                  mov     dword ptr szWork2, eax
                  mov     eax, TAB
                  dec     eax
                  sub     Ocr.cpMax, eax
            .endif
             MOVmd     cr.cpMin, SPos1
             MOVmd     cr.cpMax, SPos1
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
               jmp     Replace
         .endif
         .if OperType == 2                    ; Indent
            .if !TabOn
                  mov     ecx, SPACE          ; Increments
            .else
                  mov     ecx, TAB            ; Increments
            .endif

ShiftL:
               lea     edi, szWork1           ; Start address in input buffer

Loop1:
               cmp     byte ptr[edi], 20h
                je     Cont
            .if TabOn && byte ptr[edi] == 09h
                  mov     eax, TAB
                  dec     eax
                  add     Ocr.cpMax, eax
                  mov     ecx, 1
                  jmp     Cont
            .endif
               cmp     byte ptr[edi], 09h
               jne     GotEm

Cont:
               inc     edi
               dec     ecx
                jz     GotEm
               jmp     Loop1

GotEm:
               mov     eax, SPos1
               dec     eax                    ; For Richedit V2, V3
               add     EPos1, eax
            .if OperType == 2
               .if !TabOn
                     mov     eax, SPACE       ; Increments
               .else
                     mov     eax, TAB         ; Increments
               .endif
                  sub     eax, ecx
                  sub     Ocr.cpMax, eax
            .endif
            .if OperType == 3
                  mov     eax, EPos1
                  sub     eax, SavPos
                  sub     eax, SHIFT
                  sub     eax, ecx
                  add     eax, 2
                  sub     Ocr.cpMax, eax
            .endif
            INVOKE     lstrcpy, addr szWork2, edi
             MOVmd     cr.cpMin, SPos1
             MOVmd     cr.cpMax, EPos1
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         .endif

Replace:
;xor     eax, eax
;mov     al, byte ptr szWork2
;DSPValue hWnd, eax, 1, 'm'

         INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szWork2
          MOVmd     SPos1, SavPos
          MOVmd     cr.cpMin, SPos1
          MOVmd     cr.cpMax, SPos1
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         .if OperType == 1 && TabOn && Single && Len == 1
             MOVmd     Ocr.cpMin, Ocr.cpMax
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr Ocr
         .endif

NoMore:
            inc     ebx
            dec     Cnt
      .endw

GetOut:
      .if !Single
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr Ocr
      .endif
      INVOKE     SendMessage, hREdit, EM_HIDESELECTION, 0, 0
      INVOKE     LockWindowUpdate, 0
      INVOKE     SendMessage, hREdit, UM_NOHORZSCROLL, 0, FALSE
;      INVOKE     SendMessage, hREdit, EM_SETMODIFY, Chg, 0
         and     TabOn, 0
         ret

ShiftLine ENDP

;===================================================
; Extract FolderName PROCEDURE
;===================================================
GetFolderName PROC
LOCAL    szBuff0[256]:BYTE

         INVOKE     lstrcpy, addr szBuff0, addr PathName
         INVOKE     StripFileExt, addr szBuff0
         INVOKE     StripFileName, addr szBuff0
         INVOKE     lstrlen, addr szBuff0
           push     eax
            dec     eax
         .while (eax)
               dec     eax
            .if byte ptr szBuff0[eax] == '\'
               .break
            .endif
         .endw
            pop     ecx
            sub     ecx, eax
            inc     eax
            dec     ecx
         INVOKE     lstrcpyn, addr szFolder, addr szBuff0[eax], ecx

         ret
GetFolderName ENDP

;===================================================
; Extract FileName PROCEDURE
;===================================================
GetFileName PROC

      INVOKE     lstrlen, addr PathName
      .while (eax)
            dec     eax
         .if PathName[eax] == '\'
            .break
         .endif
      .endw
         inc     eax
      INVOKE     lstrcpy, addr FileName, addr PathName[eax]
         ret

GetFileName ENDP

;===================================================
; Extract Extent PROCEDURE
;===================================================
GetExtent PROC

      INVOKE     lstrlen, addr FileName
         mov     ecx, eax
         lea     edi, FileName
         mov     eax, 2eh                      ; Look for period in commandline
       repnz     scasb
      INVOKE     lstrcpy, addr ExtType, edi    ; Copy ExtType
         mov     ecx, 3
         lea     esi, ExtType
        call     LowerCase                     ; Convert to lowercase
         ret

GetExtent ENDP

;===================================================
; Strip file ext FileName PROCEDURE
;===================================================
StripFileExt PROC lpFileName:DWORD

      INVOKE     lstrlen, lpFileName
         mov     edx, lpFileName
      .while (eax)
            dec     eax
         .if byte ptr [edx+eax] == '.'
               mov     byte ptr [edx+eax], 0
            .break
        .endif
      .endw
      ret

StripFileExt ENDP

;===================================================
; Strip file name FileName PROCEDURE
;===================================================
StripFileName PROC lpFileName:DWORD

      INVOKE     lstrlen, lpFileName
         mov     edx, lpFileName
      .while (eax)
            dec     eax
         .if byte ptr [edx+eax] == '\'
               mov     byte ptr [edx+eax+1], 0
            .break
         .endif
      .endw
      ret

StripFileName ENDP

;=====================================================================
; Edit Stream Out Callback procedure - write to memory from a control
;=====================================================================
EditStreamWriteM PROC  uses ebx esi edi  dwCookie:DWORD, pbBuff, cb, pcb

         mov     ecx, cb             ; Block size for this callback
         mov     ebx, ecx
         mov     edi, dwCookie       ; Output
         add     edi, HoldM          ; Apply offset to the output buffer
         mov     esi, pbBuff         ; InPut, doesn't need the offset??
         rep     movsb
         mov     eax, pcb            ; Pointer to pcb
         mov     dword ptr[eax], ebx ; Actual bytes written for this callback
         add     HoldM, ebx          ; HoldM = accum offset for input buffer
         mov     eax, 0              ; Must return zero
         ret

EditStreamWriteM ENDP

;===================================================
; Create the Properties Listbox procedure
;===================================================
CreateProp PROC

        push     ecx
      INVOKE     DestroyWindow, hWndFunct
         pop     ecx
      INVOKE     CreateWindowEx, WS_EX_STATICEDGE, addr ListboxClass, 0,\
                 ecx,\
                 xFunct, yFunct, wFunct, hFunct, hWnd, 89, hInst, 0
         mov     hWndFunct, eax
      INVOKE     SendMessage, hWndFunct, LB_SETHORIZONTALEXTENT, 150, 0
      INVOKE     SendMessage, hWndFunct, LB_SETITEMHEIGHT, 0, 15        ; List items
      INVOKE     SendMessage, hWndFunct, WM_SETFONT, hFontC, TRUE
      INVOKE     ShowWindow, hWndFunct, SW_SHOWDEFAULT
         ret

CreateProp ENDP

;===================================================
; Writes to memory from a richedit control then 
; Reads from memory to a richedit control
;===================================================
WriteReadMem PROC  uses ebx esi edi  Funct:DWORD, Prop
LOCAL    EditS:EDITSTREAM
LOCAL    Streamin:DWORD, Streamout, LineCnt, Saveax, DataOn, SavPos, Cnt, StartOn
LOCAL    Blank:DWORD, Blank5, Incr, StructOn, CodeOn, ItemCnt, RestPos, GotCode
LOCAL    hMemM:DWORD, pMemM, BytesOut,cnt

;Funct == 0 = From create new window
;Funct == 1 = From Properties list
;Funct == 1 = Show Properties list
;Funct == 1 = From change
;Funct == 4 = From Goto
;Funct == 4 = From WM_LBUTTONUP  Prop = 8

;Prop == 0 = Macro's
;Prop == 1 = Constant's
;Prop == 2 = Data area
;Prop == 3 = Structure's


;Prop == 4 = Procedures
;Prop == 5 = Label's
;Prop == 6 = Label's
;Prop == 8 = Statusbar Proc display

         mov     BytesOut, 8000000
      INVOKE     HeapCreate, HEAP_GENERATE_EXCEPTIONS, BytesOut, 0
         mov     hMemM, eax
      INVOKE     HeapAlloc, hMemM, HEAP_GENERATE_EXCEPTIONS, BytesOut
         mov     pMemM, eax

         and     HoldM, 0
        push     pMemM
         pop     EditS.dwCookie
         mov     EditS.dwError, 0
         mov     EditS.pfnCallback, offset EditStreamWriteM
      INVOKE     SendMessage, hREdit, EM_STREAMOUT, SF_TEXT, addr EditS

      INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
         mov     BytesOut, eax   ; eax = bytes written

      .if !Funct
            jmp     GetOut
      .endif

;---------- [Fill the Properties Listbox] ----------
         and     GotCode, 0
         and     DataOn, 0
         and     CodeOn, 0
         and     LineCnt, 0
         and     StartOn, 0
;      INVOKE     LockWindowUpdate, hWnd
      .if Funct != 4
            and     StructOn, 0
         INVOKE     SendMessage, hWndFunct, LB_GETCOUNT, 0, 0
            mov     ItemCnt, eax
         INVOKE     SendMessage, hWndFunct, LB_GETCURSEL, 0, 0
            mov     RestPos, eax
         INVOKE     SendMessage, hWndFunct, LB_RESETCONTENT, 0, 0
            mov     eax, Prop
         .if eax != SavProp
            .if Prop != 5
                  mov     ecx, WS_CHILD or WS_VISIBLE or WS_BORDER or WS_HSCROLL or WS_VSCROLL or\
                          LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or LBS_NOTIFY or LBS_OWNERDRAWFIXED or\
                          LBS_SORT
            .else
                  mov     ecx, WS_CHILD or WS_VISIBLE or WS_BORDER or WS_HSCROLL or WS_VSCROLL or\
                          LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or LBS_NOTIFY or LBS_OWNERDRAWFIXED
            .endif
;            INVOKE     SetWindowLong, hWndFunct, GWL_STYLE, ecx
              call     CreateProp
         .endif
      .endif

      .if Prop != 8
            xor     ecx, ecx
            lea     eax, szStart
            mov     ebx, [eax]
            mov     cx, word ptr[eax+4]
          MOVmd     Cnt, BytesOut
            xor     eax, eax
            mov     edx, pMemM
         .while (Cnt)
            .if !StartOn
               .if dword ptr[edx+eax] == ebx && word ptr[edx+eax+4] == cx
                     mov     StartOn, 1
               .endif
            .endif
            .if byte ptr[edx+eax] == 09h
                  mov     byte ptr [edx+eax], ' '
            .endif
               inc     eax
               dec     Cnt
         .endw
      .endif
         
      .if !StartOn
            mov     GotCode, 1
            mov     CodeOn, 1
      .endif

;---------- [Start of file loop] ----------
         mov     byte ptr WorkBuff, 0
         mov     ecx, BytesOut
         xor     eax, eax
         xor     edi, edi
         mov     edx, pMemM
      .while (ecx)
         .if byte ptr [edx+eax] == 0dh
               inc     LineCnt
         .endif

         .if Funct == 4 && Prop == 8
               mov     ebx, LineNum
            .if LineCnt > ebx
                  jmp     AllDone
            .endif
         .endif

         .if byte ptr [edx+eax-1] == ' ' && Prop != 5 && Prop != 6 ||\
             byte ptr [edx+eax-1] == 0ah ||\
             byte ptr [edx+eax] == ' ' && Prop != 5 && Prop != 6 ||\
             byte ptr [edx+eax] == 0ah

            .if Funct == 4 || Funct != 4 && Prop == 4   ; Procedures
               .if !GotCode
                  .if dword ptr [edx+eax] == 'doc.' && byte ptr [edx+eax+5] == 0dh ||\
                      dword ptr [edx+eax] == 'DOC.' && byte ptr [edx+eax+5] == 0dh
                        mov     GotCode, 1
                  .endif
                     jmp     Pass
               .endif

               .if dword ptr [edx+eax] == 'CORP' || dword ptr [edx+eax] == 'corp'
                  .if byte ptr [edx+eax+4] == ' ' || byte ptr [edx+eax+4] == 0dh
                        mov     Saveax, eax
                        jmp     GetEm
                  .endif
               .endif
                  jmp     Pass

            .elseif Funct != 4 && Prop == 0             ; Macro's
               .if dword ptr [edx+eax] == 'RCAM' && byte ptr [edx+eax+4] == 'O' ||\
                   dword ptr [edx+eax] == 'rcam' && byte ptr [edx+eax+4] == 'o'
                     inc     eax
                     mov     Saveax, eax
                     jmp     GetEm
               .endif
                  jmp     Pass

            .elseif Funct != 4 && Prop == 1             ; Constant's
               .if dword ptr [edx+eax] == ' uqe' || dword ptr [edx+eax] == ' UQE'
                     mov     Saveax, eax
                     jmp     GetEm
               .endif
                  jmp     Pass

            .elseif Funct != 4 && Prop == 2 && DataOn   ; Data area
               .if dword ptr [edx+eax] == 'URTS' && word ptr [edx+eax+4] == 'TC' ||\
                   dword ptr [edx+eax] == 'urts' && word ptr [edx+eax+4] == 'tc'
                     mov     StructOn, 1
               .endif
               .if dword ptr [edx+eax] == 'SDNE' || word ptr [edx+eax] == 'sdne'
                     and     StructOn, 0
               .endif
               .if StructOn
                     jmp     Pass
               .endif
               .if dword ptr [edx+eax] == ' dd ' || dword ptr [edx+eax] == ' DD ' ||\
                   dword ptr [edx+eax] == ' wd ' || dword ptr [edx+eax] == ' WD ' ||\
                   dword ptr [edx+eax] == ' bd ' || dword ptr [edx+eax] == ' BD ' ||\
                   dword ptr [edx+eax] == 'laer' || dword ptr [edx+eax] == 'LAER'
                     mov     Saveax, eax
                     jmp     GetEm
               .endif
               .if dword ptr [edx+eax] == ' uqe' || dword ptr [edx+eax] == ' UQE' ||\
                   dword ptr [edx+eax] == 'rowd' || dword ptr [edx+eax] == 'ROWD' ||\
                   dword ptr [edx+eax] == 'drow' || dword ptr [edx+eax] == 'DROW' ||\
                   dword ptr [edx+eax] == 'etyb' || dword ptr [edx+eax] == 'ETYB'
                     mov     Saveax, eax
                     jmp     GetEm
               .endif
                  jmp     Pass

            .elseif Funct != 4 && Prop == 3             ; Structure's
               .if dword ptr [edx+eax] == 'URTS' && word ptr [edx+eax+4] == 'TC' ||\
                   dword ptr [edx+eax] == 'urts' && word ptr [edx+eax+4] == 'tc'
                     add     eax, 2
                     mov     Saveax, eax
                     jmp     GetEm
               .endif
                  jmp     Pass

            .elseif Funct != 4 && Prop == 5 && CodeOn ||\   ; Label's
                    Funct != 4 && Prop == 6 && CodeOn
                  mov     Blank5, 1
               .if byte ptr [edx+eax] == 0dh
                     jmp     Pass
               .endif
               .if byte ptr [edx+eax] != ' '
                     and     Blank5, 0
               .endif
                  mov     cnt, 32
                 push     eax
               .while (cnt)
                  .if byte ptr [edx+eax] == 0dh
                        pop     eax
                        jmp     Pass
                  .endif
                  .if byte ptr [edx+eax] == ' '
                        mov     Blank5, 1
                  .endif
                  .if byte ptr [edx+eax] == ':'
                        mov     Saveax, eax
                        pop     eax
                        jmp     GetEm
                  .endif
                     inc     eax
                     dec     cnt
               .endw
                  pop     eax
                  jmp     Pass

GetEm:
               .while (TRUE || !eax)
                  .if byte ptr [edx+eax] == ';'
                     .break
                  .elseif byte ptr [edx+eax] == 0dh || !eax
                        xor     edi, edi
                        mov     Blank, 1
                        and     Incr, 0
                     .if !eax    ; Added 08-21-2002
                           sub     eax, 2
                           add     ecx, 2
                     .endif
                        add     eax, 2
                        sub      ecx, 2
                        mov     esi, Saveax
                        sub     esi, eax
                        mov     SavPos, esi
                     .if Funct != 4 && Prop != 5 && Prop != 6
                           add     esi, 4
                           mov     ebx, Saveax
                        .if dword ptr [edx+ebx] == 'LAER' || dword ptr [edx+ebx] == 'laer'
                              add     esi, 2
                        .endif
                        .if dword ptr [edx+ebx] == 'ROWD' || dword ptr [edx+ebx] == 'rowd'
                              add     esi, 2
                        .endif
                     .elseif Funct != 4 && Prop == 5 || Funct != 4 && Prop == 6
                           inc     esi
                     .endif

                     .while (esi)
                        .if byte ptr [edx+eax-1] == ' ' && byte ptr [edx+eax+3] == ' '
                           .if byte ptr [edx+eax] == 'm' && byte ptr [edx+eax+1] == 'o' &&\
                               byte ptr [edx+eax+2] == 'v' || byte ptr [edx+eax] == 'M' &&\
                               byte ptr [edx+eax+1] == 'O' && byte ptr [edx+eax+2] == 'V'
                                push     eax
                                push     ecx
                                 jmp     NoOut
                           .endif
                        .endif
                           mov     bl, [edx+eax]
                           mov     byte ptr WorkBuff[edi], bl

                          push     eax
                           mov     eax, Incr
                        .if eax < SavPos && bl != ' '
                              and     Blank, 0
                        .endif
                           pop     eax

                           inc     Incr
                           inc     eax
                           inc     edi
                           dec     esi
                     .endw
                        mov     byte ptr WorkBuff[edi], 0
                       push     eax
                       push     ecx

                     .if Funct == 4 && Prop == 8
                           jmp     NoOut
                     .endif

                     .if Funct != 4
                        .if Prop != 2 && Prop != 5 && Prop != 6 || Prop == 2 && !Blank ||\
                            Prop == 5 && !Blank5 || Prop == 6 && !Blank5
                           INVOKE     SendMessage, hWndFunct, LB_ADDSTRING, 0, addr WorkBuff
                              mov     ecx, LineCnt
                              inc     ecx
                           INVOKE     SendMessage, hWndFunct, LB_SETITEMDATA, eax, ecx
                        .endif
                     .else
                        INVOKE     SendMessage, hCombo01, CB_ADDSTRING, 0, offset WorkBuff
                           mov     ecx, LineCnt
                           inc     ecx
                        INVOKE     SendMessage, hCombo01, CB_SETITEMDATA, eax, ecx
                     .endif

NoOut:
                        xor     edi, edi
                        mov     edx, pMemM
                        pop     ecx
                        pop     eax
                     .break
                  .endif
                     dec     eax
               .endw
                  mov     eax, Saveax

;               .if Funct == 4
;                     jmp     Pass
;               .endif

;               .if Funct != 4
;                     jmp     Pass
;               .endif

;               .if dword ptr [edx+eax] == 'OVNI' || dword ptr [edx+eax] == 'ovni' ||\
;                   dword ptr [edx+eax] == 'LLAC' || dword ptr [edx+eax] == 'llac'
;                  .while (TRUE)
;                        mov     bl, byte ptr [edx+eax]
;                     .if bl != 0dh
;                           mov     byte ptr WorkBuff[edi], bl
;                     .else
;                           inc     LineCnt
;                           mov     byte ptr WorkBuff[edi], 0
;                          push     eax
;                          push     ecx
;                        INVOKE     SendMessage, hWndFunct, LB_ADDSTRING, 0, addr WorkBuff
;                        INVOKE     SendMessage, hWndFunct, LB_SETITEMDATA, eax, LineCnt
;                           xor     edi, edi
;                           mov     edx, pMemM
;                           pop     ecx
;                           pop     eax
;                        .break
;                     .endif
;                        inc     edi
;                        inc     eax
;                        dec     ecx
;                  .endw
;               .endif

            .elseif Funct != 4 && Prop == 2  ; Data area
               .if dword ptr [edx+eax] == 'tad.' || dword ptr [edx+eax] == 'TAD.'
                     mov     DataOn, 1
               .endif
               .if !DataOn
                     jmp     Pass
               .endif

            .elseif Funct != 4 && Prop == 5 || Funct != 4 && Prop == 6  ; Label's
               .if !CodeOn
                  .if dword ptr [edx+eax] == 'doc.' || dword ptr [edx+eax] == 'DOC.'
                        mov     CodeOn, 1
                  .endif
               .endif
;            .else
;jmp     Pass
            .endif
         .endif

Pass:
         .if  Funct != 4 && byte ptr ExtType != 'i' && byte ptr ExtType+2 != 'c' && Prop != 0
            .if Prop == 0 || Prop == 1 || Prop == 2 || Prop == 3
               .if Prop == 1 && dword ptr [edx+eax] == 'tad.' ||\
                   Prop == 1 && dword ptr [edx+eax] == 'TAD.' ||\
                   Prop != 1 && dword ptr [edx+eax] == 'doc.' ||\
                   Prop != 1 && dword ptr [edx+eax] == 'DOC.'
                  .if byte ptr [edx+eax-1] != ',' && byte ptr [edx+eax-1] != "'"
;                     INVOKE     LockWindowUpdate, 0
                        jmp     EndIt
                  .endif
               .endif
            .endif
         .endif
             inc     eax
            dec     ecx
      .endw

AllDone:
;      INVOKE     LockWindowUpdate, 0
      .if Funct == 1 || Funct == 4
            jmp     EndIt
      .endif

GetOut:
EndIt:
      .if  Funct != 4
         INVOKE     SendMessage, hWndFunct, LB_GETCOUNT, 0, 0
         .if eax != ItemCnt
               mov     RestPos, -1
         .endif

            mov     eax, SavProp
         .if eax == Prop
            INVOKE     SendMessage, hWndFunct, LB_SETCURSEL, RestPos, 0
         .endif
          MOVmd     SavProp, Prop
      .endif
      INVOKE     HeapDestroy, hMemM
      INVOKE     SetFocus, hREdit

         ret
WriteReadMem ENDP

;===================================================
; esi = input string pointer ecx = len get before call
; returns string converted to lower case
;===================================================
LowerCase PROC

         xor     eax, eax
      .while ecx
         .if byte ptr[esi+eax] >= 'A' && byte ptr[esi+eax] <= 'Z'
;               and     byte ptr[esi+eax], 0dfh  ; and off lower case bit
               add     byte ptr[esi+eax], 20h   ; add 20h to upper case bit
         .endif
            inc     eax
            dec     ecx
      .endw
         ret

LowerCase ENDP

;=====================================================================
; Parses the command line and extracts the exe root dir and if
; available builds a full path name , file name, ext name and filling
; in the needed ofn words
;=====================================================================
ParseCommandLine PROC  uses esi edi
LOCAL    Len:DWORD
LOCAL    szWork[256]:BYTE

         and     Len, 0
      INVOKE     lstrcpy, addr szWork, CommandLine
      INVOKE     lstrlen, addr szWork
         sub     eax, 2
      .if byte ptr szWork == '"'
         .if byte ptr szWork[eax] == '"'
               jmp     GetRoot
         .else
               add     eax, 2
               mov     ecx, eax
               lea     esi, szWork
               lea     edi, WorkBuff
            .while (ecx)
                  mov     al, byte ptr[esi]
               .if al == '"'
                     inc     esi
                     dec     ecx
               .else
                     mov     byte ptr[edi], al
                     inc     esi
                     inc     edi
                     dec     ecx
               .endif
            .endw
               mov     byte ptr[edi], 0
            INVOKE     lstrcpy, CommandLine, addr WorkBuff
         .endif
      .endif
      INVOKE     lstrlen, CommandLine          ;Saved address of commandline
         mov     ecx, eax
         mov     edi, CommandLine              ;Saved address of commandline
      .if byte ptr[edi] == 22h
            jmp     GetRoot
      .endif
         sub     ecx, 2
         add     edi, 2
         mov     eax, 3ah                      ; Look for colon in commandline
       repnz     scasb
;       jecxz     GetRoot                       ; Not from command or association
.if !ecx
      jmp     GetRoot
.endif
         add     ecx, 2
         sub     edi, 2
         mov     Len, ecx                      ; Save length of arg
        push     edi
      INVOKE     lstrcpy, addr PathName, edi   ; Copy PathName
         pop     edi
         mov     ecx, Len
         mov     eax, 2eh                      ; Look for period in commandline
       repnz     scasb
        push     eax
      INVOKE     lstrcpy, addr ExtType, edi    ; Copy ExtType
         pop     eax
;         mov     ofn.nFileExtension, ax
         mov     ecx, 3
         lea     esi, ExtType
        call     LowerCase                     ; Convert to lowercase
      INVOKE     lstrlen, addr PathName
      .if byte ptr PathName[eax-1] == '"'
           push     eax
         INVOKE     lstrcpyn, addr PathName, addr PathName, eax  ; Remove '"'
         INVOKE     lstrlen, addr ExtType
         INVOKE     lstrcpyn, addr ExtType, addr ExtType, eax    ; Remove '"'
            pop     eax
            dec     eax
      .endif
         lea     edi, PathName
         add     edi, eax
      .while (eax)
         .if byte ptr[edi] == 5ch              ; \
              .break 
         .endif
            dec     eax
            dec     edi
      .endw
         add     edi, 1
      INVOKE     lstrcpy, addr FileName, edi   ; Copy FileName

GetRoot:
      INVOKE     lstrlen, CommandLine
         mov     edi, CommandLine
         add     edi, eax
         sub     edi, Len
      .while (eax)
         .if byte ptr[edi] == 5ch              ; \
              .break 
         .endif
            dec     eax
            dec     edi
      .endw
         add     edi, 2
         sub     edi, CommandLine
        push     edi
      INVOKE     lstrcpy, addr WorkBuff, CommandLine
         pop     edi
         mov     eax, offset WorkBuff
      .if WorkBuff == 22h                      ; "
            inc     eax
            dec     edi
      .endif
      INVOKE     lstrcpyn, addr RootDir, eax, edi ;Copy RootDir
;INVOKE    MessageBox,NULL, CommandLine, addr AppName, MB_OK
;INVOKE    MessageBox,NULL, addr RootDir, addr AppName, MB_OK
;INVOKE    MessageBox,NULL, addr PathName, addr AppName, MB_OK
;INVOKE    MessageBox,NULL, addr FileName, addr AppName, MB_OK
;INVOKE    MessageBox,NULL, addr ExtType, addr AppName, MB_OK
         ret
ParseCommandLine ENDP

;===================================================
; Read file  PROCEDURE
;===================================================
ReadF PROC  uses ebx
LOCAL    hFile:DWORD

      .if hpMem
         INVOKE     GlobalUnlock, fpMem
         INVOKE     GlobalFree, hpMem
            mov     hpMem, 0
      .endif

      INVOKE     SendMessage, hREdit, EM_SETREADONLY, FALSE, 0
         mov     ebx, hBuff
      INVOKE     CreateFile, ebx,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 0, OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE, 0
         jmp     ChkHandle

ReadOnlyFile:
      INVOKE     SendMessage, hREdit, EM_SETREADONLY, TRUE, 0
         mov     ebx, hBuff
      INVOKE     CreateFile, ebx,\
                 GENERIC_READ, FILE_SHARE_READ,\
                 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0

ChkHandle:
      .if eax == INVALID_HANDLE_VALUE
           call     GetLastError
         .if eax == 32
            INVOKE     MessageBox, hWnd, addr szAccess, addr AppName, MB_YESNO
            .if eax == IDYES
                  jmp     ReadOnlyFile
            .endif
               xor     eax, eax
               jmp     NoFile
         .else
            INVOKE     MessageBox, NULL, addr szFileError, addr AppName, MB_OK
               xor     eax, eax
               jmp     NoFile
         .endif
      .endif
         mov     hFile, eax
      INVOKE     GetFileSize, hFile, 0
         mov     ebx, eax
      INVOKE     GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, ebx
         mov     hpMem, eax
      INVOKE     GlobalLock, hpMem
         mov     fpMem, eax
      INVOKE     ReadFile, hFile, fpMem, ebx, addr BytesR, NULL
        push     eax
      INVOKE     CloseHandle, hFile
         pop     eax

NoFile:
         ret
ReadF ENDP

;===================================================
; Write file PROCEDURE
;===================================================
WriteF PROC
LOCAL    hFile:DWORD, BytesOut

         mov     ecx, hBuff
      INVOKE     CreateFile, ecx,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,\
                 NULL
      .if eax == INVALID_HANDLE_VALUE
            xor     eax, eax
            jmp     NoFile
      .endif
         mov     hFile, eax
      INVOKE     WriteFile, hFile, fpMem, BytesR, addr BytesOut, NULL
        push     eax
      INVOKE     CloseHandle, hFile
         pop     eax

NoFile:
         ret
WriteF ENDP

;===================================================
; Copy files Dialog PROCEDURE
;===================================================
CopyFiles PROC uses ebx hdlg:DWORD, wMsg, wParam, lParam
LOCAL    Cnt:DWORD, SaveAddr
LOCAL    szWork[256]:BYTE, szBuff1[256]:BYTE

      .if wMsg == WM_INITDIALOG
          MOVmd     hCopyFile, hdlg
          MOVmd     hWndDlg, hdlg
            mov     Run, 2

         INVOKE     ReadTheFile, addr WorkBuff
            and     Run, 0
;         INVOKE     lstrcat, addr WorkBuff, addr szProject
            mov     ebx, ProjGroup
         INVOKE     lstrcat, addr WorkBuff, ProjNamArray[ebx*4]

;         INVOKE     SetDlgItemText, hdlg, 401, addr szProject
         INVOKE     SetDlgItemText, hdlg, 401, ProjNamArray[ebx*4]

         INVOKE     GetDlgItem, hdlg, 701
         .if Tdll
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
         .else

            INVOKE     EnableWindow, eax, 0
         .endif
         INVOKE     GetDlgItem, hdlg, 702
         .if Tlib
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
         .else
            INVOKE     EnableWindow, eax, 0
         .endif
         INVOKE     GetDlgItem, hdlg, 703
         .if Tinc
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
         .else
            INVOKE     EnableWindow, eax, 0
         .endif
         INVOKE     GetDlgItem, hdlg, 704
         .if Texe
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
         .else
            INVOKE     EnableWindow, eax, 0
         .endif
         INVOKE     GetDlgItem, hdlg, 801
            mov     h42, eax
         INVOKE     GetDlgItem, hdlg, 802
            mov     h43, eax

      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
            and     eax, 0ffffh
            mov     ebx, wParam
            shr     ebx, 16

         .if ebx == BN_CLICKED
            INVOKE     GetFocus
            INVOKE     GetDlgCtrlID, eax
         .endif

         .if eax == 801                ; Copy
               and     Cnt, 0
            INVOKE     IsDlgButtonChecked, hdlg, 701    ; dll
            .if eax
                  lea     eax, szDll
                  mov     SaveAddr, eax
                  inc     Cnt
            .endif
            INVOKE     IsDlgButtonChecked, hdlg, 702    ; lib
            .if eax
                  lea     eax, szLib
                  mov     SaveAddr, eax
                  inc     Cnt
            .endif
            INVOKE     IsDlgButtonChecked, hdlg, 703    ; inc
            .if eax
                  lea     eax, szInc
                  mov     SaveAddr, eax
                  inc     Cnt
            .endif
            INVOKE     IsDlgButtonChecked, hdlg, 704    ; exe
            .if eax
                  lea     eax, szExe
                  inc     eax
                  mov     SaveAddr, eax
                  inc     Cnt
            .endif
            .if Cnt != 1
               .if !Cnt
                  INVOKE     MessageBox, NULL, addr szNoSel, addr AppName, MB_OK
               .elseif Cnt > 1
                  INVOKE     MessageBox, NULL, addr szMultSel, addr AppName, MB_OK
               .endif
                  jmp     CopyFilesDone
            .endif

            INVOKE     lstrcpy, addr szBuff1, addr WorkBuff
            INVOKE     lstrcat, addr szBuff1, addr szPer
            INVOKE     lstrcat, addr szBuff1, SaveAddr        ; File extension
   
            INVOKE     lstrcpy, addr szWork, addr PathName
               mov     ecx, hBuff
            INVOKE     lstrcpy, ecx, addr szBuff1
               mov     ecx, hBuff
            INVOKE     lstrcpy, addr PathName, ecx
              call     ReadF
            .if eax
                  mov     SaveAs, 1
                  mov     SaveFlg1, 5
                 call     SaveFile
            .endif
            .if hpMem
               INVOKE     GlobalUnlock, fpMem
               INVOKE     GlobalFree, hpMem
                  mov     hpMem, 0
            .endif
            INVOKE     lstrcpy, addr PathName, addr szWork

         .elseif eax == 802
               jmp     CancelOut
         .endif

      .elseif wMsg == WM_CLOSE
            jmp     CancelOut
      .endif
         jmp     CopyFilesDone

CancelOut:
         and     hCopyFile, 0
         and     hWndDlg, 0
      INVOKE     SetFocus, hREdit
      INVOKE     DestroyWindow, hdlg ; End the dialog
         mov     eax, TRUE           ; Return
         jmp     CopyFilesRet        ; with TRUE

CopyFilesDone:
         mov     eax, FALSE          ; Return with FALSE

CopyFilesRet:
         ret

CopyFiles ENDP

;======================================================
; Find Replace  set varibles Procedure
;======================================================
FindRep PROC hwnd:DWORD, lpInput, lpReplace

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

FindNext:
;         mov     eax, hwnd
;      .if eax == hREdit
;         INVOKE     SendMessage, hwnd, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD or FR_MATCHCASE, addr ft
;      .else
         INVOKE     SendMessage, hwnd, EM_FINDTEXT, FR_DOWN, addr ft
;      .endif
      .if eax != -1
            mov     ft.chrg.cpMin, eax
            inc     ft.chrg.cpMin
            mov     cr.cpMin, eax
            mov     cr.cpMax, eax
         INVOKE     lstrlen, lpInput
            add     cr.cpMax, eax ;6
         INVOKE     SendMessage, hwnd, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hwnd, EM_REPLACESEL, TRUE, lpReplace
            jmp     FindNext
      .endif

         ret
FindRep ENDP

;=======================================
; Includes and Libraries Dialog
;=======================================
IncLib PROC uses ebx esi hdlg:DWORD, wMsg, wParam, lParam
LOCAL    Cnt:DWORD, Num
LOCAL    HutchDir[256]:BYTE, szBuff1[256]:BYTE, szBuff2[256]:BYTE, szListName[256]:BYTE
LOCAL    szOutPut1[1024]:BYTE, szOutPut2[1024]:BYTE

      .if wMsg == WM_INITDIALOG                  ; If message is INITDIALOG then
          MOVmd     hWndDlg, hdlg
         INVOKE     GetDlgItem, hdlg, 445        ; Get the handle of the Listbox
            mov     h45, eax
         INVOKE     GetDlgItem, hdlg, 545        ; Get the handle of the button
            mov     h42, eax

            lea     esi, offset szIncLib
            xor     eax, eax

Getlen:
         .if byte ptr[esi+eax] == 2ch
               mov     Num, eax
               inc     Num 
            INVOKE     lstrcpyn, addr szBuff1, esi, Num
            INVOKE     SendMessage, h45, LB_ADDSTRING, 0, addr szBuff1
               add     esi, Num
               xor     eax, eax
               jmp     Getlen
         .elseif byte ptr[esi+eax] == 0h
            INVOKE     SendMessage, h45, LB_SETSEL, TRUE, 0
               jmp     LoadedOK
         .endif
            inc     eax
            jmp     Getlen

LoadedOK:
      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLORLISTBOX ||  wMsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam
            jmp     IncLibDone

      .elseif wMsg == WM_CLOSE

EndIt:
            and     hWndDlg, 0
         INVOKE     EndDialog, hdlg, 0
            mov     eax, TRUE
            and     hIncLib, 0
            jmp     IncLibRet

      .elseif wMsg != WM_COMMAND
            jmp     IncLibDone
      .endif

         mov     eax, wParam
        cwde
         mov     ebx, wParam
         shr     ebx, 16

      .if ebx == BN_CLICKED
         INVOKE     GetFocus
         INVOKE     GetDlgCtrlID, eax
      .endif

      .if eax == 545
            mov     lpcbData, sizeof HutchDir
         INVOKE     RegQuerySZ, addr rDEFb, addr HutchDir
            mov     byte ptr szOutPut1, 0
            mov     byte ptr szOutPut2, 0
         INVOKE     SendMessage, h45, LB_SETSEL, TRUE, 0   ; To make sure Windows.inc is selected
         INVOKE     SendMessage, h45, LB_GETSELCOUNT, 0, 0
            mov     ecx, eax
         INVOKE     SendMessage, h45, LB_GETSELITEMS, ecx, addr szListName
            mov     Num, eax
            and     Cnt, 0
         .while (Num)
               mov     ecx, Cnt
            INVOKE     SendMessage, h45, LB_GETTEXT, dword ptr szListName[ecx*4], addr szBuff2
            INVOKE     lstrcat, addr szOutPut1, addr szIncInc1
            .if !Cnt
               INVOKE     lstrcat, addr szOutPut1, addr AsmRootDir
            .else
               INVOKE     lstrcat, addr szOutPut1, addr HutchDir
            .endif
            INVOKE     lstrcat, addr szOutPut1, addr szIncInc2
            INVOKE     lstrcat, addr szOutPut1, addr szBuff2
            INVOKE     lstrcat, addr szOutPut1, addr szPer
            INVOKE     lstrcat, addr szOutPut1, addr szInc
            INVOKE     lstrcat, addr szOutPut1, addr szCRLF
            .if Cnt
               INVOKE     lstrcat, addr szOutPut2, addr szIncLib1
               INVOKE     lstrcat, addr szOutPut2, addr HutchDir
               INVOKE     lstrcat, addr szOutPut2, addr szIncLib2
               INVOKE     lstrcat, addr szOutPut2, addr szBuff2
               INVOKE     lstrcat, addr szOutPut2, addr szPer
               INVOKE     lstrcat, addr szOutPut2, addr szLib
               INVOKE     lstrcat, addr szOutPut2, addr szCRLF
            .endif
               inc     Cnt
               dec     Num
         .endw
         INVOKE     lstrcpy, hOutPut, addr szOutPut1
         INVOKE     lstrcat, hOutPut, addr szCRLF
         INVOKE     lstrcat, hOutPut, addr szOutPut2
         INVOKE     lstrcat, hOutPut, addr szCRLF
         INVOKE     SendMessage, hREdit, EM_HIDESELECTION, 1, 0
         INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, hOutPut
         INVOKE     SendMessage, hREdit, EM_HIDESELECTION, 0, 0
            jmp     EndIt
      .endif

IncLibDone:
         mov     eax, FALSE           ; Return with FALSE

IncLibRet:
         ret

IncLib ENDP

;===================================================
; User code procedure
;===================================================
QuickCode PROC wParam:DWORD, dwCode
LOCAL    szWork[10]:BYTE, szBuff[10]:BYTE, szBuff1[1024]:BYTE, szBuff2[256]:BYTE

;---------- [IDM_BUTTBUILD = ButBuild - IDM_TOOLBUILD = ToolBuild - IDM_TABBUILD = TabBuild] ----------
      .if wParam == IDM_BUTTBUILD || wParam == IDM_TOOLBUILD || wParam == IDM_TABBUILD || wParam == IDM_CALC
         INVOKE     SetCurrentDirectory, addr RootDir
      .endif

      .if wParam == IDM_BUTTBUILD
         INVOKE     lstrcpy, addr szBuff2, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff2, addr szButBuild
         INVOKE     ShellExecute, hWnd, addr szOpen, addr szBuff2, NULL, NULL, SW_SHOWNORMAL
            ret

      .elseif wParam == IDM_TABBUILD
         INVOKE     lstrcpy, addr szBuff2, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff2, addr szTabBuild
         INVOKE     ShellExecute, hWnd, addr szOpen, addr szBuff2, NULL, NULL, SW_SHOWNORMAL
            ret

      .elseif wParam == IDM_TOOLBUILD
         INVOKE     lstrcpy, addr szBuff2, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff2, addr szToolBuild
         INVOKE     ShellExecute, hWnd, addr szOpen, addr szBuff2, NULL, NULL, SW_SHOWNORMAL
            ret

      .elseif wParam == IDM_CALC
         INVOKE     lstrcpy, addr szBuff2, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff2, addr szCalculator
         INVOKE     ShellExecute, hWnd, addr szOpen, addr szBuff2, NULL, NULL, SW_SHOWNORMAL
            ret

      .elseif wParam > 7500 && wParam < 7513 || wParam == IDM_MDIEDIT || wParam == IDM_MDINOEDIT
         INVOKE     lstrcpy, addr szBuff2, addr AsmRootDir
         .if wParam == IDM_MDIEDIT || wParam == IDM_MDINOEDIT
            INVOKE     lstrcat, addr szBuff2, addr szTemplatesM
         .else
            INVOKE     lstrcat, addr szBuff2, addr szTemplatesC
         .endif

         .if wParam == 7501
            INVOKE     CreateDialogParam, hInst, IDD_INCLIB, hREdit, offset IncLib, 0
               mov     hIncLib, eax
               ret
         .elseif wParam == 7502
            INVOKE     lstrcat, addr szBuff2, addr szRegClass
         .elseif wParam == 7503
            INVOKE     lstrcat, addr szBuff2, addr szOpenFile
         .elseif wParam == 7504
            INVOKE     lstrcat, addr szBuff2, addr szSaveFile
         .elseif wParam == 7505
            INVOKE     lstrcat, addr szBuff2, addr szCreateFileR
         .elseif wParam == 7506
            INVOKE     lstrcat, addr szBuff2, addr szCreateFileW
         .elseif wParam == 7507
            INVOKE     lstrcat, addr szBuff2, addr szChooseFont
         .elseif wParam == 7508
            INVOKE     lstrcat, addr szBuff2, addr szChooseColor
         .elseif wParam == 7509
            INVOKE     lstrcat, addr szBuff2, addr szFindRep
         .elseif wParam == 7510
            INVOKE     lstrcat, addr szBuff2, addr szPageSetup
         .elseif wParam == 7511
            INVOKE     lstrcat, addr szBuff2, addr szPrint
         .elseif wParam == 7512
            INVOKE     lstrcat, addr szBuff2, addr szAllCommon
         .elseif wParam == IDM_MDIEDIT
            INVOKE     lstrcat, addr szBuff2, addr szMDIEdit
         .elseif wParam == IDM_MDINOEDIT
            INVOKE     lstrcat, addr szBuff2, addr szMDINoEdit
         .endif

            mov     ecx, hBuff
         INVOKE     lstrcpy, ecx, addr szBuff2
           call     ReadF
         .if eax
            INVOKE     MessageBox, NULL, addr szSeparate, addr AppName,\
                       MB_YESNO or MB_ICONQUESTION or MB_TASKMODAL
            .if eax == IDYES
;                  mov     NewOn, 1
               INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_NEW, 0
            .endif

            INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
             MOVmd     cr.cpMax, cr.cpMin
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, fpMem
         .endif
         .if hpMem
            INVOKE     GlobalUnlock, fpMem
            INVOKE     GlobalFree, hpMem
               mov     hpMem, 0
         .endif

         .if wParam == IDM_MDIEDIT || wParam == IDM_MDINOEDIT

               mov     szBuff2, 0
               mov     lpcbData, sizeof szBuff2
            INVOKE     RegQuerySZ, addr rDEFb, addr szBuff2
            .if szBuff2 == ' ' || !szBuff2
               INVOKE     lstrcpy, addr szBuff2, addr RootDir
            .endif
            INVOKE     FindRep, hREdit, addr szPATHR, addr AsmRootDir
            INVOKE     FindRep, hREdit, addr szAsmEditDir, addr AsmRootDir
            INVOKE     FindRep, hREdit, addr szHutchDir, addr szBuff2
         .endif

      .elseif wParam == 7513 || wParam == IDM_EDITSAMP || wParam == IDM_NOEDITSAMP
         INVOKE     lstrcpy, addr szBuff2, addr AsmRootDir
         .if wParam == 7513
            INVOKE     lstrcat, addr szBuff2, addr szTemplatesC
            INVOKE     lstrcat, addr szBuff2, addr szAllComExe    ; All common controls
         .elseif wParam == IDM_EDITSAMP
            INVOKE     lstrcat, addr szBuff2, addr szTemplatesM
            INVOKE     lstrcat, addr szBuff2, addr szMDIwEexe     ; MDI with edit
         .elseif wParam == IDM_NOEDITSAMP
            INVOKE     lstrcat, addr szBuff2, addr szTemplatesM
            INVOKE     lstrcat, addr szBuff2, addr szMDInEexe     ; MDI no edit
         .endif
         INVOKE     ShellExecute, hWnd, addr szOpen, addr szBuff2, NULL, NULL, SW_SHOWNORMAL

      .elseif wParam > 8500 && wParam < 8541
            mov     ecx, wParam
            sub     ecx, 8500
         INVOKE     BaseAscii, ecx, addr szWork, 2, 10, 0, 1, 1
         INVOKE     lstrcpy, addr szBuff, addr szUser0140
         INVOKE     lstrcat, addr szBuff, addr szWork
         INVOKE     lstrcpy, addr szBuff2, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff2, addr szUserCode
         INVOKE     GetPrivateProfileString, addr szUserC, addr szBuff,\
                    addr szNULL, addr szBuff1, 255, addr szBuff2
;         INVOKE     SendMessage, hREdit, EM_EXGETSEL, 0, addr cr
;         INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
         INVOKE     lstrcat, addr szBuff1, addr szCR
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, TRUE, addr szBuff1
      .endif

         ret
QuickCode ENDP

;===================================================
; User Temp Dialog PROCEDURE
;===================================================
UserTemp PROC uses ebx hdlg:DWORD, wMsg, wParam, lParam
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    hReg:DWORD, hFind, hFindS, ChkType
LOCAL    szFileName[50]:BYTE, szBuff0[256]:BYTE, szBuff1[256]:BYTE, szBuff2[256]:BYTE, szWork[50]:BYTE

      .if wMsg == WM_INITDIALOG
          MOVmd     hUserTemp, hdlg

         INVOKE     GetDlgItem, hdlg, 903            ; Get the handle of the Browse
            mov     hReturn, eax                     ; Save it
         INVOKE     GetDlgItem, hdlg, IDCANCEL       ; Get the handle of the IDCANCEL
            mov     hCancel01, eax                   ; Save it
         INVOKE     GetDlgItem, hdlg, 30
         INVOKE     SetFocus, eax

         INVOKE     CreateWindowEx, WS_EX_CLIENTEDGE, addr ListBoxClass, 0,
                    WS_CHILD or WS_VSCROLL or WS_VISIBLE or LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or \
                    LBS_DISABLENOSCROLL or LBS_SORT,
                    18, 18, 150, 100, hdlg, 315, 0, 0
            mov     hListBox, eax

         INVOKE     lstrcpy, addr szBuff0, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff0, addr szTemplatesU
         INVOKE     lstrcpy, addr szBuff1, addr szBuff0
         INVOKE     lstrcat, addr szBuff0, addr szAll
            and     ChkType, 0

GetFirstF:
         INVOKE     FindFirstFile, addr szBuff0, addr FindData
           test     eax, eax
             js     NoFile
            mov     hFind, eax
            jmp     ChkFile

GetNextF:
         INVOKE     FindNextFile, hFind, addr FindData
           test     eax, eax
             jz     AllDone

;---------- [Validate File] ----------
ChkFile:
         .if byte ptr FindData.cFileName == '.'
               jmp     GetNextF
         .endif

         .if ChkType
            INVOKE     lstrlen, addr FindData.cFileName
               mov     bl, byte ptr FindData.cFileName[eax-3]
            .if bl == '.'
                  mov     bl, byte ptr FindData.cFileName[eax-2]
            .endif
            .if bl >= 'A' && bl <= 'Z'
                  add     bl, 20h
            .endif
            .if bl == 'a'
                  mov     Asm, 1
            .elseif bl == 'd'
                  mov     Def, 1
            .elseif bl == 'r'
                  mov     Rsc, 1
            .endif
               jmp     GetNextF
         .endif

         INVOKE     lstrcpy, addr szFileName, addr FindData.cFileName

;---------- [Check for types of files in the user folder] ----------
         INVOKE     lstrcpy, addr szBuff2, addr szBuff1
         INVOKE     lstrcat, addr szBuff2, addr FindData.cFileName
         INVOKE     lstrcat, addr szBuff2, addr szSlashB
         INVOKE     lstrcat, addr szBuff2, addr szAll

GetFirstSub:
         INVOKE     FindFirstFile, addr szBuff2, addr FindData
           test     eax, eax
             js     GetNextF
            mov     hFindS, eax
            jmp     ChkSub

GetNextSub:
         INVOKE     FindNextFile, hFindS, addr FindData
         .if eax == 0
            INVOKE     FindClose, hFindS
               jmp     GetNextF
         .endif

ChkSub:
         .if byte ptr FindData.cFileName == '.'
               jmp     GetNextSub
         .endif
         INVOKE     lstrlen, addr FindData.cFileName
            mov     bl, byte ptr FindData.cFileName[eax-3]
         .if bl == 'a' || bl == 'A'
            INVOKE     FindClose, hFindS
            INVOKE     SendMessage, hListBox, LB_ADDSTRING, 0, addr szFileName
               jmp     GetNextF
         .else
               jmp     GetNextSub
         .endif

AllDone:
         INVOKE     FindClose, hFind
         .if ChkType
               jmp     GetOut
         .endif

NoFile:
      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLORLISTBOX || wMsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_COMMAND
            mov     eax, wParam
           cwde
            mov     ebx, wParam
            shr     ebx, 16

         .if ebx == BN_CLICKED
            INVOKE     GetFocus
            INVOKE     GetDlgCtrlID, eax
         .endif

         .if eax == IDCANCEL
               and     Asm, 0
               jmp     GetOut

         .elseif eax == 903     ; Return
            INVOKE     SendMessage, hListBox, LB_GETCURSEL, 0, 0
            .if eax == -1
               INVOKE     MessageBox, NULL, addr szError14, addr ClassName,\
                          MB_OK or MB_ICONWARNING or MB_SYSTEMMODAL
                  jmp     Ret0
            .else
                  mov     ebx, eax
               INVOKE     SendMessage, hListBox, LB_GETTEXT, ebx, addr szWorkPgm
                  mov     ChkType, 1
               INVOKE     lstrcpy, addr szBuff0, addr AsmRootDir
               INVOKE     lstrcat, addr szBuff0, addr szTemplatesU
               INVOKE     lstrcat, addr szBuff0, addr szWorkPgm
               INVOKE     lstrcat, addr szBuff0, addr szSlashB
               INVOKE     lstrcat, addr szBuff0, addr szAll
                  jmp     GetFirstF
            .endif
         .endif

      .elseif wMsg == WM_CLOSE
            and     Asm, 0

GetOut:
            and     hListBox, 0
            and     hUserTemp, 0
         INVOKE     EndDialog, hdlg, 0
            mov     eax, TRUE
            ret
      .endif

Ret0:
         xor     eax, eax
         ret

UserTemp ENDP

;===================================================
; Create Project Dialog PROCEDURE
;===================================================
CreateProject PROC uses ebx esi edi hdlg:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    ofn:OPENFILENAME
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    hFind:DWORD, DllOn
LOCAL    szBuff0[256]:BYTE, szBuff1[256]:BYTE, szBuff2[256]:BYTE, szBlank[2]:BYTE
LOCAL    PtrBuild[1024*2]:BYTE, szProjectName[64]:BYTE, szProjDir[256]:BYTE
LOCAL    FileType[10]:BYTE, szExt[10]:BYTE

      .if wMsg == WM_INITDIALOG
          MOVmd     hCreateProj, hdlg
          MOVmd     ProjType, lParam
            and     AddinOn, 0
            and     hAddin, 0
         .if lParam == 21
               mov     AddinOn, 1
             MOVmd     hAddin, hdlg
            INVOKE     GetWindowRect, hREdit, addr rect
               add     rect.left, 2
               add     rect.top, 2
            INVOKE     SetWindowPos, hAddin, 0, rect.left, rect.top, 0, 0,\
                       SWP_NOSIZE or SWP_NOZORDER or SWP_SHOWWINDOW
         .endif

         INVOKE     GetDlgItem, hdlg, 801            ; Get the handle of the User
            mov     hUser, eax                       ; Save it
         INVOKE     GetDlgItem, hdlg, 802            ; Get the handle of the Step by step
            mov     hStep, eax                       ; Save it
         INVOKE     GetDlgItem, hdlg, 901            ; Get the handle of the Create
            mov     hCreate, eax                     ; Save it
         INVOKE     GetDlgItem, hdlg, 902            ; Get the handle of the Browse
            mov     hBrowse, eax                     ; Save it
         INVOKE     GetDlgItem, hdlg, IDCANCEL       ; Get the handle of the IDCANCEL
            mov     hCancel, eax                     ; Save it
         INVOKE     GetDlgItem, hdlg, 401
         INVOKE     SetFocus, eax

         .if ProjType == 1
            INVOKE     GetDlgItem, hdlg, 502
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
            INVOKE     GetDlgItem, hdlg, 504
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
            INVOKE     GetDlgItem, hdlg, 506
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
            INVOKE     GetDlgItem, hdlg, 507
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
            INVOKE     GetDlgItem, hdlg, 510
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
            INVOKE     GetDlgItem, hdlg, 512

         .elseif ProjType == 2 || ProjType == 21     ; 21 = Addin new project
            INVOKE     GetDlgItem, hdlg, 701
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
            .if ProjType == 21
               INVOKE     GetDlgItem, hdlg, 704
               INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
            .endif
         .elseif ProjType == 3
            INVOKE     GetDlgItem, hdlg, 701
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_UNCHECKED, 0
            INVOKE     GetDlgItem, hdlg, 706
            INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
         .endif
            mov     szRoot, 0
            mov     lpcbData, sizeof szRoot
         INVOKE     RegQuerySZ, addr rDEFb, addr szRoot
            mov     szBuff0, 0
            mov     lpcbData, sizeof szBuff0
         INVOKE     RegQuerySZ, addr rDEFp, addr szBuff0
         .if ProjType != 21
            INVOKE     SetDlgItemText, hdlg, 402, addr szBuff0
         .else
            INVOKE     lstrcpy, addr szBuff0, addr AsmRootDir
            INVOKE     lstrcat, addr szBuff0, addr szAddins
            INVOKE     SetDlgItemText, hdlg, 402, addr szBuff0
         .endif

      .elseif wMsg == WM_CTLCOLORDLG
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLORSTATIC
         INVOKE     GetDlgItem, hdlg, 34
         .if lParam != eax
            INVOKE     SetBkColor, wParam, Color.DialogBC
            INVOKE     SetTextColor, wParam, 00000000h
               mov     eax, hBRD

         .else
            INVOKE     SetBkColor, wParam, 00ffffeah
            INVOKE     SetTextColor, wParam, 00800000h
               mov     eax, hBRS
         .endif
            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
         INVOKE     DrawButt, lParam
            jmp     Ret0

      .elseif wMsg == WM_CLOSE
            mov     edi, -1
            jmp     CancelOut

      .elseif wMsg != WM_COMMAND    ; See if msg is a command
            jmp     Ret0
      .endif
         mov     eax, wParam
        cwde
         mov     ebx, wParam
         shr     ebx, 16

      .if ebx == BN_CLICKED
         INVOKE     GetFocus
         INVOKE     GetDlgCtrlID, eax
      .endif

         xor     edi, edi

      .if eax == IDCANCEL
            mov     edi, -1
            jmp     CancelOut

;---------- [Project with templates radio buttons
      .elseif eax == 504                                        ; Set no .rc
         INVOKE     IsDlgButtonChecked, hdlg, 505               ; Dialog as main window
         .if eax
            INVOKE     CheckRadioButton, hdlg, 503, 504, 503    ; Set .rc
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 508               ; No edit
         .if eax
            INVOKE     CheckRadioButton, hdlg, 503, 504, 503    ; Set .rc
         .endif

      .elseif eax == 505                                        ; Dialog as main window
         INVOKE     IsDlgButtonChecked, hdlg, 505
         .if eax
            INVOKE     CheckRadioButton, hdlg, 503, 504, 503    ; Set .rc
         .endif

      .elseif eax == 508                                        ; No edit
         INVOKE     IsDlgButtonChecked, hdlg, 504
         .if eax
            INVOKE     CheckRadioButton, hdlg, 503, 504, 503    ; Set .rc
         .endif

      .elseif eax == 509                                        ; MDI
         INVOKE     CheckRadioButton, hdlg, 503, 504, 503       ; Set .rc
         INVOKE     CheckRadioButton, hdlg, 501, 502, 502       ; Set no .dll

      .elseif eax == 510                                        ; No MDI
         INVOKE     CheckRadioButton, hdlg, 503, 504, 504       ; Set no .rc

;---------- [No templates
      .elseif eax > 700 && eax < 706
         INVOKE     IsDlgButtonChecked, hdlg, eax
         .if eax
            INVOKE     CheckDlgButton, hdlg, 706, BST_UNCHECKED
         .endif

      .elseif eax == 706
         INVOKE     IsDlgButtonChecked, hdlg, 706               ; Output only a .ptr file
         .if eax
            INVOKE     CheckDlgButton, hdlg, 701, BST_UNCHECKED
            INVOKE     CheckDlgButton, hdlg, 702, BST_UNCHECKED
            INVOKE     CheckDlgButton, hdlg, 703, BST_UNCHECKED
            INVOKE     CheckDlgButton, hdlg, 704, BST_UNCHECKED
            INVOKE     CheckDlgButton, hdlg, 705, BST_UNCHECKED
         .endif

      .elseif eax == 801                                        ; User templates
         INVOKE     DialogBoxParam, hInst, IDD_USERTEMP, hCreateProj, addr UserTemp, 0
         .if Asm                                                ; Return from UserTemplates 
            INVOKE     CheckRadioButton, hdlg, 501, 502, 502    ; Set no .dll
            INVOKE     CheckRadioButton, hdlg, 503, 504, 504    ; Set no .rc
            INVOKE     CheckRadioButton, hdlg, 511, 512, 512    ; Set no Folder, Pointer only
            .if Def
               INVOKE     CheckRadioButton, hdlg, 501, 502, 501 ; Set .dll
            .endif
            .if Rsc
               INVOKE     CheckRadioButton, hdlg, 503, 504, 503 ; Set .rc
            .endif
            INVOKE     lstrcpy, addr szBuff1, addr szWorkPgm
               mov     ProjType, 4
               jmp     FinishIt
         .endif

      .elseif eax == 802                                        ; Step by step
            mov     ProjType, 5
            jmp     FinishIt

      .elseif eax == 901         ; Create
;---------- [Build the pointer file

FinishIt:
            and     DllOn, 0
         INVOKE     GetDlgItemText, hdlg, 401, addr szProjectName, lengthof szProjectName
         .if !eax
            INVOKE     MessageBox, NULL, addr szError6, addr AppName,\
                       MB_OK or MB_ICONWARNING or MB_SYSTEMMODAL
               jmp     Ret0
         .endif
         INVOKE     GetDlgItemText, hdlg, 402, addr szProjDir, lengthof szProjDir
         INVOKE     lstrcpy, addr szBuffP, addr AsmRootDir
;         INVOKE     lstrcat, addr szBuffP, addr szPointer

      .if ProjGroup
         INVOKE     lstrcat, addr szBuffP, addr szPointUser

      .endif

         mov     ecx, ProjGroup
      INVOKE     lstrcat, addr szBuffP, PtrArray[ecx*4]

         INVOKE     lstrcat, addr szBuffP, addr szProjectName
         INVOKE     lstrcat, addr szBuffP, addr szPer
         INVOKE     lstrcat, addr szBuffP, addr szPtr
         INVOKE     GetFileAttributes, addr szBuffP
         .if eax != -1
            INVOKE     IsDlgButtonChecked, hdlg, 706
            .if eax || ProjType == 1 || AddinOn
               INVOKE     MessageBox, NULL, addr szError11, addr AppName,\
                          MB_OK or MB_ICONWARNING or MB_SYSTEMMODAL
                  jmp     Ret0
            .endif
         .endif
         INVOKE     lstrcpy, addr PtrBuild, addr szProjectName
         INVOKE     lstrcat, addr PtrBuild, addr szCol
         INVOKE     lstrcat, addr PtrBuild, addr szProjDir
         INVOKE     lstrcat, addr PtrBuild, addr szProjectName
         INVOKE     lstrcat, addr PtrBuild, addr szSlashB
         INVOKE     lstrlen, addr PtrBuild
            mov     BytesR, eax
         INVOKE     GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, 100000
            mov     hpMem, eax
         INVOKE     GlobalLock, hpMem
            mov     fpMem, eax
         INVOKE     lstrcpy, fpMem, addr PtrBuild
            mov     ecx, hBuff
         INVOKE     lstrcpy, ecx, addr szBuffP
           call     WriteF
         .if !eax || eax == INVALID_HANDLE_VALUE
            INVOKE     MessageBox, NULL, addr szError12, addr AppName,\
                       MB_OK or MB_ICONWARNING or MB_SYSTEMMODAL
         .endif
         .if hpMem
            INVOKE     GlobalUnlock, fpMem
            INVOKE     GlobalFree, hpMem
               mov     hpMem, 0
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 706
         .if eax
               jmp     CancelOut
         .endif

;---------- [Without templates
         .if ProjType > 1 && ProjType != 4    ; 4 = User pgms
               jmp     BuildFiles
         .endif

;---------- [With templates
         INVOKE     lstrcpy, addr szWorkPgm, addr szPgm01
         INVOKE     IsDlgButtonChecked, hdlg, 501
         .if eax
               mov     DllOn, 1
            INVOKE     lstrcpy, addr szWorkPgm, addr szPgm05
            INVOKE     IsDlgButtonChecked, hdlg, 503
            .if eax
               INVOKE     lstrcpy, addr szWorkPgm, addr szPgm06
               INVOKE     IsDlgButtonChecked, hdlg, 508
               .if eax
                  INVOKE     lstrcpy, addr szWorkPgm, addr szPgm08
               .endif
            .endif
         .else

            INVOKE     IsDlgButtonChecked, hdlg, 503
            .if eax
               INVOKE     lstrcpy, addr szWorkPgm, addr szPgm02
               INVOKE     IsDlgButtonChecked, hdlg, 508
               .if eax
                  INVOKE     lstrcpy, addr szWorkPgm, addr szPgm07
               .endif
            .endif

            INVOKE     IsDlgButtonChecked, hdlg, 505
            .if eax
               INVOKE     lstrcpy, addr szWorkPgm, addr szPgm04
               INVOKE     IsDlgButtonChecked, hdlg, 508
               .if eax
                  INVOKE     lstrcpy, addr szWorkPgm, addr szPgm03
               .endif
            .endif

            INVOKE     IsDlgButtonChecked, hdlg, 509
            .if eax
               INVOKE     lstrcpy, addr szWorkPgm, addr szPgm11
               INVOKE     IsDlgButtonChecked, hdlg, 508
               .if eax
                  INVOKE     lstrcpy, addr szWorkPgm, addr szPgm10
               .endif
            .endif
         .endif
         INVOKE     lstrcpy, addr szBuff0, addr szProjDir
         INVOKE     lstrcat, addr szBuff0, addr szProjectName
         INVOKE     lstrcpy, addr szProjDir, addr szBuff0
         INVOKE     CreateDirectory, addr szProjDir, NULL

;---------- [Read and Write Templates to the new project directory
         INVOKE     GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, 100000
            mov     hpMem, eax
         INVOKE     GlobalLock, hpMem
            mov     fpMem, eax
         INVOKE     GetWindowRect, hdlg, addr rect
; or WS_VISIBLE  MS
         INVOKE     CreateWindowEx, 0, addr RichEdit, 0,
                    WS_POPUP or ES_MULTILINE,
                    rect.left, rect.top, 400, 300, hdlg, 0, hInst, 0
            mov     hEdit, eax
         INVOKE     SendMessage, hEdit, EM_EXLIMITTEXT, 0, 100000

FromDoDll:
         INVOKE     lstrcpy, addr szBuff2, addr AsmRootDir
         .if ProjType == 4       ; User pgms
               and     ProjType, 0
            INVOKE     lstrcat, addr szBuff2, addr szTemplatesU
            INVOKE     lstrcat, addr szBuff2, addr szBuff1
         .else
            INVOKE     lstrcat, addr szBuff2, addr szTemplates
            INVOKE     lstrcat, addr szBuff2, addr szWorkPgm
         .endif
         INVOKE     lstrcat, addr szBuff2, addr szSlashB
         INVOKE     lstrcpy, addr szBuff1, addr szBuff2
         INVOKE     lstrcat, addr szBuff2, addr szAll

;---------- [Find first file] ----------
GetFirstF:
         INVOKE     FindFirstFile, addr szBuff2, addr FindData
         .if eax == -1
            INVOKE     MessageBox, NULL, addr szError13, addr szTemplates, MB_OK or\
                       MB_ICONWARNING or MB_SYSTEMMODAL
               jmp     NoFile
         .endif
            mov     hFind, eax
            jmp     ChkFile

;---------- [Find next file] ----------
GetNextF:
         INVOKE     FindNextFile, hFind, addr FindData
           test     eax, eax
             jz     CleanUp

;---------- [Validate file] ----------
ChkFile:
         .if byte ptr FindData.cFileName == '.'
               jmp     GetNextF
         .endif
         INVOKE     lstrcpy, addr szBuff0, addr szBuff1
         INVOKE     lstrcat, addr szBuff0, addr FindData.cFileName
;            .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
;                  jmp     AddDir
;            .endif
         INVOKE     lstrlen, addr FindData.cFileName
         .while (eax)
               dec     eax
            .if FindData.cFileName[eax] == '.'
               .break
            .endif
         .endw
         INVOKE     lstrcpy, addr szExt, addr FindData.cFileName[eax]
         INVOKE     lstrlen, addr szExt
            mov     ecx, eax
            lea     esi, szExt
           call     LowerCase

            mov     ecx, hBuff
         INVOKE     lstrcpy, ecx, addr szBuff0

;---------- [Read the template file
           call     ReadF
         .if eax
            INVOKE     SendMessage, hEdit, WM_SETTEXT, NULL, fpMem
;---------- [Update the project name and paths

            INVOKE     FindRep, hEdit, addr szXXXX, addr szProjectName
            INVOKE     FindRep, hEdit, addr szAsmEditDir, addr AsmRootDir
            INVOKE     FindRep, hEdit, addr szHutchDir, addr szRoot
            INVOKE     SendMessage, hEdit, WM_GETTEXT, 100000, fpMem
               mov     BytesR, eax

            INVOKE     lstrcpy, addr szBuff0, addr szProjDir
            INVOKE     lstrcat, addr szBuff0, addr szSlashB
            .if byte ptr szExt+1 == 'a' || byte ptr szExt+1 == 'r' || byte ptr szExt+1 == 'i' ||\
                byte ptr szExt+1 == 'd'
               INVOKE     lstrcat, addr szBuff0, addr szProjectName
               INVOKE     lstrcat, addr szBuff0, addr szExt
            .else
               INVOKE     lstrcat, addr szBuff0, addr FindData.cFileName
            .endif
               mov     ecx, hBuff
            INVOKE     lstrcpy, ecx, addr szBuff0

;---------- [Write the template file to the new project directory
              call     WriteF
            .if !eax || eax == INVALID_HANDLE_VALUE
               INVOKE     MessageBox, NULL, addr szError12, addr AppName,\
                          MB_OK or MB_ICONWARNING or MB_SYSTEMMODAL
               INVOKE     FindClose, hFind
                  jmp     NoFile
            .endif
               jmp     GetNextF
         .else
; Do message
         .endif

CleanUp:
         INVOKE     FindClose, hFind
         .if DllOn == 1
               mov     DllOn, 2
            INVOKE     lstrcpy, addr szWorkPgm, addr szEWCallDLL
               jmp     FromDoDll
         .endif
         .if DllOn == 2
            INVOKE     lstrcpy, addr szBuff0, addr szProjDir
            INVOKE     lstrcat, addr szBuff0, addr szSlashB
            INVOKE     lstrcat, addr szBuff0, addr szCallDLLb
            INVOKE     WinExec, addr szBuff0, SW_HIDE  ; Exec a .bat program
            .if eax < 32
                  ;Do error
            .endif
         .endif
jmp     SetProject

NoFile:
         .if hpMem
            INVOKE     GlobalUnlock, fpMem
            INVOKE     GlobalFree, hpMem
               mov     hpMem, 0
         .endif
         INVOKE     DestroyWindow, hEdit
            and     hEdit, 0
jmp     Ret0

BuildFiles:
;---------- [Build the project files
         INVOKE     FillBuffer, addr FileType, sizeof FileType, '0', 1
         .if ProjType == 5     ; 5 = StepByStep
               mov     byte ptr FileType, 1
               jmp     PressOn
         .endif
            and     FilesOn, 0
            xor     ebx, ebx
            mov     esi, 5
            mov     edi, 701
         .while (esi)
            INVOKE     IsDlgButtonChecked, hdlg, edi
            .if eax
                  mov     FilesOn, 1
                  mov     FileType[ebx], 1
            .endif
               inc     ebx
               inc     edi
               dec     esi
         .endw
         .if !FilesOn
               jmp     Ret0
         .endif

PressOn:
            mov     szBlank, 0
         INVOKE     lstrcpy, addr szBuff0, addr szProjDir
         INVOKE     lstrcat, addr szBuff0, addr szProjectName
         INVOKE     lstrcpy, addr szProjDir, addr szBuff0
         INVOKE     CreateDirectory, addr szProjDir, NULL
         INVOKE     lstrcat, addr szBuff0, addr szSlashB
         INVOKE     lstrcat, addr szBuff0, addr szProjectName
         INVOKE     GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, 100000
            mov     hpMem, eax
         INVOKE     GlobalLock, hpMem
            mov     fpMem, eax

            xor     ebx, ebx
            mov     esi, 5
         .while (esi)
            .if byte ptr FileType[ebx] == 1
               INVOKE     lstrcpy, addr szBuff1, addr szBuff0
               INVOKE     lstrcat, addr szBuff1, addr szPer
               .if ebx == 0
                  INVOKE     lstrcat, addr szBuff1, addr szAsm
               .elseif ebx == 1
                  INVOKE     lstrcat, addr szBuff1, addr szRsc
               .elseif ebx == 2
                  INVOKE     lstrcat, addr szBuff1, addr szInc
               .elseif ebx == 3
                  INVOKE     lstrcat, addr szBuff1, addr szDef
               .elseif ebx == 4
;---------- [Build the batch command files for Lib out only
                  INVOKE     lstrcpy, addr szBuffR, addr szRoot
                  INVOKE     lstrcpy, addr szBuffA, addr szRoot
                  INVOKE     lstrcpy, addr szBuffL, addr szRoot
                  INVOKE     lstrcat, addr szBuffR, addr szResr
                  INVOKE     lstrcat, addr szBuffA, addr szAsmb

                  INVOKE     lstrcat, addr szBuffR, addr szIPath
                  INVOKE     lstrcat, addr szBuffR, addr szRoot
                  INVOKE     lstrcat, addr szBuffR, addr szIncludeP
                  INVOKE     lstrcat, addr szBuffR, addr szProjectName
                  INVOKE     lstrcat, addr szBuffR, addr szPer
                  INVOKE     lstrcat, addr szBuffR, addr szRsc

                  INVOKE     lstrcat, addr szBuffA, addr szIPath
                  INVOKE     lstrcat, addr szBuffA, addr szRoot
                  INVOKE     lstrcat, addr szBuffA, addr szIncludeP
                  INVOKE     lstrcat, addr szBuffA, addr szProjectName
                  INVOKE     lstrcat, addr szBuffA, addr szPer
                  INVOKE     lstrcat, addr szBuffA, addr szAsm

                  INVOKE     lstrcat, addr szBuffL, addr szLinkL
                  INVOKE     lstrcat, addr szBuffL, addr szProjectName
                  INVOKE     lstrcat, addr szBuffL, addr szPer
                  INVOKE     lstrcat, addr szBuffL, addr szObj
                  INVOKE     lstrcat, addr szBuffL, addr szLinkLO
                  INVOKE     lstrcat, addr szBuffL, addr szProjectName
                  INVOKE     lstrcat, addr szBuffL, addr szPer
                  INVOKE     lstrcat, addr szBuffL, addr szLib

                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
                  INVOKE     lstrcat, addr PtrBuild, addr szSavBuild
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
                  INVOKE     IsDlgButtonChecked, hdlg, 702   ; .rc file
                  .if eax
                     INVOKE     lstrcat, addr PtrBuild, addr szR1E
                     INVOKE     lstrcat, addr PtrBuild, addr szBuffR
                     INVOKE     lstrcat, addr PtrBuild, addr szCRLF

                  .endif

                  INVOKE     lstrcat, addr PtrBuild, addr szA1E
                  INVOKE     lstrcat, addr PtrBuild, addr szBuffA
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF
                  INVOKE     lstrcat, addr PtrBuild, addr szL1E
                  INVOKE     lstrcat, addr PtrBuild, addr szBuffL
                  INVOKE     lstrcat, addr PtrBuild, addr szCRLF

                  INVOKE     lstrlen, addr PtrBuild
                     mov     BytesR, eax
                  INVOKE     lstrcpy, fpMem, addr PtrBuild
                     mov     ecx, hBuff
                  INVOKE     lstrcpy, ecx, addr szBuffP
                    call     WriteF
                  .break
               .endif
               INVOKE     lstrlen, addr szBlank
                  mov     BytesR, eax
               INVOKE     lstrcpy, fpMem, addr szBlank
                  mov     ecx, hBuff
               INVOKE     lstrcpy, ecx, addr szBuff1
                 call     WriteF
            .endif
               inc     ebx
               dec     esi
         .endw

SetProject:
;         INVOKE     lstrcpy, addr szProject, addr szProjectName
            mov     ebx, ProjGroup
         INVOKE     lstrcpy, ProjNamArray[ebx*4], addr szProjectName
;         INVOKE     LoadTreeView, addr szProject, 0
         INVOKE     LoadTreeView, ProjNamArray[ebx*4], 0
         .if eax
               mov     hItem, eax
;            INVOKE     LoadTreeView, addr szProject, 1
            INVOKE     LoadTreeView, ProjNamArray[ebx*4], 1
         .endif
         .if hpMem
            INVOKE     GlobalUnlock, fpMem
            INVOKE     GlobalFree, hpMem
               mov     hpMem, 0
         .endif
         .if ProjType == 5       ; 5 = StepByStep
            INVOKE     lstrcpy, addr PathName, addr szBuff1
               mov     OA, 1
               mov     OpenFlg1, 1
              call     OpenFileA
            INVOKE     SendMessage, hWnd, WM_COMMAND, IDM_STEPBYSTEP, 0
         .endif
            jmp     CancelOut

      .elseif eax == 902         ; Browse
         INVOKE     RtlZeroMemory, addr ofn, sizeof ofn
         INVOKE     RegQuerySZ, addr rDEFr, addr szBuff0
         INVOKE     lstrcat, addr szBuff0, addr szAll
            lea     eax, szBuff0
            mov     ofn.lStructSize, sizeof ofn
            mov     ofn.lpstrFilter, offset szFilter
            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     Ret0
            xor     ebx, ebx
            mov     bx, ofn.nFileOffset
            inc     ebx
         INVOKE     lstrcpyn, addr szBuff0, ofn.lpstrFile, ebx
         INVOKE     SetDlgItemText, hdlg, 402, ofn.lpstrFile
            jmp     Ret0
      .endif
         jmp     Ret0

CancelOut:
         and     hCreateProj, 0
         and     hWndDlg, 0
      INVOKE     SetFocus, hREdit
      .if hEdit
         INVOKE     DestroyWindow, hEdit
            and     hEdit, 0
      .endif
      .if AddinOn
            and     hAddin, 0
         INVOKE     EndDialog, hdlg, wParam
      .else
         INVOKE     DestroyWindow, hdlg  ; End the dialog
      .endif
      .if edi == -1 && AddinOn
;            mov     szProject, 0
            mov     ecx, ProjGroup
            mov     ProjNamArray[ecx*4], 0
      .endif
         mov     eax, TRUE               ; Return
         jmp     CreateFolderRet

Ret0:
         mov     eax, FALSE              ; Return with FALSE

CreateFolderRet:
         ret

CreateProject ENDP

;===================================================
; Snippets Dialog PROCEDURE
;===================================================
Snippets PROC uses ebx hdlg:DWORD, wMsg, wParam, lParam
LOCAL    rect:RECT
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    hFind:DWORD
LOCAL    szBuff0[256]:BYTE, szBuff1[256]:BYTE, szSavBuff[256]:BYTE

      .if wMsg == WM_INITDIALOG
         INVOKE     GetDlgItem, hdlg, 472
            mov     hComboS, eax
         INVOKE     GetDlgItem, hdlg, 473
            mov     hListWS, eax
         INVOKE     GetDlgItem, hdlg, 474
            mov     hButtS, eax
         INVOKE     GetDlgItem, hdlg, 30
         INVOKE     SetFocus, eax

         INVOKE     GetWindowRect, hdlg, addr rect
            mov     eax, rect.left
            sub     rect.right, eax
            mov     eax, rect.top
            sub     rect.bottom, eax
           push     rect.bottom
           push     rect.right
         INVOKE     GetWindowRect, hREdit, addr rect
         INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
            mov     ebx, eax
            pop     ecx
            pop     edx
            mov     eax, rect.right
            sub     eax, ecx
            mov     rect.left, eax
            sub     rect.left, 2
            add     rect.top, 2
         .if ebx > 1000
               sub     rect.left, 16
         .endif
         INVOKE     MoveWindow, hdlg, rect.left, rect.top, ecx, edx, TRUE

         INVOKE     GetWindowRect, hdlg, addr rect
            mov     ecx, rect.right
            sub     ecx, 372
            mov     edx, rect.bottom

;---------- [Create the Snippets WorkArea Window] ----------
      INVOKE     CreateWindowEx, WS_EX_TOOLWINDOW, addr WorkClass, addr szWorkAreaS,\
                 WS_POPUP or WS_CAPTION or WS_THICKFRAME,\
                 ecx, edx, 372, 132, hWnd, NULL, hInst, NULL  ;494, 456, hdlg
         mov     hWorkAreaS, eax

;---------- [Create the Snippets WorkArea 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 WS_CLIPSIBLINGS,\
                 0, 0, 364, 108, hWorkAreaS, 4491, hInst, NULL
         mov     hWEditS, eax

      INVOKE     SendMessage, hWEditS, WM_SETFONT, hFont, TRUE
INVOKE     SendMessage, hWEditS, UM_SUBCLASSCTRL, 0, WorkEditProc
         mov     lpWorkEdit, eax
      INVOKE     SendMessage, hWEditS, EM_EXLIMITTEXT, 0, 100000

         INVOKE     lstrcpy, addr szBuff0, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff0, addr szSnippets
         INVOKE     lstrcat, addr szBuff0, addr szAll

GetFirstF:
         INVOKE     FindFirstFile, addr szBuff0, addr FindData
           test     eax, eax
             js     NoFile
            mov     hFind, eax
            jmp     ChkFile

GetNextF:
         INVOKE     FindNextFile, hFind, addr FindData
           test     eax, eax
             jz     AllDone

;---------- [Validate File] ----------
ChkFile:
         .if byte ptr FindData.cFileName == '.'
               jmp     GetNextF
         .endif
         INVOKE     SendMessage, hComboS, CB_ADDSTRING, 0, addr FindData.cFileName
            jmp     GetNextF

AllDone:
         INVOKE     FindClose, hFind
         INVOKE     SendMessage, hComboS, CB_SETCURSEL, 0, 0

NoFile:
            jmp     SnippetsDone

      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            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
         INVOKE     DrawButt, lParam

      .elseif wMsg == WM_CLOSE
            jmp     CancelOut

      .elseif wMsg == WM_COMMAND    ; See if msg is a command
            mov     eax, wParam
            mov     ebx, eax
            shr     ebx, 16

         .if ebx == BN_CLICKED
            INVOKE     GetFocus
            INVOKE     GetDlgCtrlID, eax
         .endif

;---------- [For Catagory files] ----------
         .if ebx == LBN_SELCHANGE
            INVOKE     SendMessage, hComboS, CB_GETCURSEL, 0, 0
            .if eax == LB_ERR
                  jmp     SnippetsDone
            .endif
               mov     ecx, eax
            INVOKE     SendMessage, hComboS, CB_GETLBTEXT, ecx, addr szBuff0
            .if eax == CB_ERR
                  jmp     SnippetsDone
            .endif
            INVOKE     lstrcpy, addr szBuff1, addr AsmRootDir
            INVOKE     lstrcat, addr szBuff1, addr szSnippets
            INVOKE     lstrcat, addr szBuff1, addr szBuff0
            INVOKE     lstrcat, addr szBuff1, addr szSlashB
            INVOKE     lstrcpy, addr WorkBuff, addr szBuff1
            INVOKE     lstrcat, addr szBuff1, addr szAll

            INVOKE     SendMessage, hListWS, LB_RESETCONTENT, 0, 0
            INVOKE     FindFirstFile, addr szBuff1, addr FindData
              test     eax, eax
                js     NoFileS
               mov     hFind, eax
               jmp     ChkFileS

GetNextFS:
            INVOKE     FindNextFile, hFind, addr FindData
              test     eax, eax
                jz     AllDoneS

;---------- [Validate File] ----------
ChkFileS:
            .if byte ptr FindData.cFileName == '.'
                  jmp     GetNextFS
            .endif
            INVOKE     SendMessage, hListWS, LB_ADDSTRING, 0, addr FindData.cFileName
               jmp     GetNextFS

AllDoneS:
            INVOKE     FindClose, hFind

NoFileS:
               jmp     SnippetsDone

         .elseif eax == 474
            INVOKE     SendMessage, hListWS, LB_GETCURSEL, 0, 0
            .if eax == LB_ERR
                  jmp     SnippetsDone
            .endif
               mov     ecx, eax
            INVOKE     SendMessage, hListWS, LB_GETTEXT, ecx, addr szBuff1
            INVOKE     ShowWindow, hWorkAreaS, SW_SHOW
   
            INVOKE     lstrcpy, addr szBuff0, addr WorkBuff
            INVOKE     lstrcat, addr szBuff0, addr szBuff1
               mov     ecx, hBuff
            INVOKE     lstrcpy, ecx, addr szBuff0
              call     ReadF
            .if eax
               INVOKE     SendMessage, hWEditS, WM_SETTEXT, 0, fpMem
            .endif
            .if hpMem
               INVOKE     GlobalUnlock, fpMem
               INVOKE     GlobalFree, hpMem
                  mov     hpMem, 0
            .endif
         .endif
      .endif
         jmp     SnippetsDone

CancelOut:
         and     hSnip, 0
         and     hWndDlg, 0
      INVOKE     SetFocus, hREdit
      INVOKE     DestroyWindow, hWorkAreaS
      INVOKE     EndDialog, hdlg, wParam
         mov     eax, TRUE          ; Return
         jmp     SnippetsRet        ; with TRUE

SnippetsDone:
         mov     eax, FALSE         ; Return with FALSE

SnippetsRet:

         ret
Snippets ENDP

;===================================================
; Format the input file to hex
;===================================================
BuildHex PROC  uses ebx edx esi edi  hREditO:DWORD, InFile, FileSize, Base
LOCAL    hMemO:DWORD, pMemO, BytesO, SavIn, SavOut, Cnt, Num, BuffOff, Len, Hold
LOCAL    szBuff[256]:BYTE

         mov     eax, FileSize
        imul     eax, 5
         mov     BytesO, eax

      INVOKE     HeapCreate, HEAP_GENERATE_EXCEPTIONS, BytesO, 0
         mov     hMemO, eax
      INVOKE     HeapAlloc, hMemO, HEAP_GENERATE_EXCEPTIONS, BytesO
         mov     pMemO, eax

         mov     SavIn, 0
         mov     SavOut, 0
         mov     Cnt, 0
         mov     Len, 17
         mov     eax, FileSize
      .if eax < 17
            inc     eax
            mov     Len, eax
      .endif

LoopIt:
;---------- [Offset characters] ---------- 
         mov     Num, 0
         mov     BuffOff, 0
         mov     edi, SavOut
         mov     eax, pMemO
         add     eax, edi
         mov     Hold, edi
      INVOKE     BaseAscii, Cnt, eax, 8, Base, 0, 1, 1
         mov     ecx, Len
         dec     ecx
         add     SavOut, 10
         mov     edi, SavOut
         mov     edx, pMemO
         mov     Word ptr[edx+edi-2], '  '

;---------- [Hex characters] ---------- 
      .while (ecx)
            mov     esi, SavIn
            mov     ebx, InFile
            mov     al, byte ptr [ebx+esi]
            mov     esi, BuffOff
         .if al == 0ah || al == 0dh || al == 09h || al < 20h || al > 7fh
               mov     byte ptr szBuff[esi], 2eh
         .else
               mov     byte ptr szBuff[esi], al
         .endif
            shr     eax, 4
            and     eax, 0fh
         .if eax > 9
            add     eax, 37h
         .else
            add     eax, 30h
         .endif
            mov     byte ptr[edx+edi], al
            mov     esi, SavIn
            mov     ebx, InFile
            mov     al, byte ptr [ebx+esi]
            and     eax, 0fh
         .if eax > 9
               add     eax, 37h
         .else
               add     eax, 30h
         .endif
            inc     edi
            mov     byte ptr[edx+edi], al
            inc     BuffOff
            inc     SavIn
            add     Num, 2
            inc     edi
         .if Num == 4
               mov     byte ptr[edx+edi], ' '
               inc     edi
               mov     Num, 0
         .endif
            dec     ecx
      .endw

         mov     esi, BuffOff
         mov     byte ptr szBuff[esi], 0
         dec     edi
      .if Num == 2
            inc     edi
      .endif
         mov     SavOut, edi
         mov     word ptr[edx+edi], '  '
         inc     edi
         inc     edi
         mov     eax, 17
      .if Len < eax
            mov     eax, edi
            sub     eax, Hold
            mov     ecx, 51 ;50
            sub     ecx, eax
         .while (ecx)
               mov     byte ptr[edx+edi], ' '
               inc     edi
               dec     ecx
         .endw
      .endif

;---------- [Ascii characters] ---------- 
         mov     edx, pMemO
         mov     ecx, 16
         xor     ebx, ebx
      .while (ecx)
            mov     al, byte ptr szBuff[ebx]
            mov     byte ptr[edx+edi], al
            inc     edi
            inc     ebx
            dec     ecx
      .endw

;---------- [Finish the line] -----------
         add     Cnt, 16
;INVOKE     MessageBox, hWnd, pMemO, addr AppName, MB_OK
         mov     eax, FileSize
      .if SavIn < eax
            sub     eax, SavIn
         .if eax < 17
               inc     eax
               mov     Len, eax
         .endif
            mov     edx, pMemO
            mov     edi, SavOut
            add     edi, 18
            mov     word ptr[edx+edi], 0a0dh
            add     SavOut, 20
            jmp     LoopIt
      .endif
         mov     word ptr[edx+edi], 0a0dh
         add     edi, 2
         mov     word ptr[edx+edi], 0a0dh
         add     edi, 2
      INVOKE     SendMessage, hREditO, EM_EXLIMITTEXT, 0, edi
      INVOKE     SendMessage, hREditO, WM_SETTEXT, NULL, pMemO
      INVOKE     HeapDestroy, hMemO
      INVOKE     BaseAscii, BytesR, addr Fsize, 0, 10, 1, 0, 1
      INVOKE     lstrcpy, addr szFileSize, addr szOpened
      INVOKE     lstrcat, addr szFileSize, addr Fsize
      INVOKE     SendMessage, hWndStat, SB_SETTEXT, 0, addr szFileSize
      INVOKE     SendMessage, hREdit, EM_SETMODIFY, FALSE, 0

         ret
BuildHex ENDP

;==========================================
; Convert hex to previous format PROCEDURE
;==========================================
ConvHex PROC uses ebx edx esi edi
LOCAL    hMemI:DWORD, pMemI, hMemO, pMemO, BytesO, SavIn, LineLen, SavOut
LOCAL    txtBuffer[64]:BYTE, szWorkS[10]:BYTE

         mov     SavIn, 0
         mov     SavOut, 0
         mov     LineLen, 0

      INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
         inc     eax
         mov     BytesO, eax
      INVOKE     HeapCreate, HEAP_GENERATE_EXCEPTIONS, BytesO, 0
         mov     hMemI, eax
      INVOKE     HeapAlloc, hMemI, HEAP_GENERATE_EXCEPTIONS, BytesO
         mov     pMemI, eax
      INVOKE     HeapCreate, HEAP_GENERATE_EXCEPTIONS, BytesO, 0
         mov     hpMem, eax
      INVOKE     HeapAlloc, hpMem, HEAP_GENERATE_EXCEPTIONS, BytesO
         mov     fpMem, eax
      INVOKE     SendMessage, hREdit, WM_GETTEXT, BytesO, pMemI
         mov     BytesO, eax
         mov     SavIn, 10

;---------- [Convert the hex portion to ascii] ----------
LoopIt:
         mov     ecx, BytesO
      .while (SavIn <= ecx)
         .while (LineLen < 40)
               mov     esi, SavIn
               mov     ebx, pMemI
               mov     edi, SavOut
               mov     edx, fpMem
               xor     eax, eax
            .if byte ptr [ebx+esi] == 20h && byte ptr [ebx+esi+1] == 20h && LineLen < 38
                  jmp     NoMore
            .endif
            .if byte ptr [ebx+esi] == 20h && byte ptr [ebx+esi+1] == 20h
               .break
            .endif
               mov     al, byte ptr [ebx+esi]
            .if al == 0ah || al == 0dh || al == 20h
                  inc     SavIn
                  inc     LineLen
                  jmp     LoopIt
            .endif
               mov     ax, word ptr [ebx+esi]
               mov     word ptr szWorkS, ax
               mov     eax, 2
               xor     ecx, ecx
            .while (eax)
               .if byte ptr szWorkS[ecx] > 60h
                     sub     byte ptr szWorkS[ecx], 57h
               .elseif byte ptr szWorkS[ecx] > 40h
                     sub     byte ptr szWorkS[ecx], 37h
               .else
                     xor     byte ptr szWorkS[ecx], 30h
               .endif
                  dec     eax
                  inc     ecx
            .endw
               mov     al, byte ptr szWorkS
              imul     eax, 16
               mov     ecx, eax
               mov     al, byte ptr szWorkS+1
               and     eax, 000000ffh
               add     ecx, eax
               mov     byte ptr [edx+edi], cl
               add     SavIn, 2
               add     LineLen, 2
               inc     SavOut
               jmp     LoopIt
         .endw
            and     LineLen, 0
            add     SavIn, 29
      .endw

NoMore:
         mov     edi, SavOut
         mov     byte ptr [edx+edi], 0
         mov     eax, BytesR
      .if eax != SavOut
         INVOKE     MessageBox, NULL, addr szError1, addr AppName, MB_YESNO or MB_ICONQUESTION
         .if eax == IDNO
               jmp     NoUpdate
         .endif

      .endif
         mov     SaveAs, 1
         mov     SaveFlg1, 5
       MOVmd     BytesR, SavOut

        call     SaveFile

NoUpdate:
      INVOKE     HeapDestroy, hMemI
      INVOKE     HeapDestroy, hpMem
      INVOKE     BaseAscii, SavOut, addr Fsize, 0, 10, 1, 0, 1
      INVOKE     lstrcpy, addr szFileSize, addr szSaved
      INVOKE     lstrcat, addr szFileSize, addr Fsize
      INVOKE     SendMessage, hWndStat, SB_SETTEXT, 0, addr szFileSize
      INVOKE     SendMessage, hREdit, EM_SETMODIFY, FALSE, 0
         ret

ConvHex ENDP


;==========================================
; Convert file to unicode PROCEDURE

;==========================================
ConvToUnicode PROC uses ebx esi edi
LOCAL    hMemI:DWORD, pMemI, BytesO
LOCAL    szBuff[256]:BYTE

      INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
      .if !eax
            ret
      .endif
         mov     esi, eax
         mov     edi, eax
         shl     edi, 1
         add     edi, 3                ; For fffe prefix and termanator

      INVOKE     HeapCreate, HEAP_GENERATE_EXCEPTIONS, esi, 0
         mov     hMemI, eax
      INVOKE     HeapAlloc, hMemI, HEAP_GENERATE_EXCEPTIONS, esi
         mov     pMemI, eax
      INVOKE     HeapCreate, HEAP_GENERATE_EXCEPTIONS, edi, 0
         mov     hpMem, eax
      INVOKE     HeapAlloc, hpMem, HEAP_GENERATE_EXCEPTIONS, edi
         mov     fpMem, eax
      INVOKE     SendMessage, hREdit, WM_GETTEXT, BytesO, pMemI

         and     BytesO, 0
         mov     ecx, eax
         mov     esi, pMemI
         mov     edi, fpMem
         mov     word ptr[edi], 0feffh
         add     edi, 2

      .if byte ptr[esi+ecx-1] == 0dh && byte ptr[esi+ecx-2] == 0dh
            mov     byte ptr[esi+ecx-2], 0
            dec     ecx
      .endif
      .while (ecx)
            mov     al, byte ptr[esi]
            mov     byte ptr[edi], al
            mov     byte ptr[edi+1], 0
            add     edi, 2
         .if al == 0dh
               mov     word ptr[edi], 000ah
               add     edi, 2
         .endif
            inc     esi
            dec     ecx
      .endw

         sub     edi, fpMem
         mov     BytesR, edi
         mov     SaveAs, 1
         mov     SaveFlg1, 5
        call     SaveFile

      INVOKE     HeapDestroy, hMemI
      INVOKE     HeapDestroy, hpMem
         ret

ConvToUnicode ENDP

;===================================================
; ChgBmpColor procedure
;===================================================
ChgBmpColor PROC hBitmap:DWORD
LOCAL    mDC:DWORD, hNewBrush, hOldBmp, Fill, hOldBrush

      INVOKE     CreateCompatibleDC, NULL
         mov     mDC, eax
      INVOKE     SelectObject, mDC, hBitmap
         mov     hOldBmp, eax
      INVOKE     GetSysColor, COLOR_BTNFACE
      INVOKE     CreateSolidBrush, eax
         mov     hNewBrush, eax
      INVOKE     SelectObject, mDC, hNewBrush
         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, hNewBrush
      INVOKE     SelectObject, mDC, hBitmap
        push     eax
      INVOKE     DeleteDC, mDC
         pop     eax
         ret

ChgBmpColor ENDP

;======================================
; Type of Button
;======================================
ButtInfo PROC BFont, BBack, BText

       MOVmd     disFont, BFont
       MOVmd     disBack, BBack
       MOVmd     disText, BText

         ret
ButtInfo ENDP

;======================================
; Owner drawn Buttons
;======================================
DrawButt  PROC uses ebx esi edi disDC
LOCAL    disBrush:DWORD, hOldFont
LOCAL    szBuff0[256]:BYTE

         mov     esi, disDC
         lea     edi, dis
         mov     ecx, sizeof dis
         rep     movsb

      .if dis.itemID != -1
            mov     eax, dis.hwndItem
         .if eax == hCancel || eax == hCancel01
            INVOKE     ButtInfo, hFontButt, 006464ffh, 00000000h ; Font, BackColor, TextColor
         .elseif eax == hCreate || eax == hUpdate
            INVOKE     ButtInfo, hFontButt, 00000000h, 00ffff00h
         .elseif eax == hBrowse
            INVOKE     ButtInfo, hFontButt, 0095caffh, 00004000h
         .elseif eax == hReturn || eax == hUser || eax == hStep || eax == h41 || eax == h47
            INVOKE     ButtInfo, hFontButt, 00c1ffc1h, 00006000h
         .elseif eax == h42 || eax == hButtS
            INVOKE     ButtInfo, hFontButt, 00b0b000h, 00000000h
         .elseif eax == h43
            INVOKE     ButtInfo, hFontButt, 006464ffh, 00000000h
         .elseif eax == h48
            INVOKE     IsWindowEnabled, dis.hwndItem
            .if !eax
               INVOKE     ButtInfo, hFontC, 00c9c9c9h, 00ffffffh
            .else
               INVOKE     ButtInfo, hFontC, 00b0b000h, 00000000h
            .endif
         .elseif eax == h49
            INVOKE     ButtInfo, hFontButt, 006464ffh, 00000000h
         .elseif eax == h50
            INVOKE     ButtInfo, hFontC, 000080ffh, 00000000h
         .elseif eax == h51 || eax == h53
            INVOKE     ButtInfo, hFontButt, 00c1ffc1h, 00000000h
         .elseif eax == h52 || eax == h54
            INVOKE     IsWindowEnabled, dis.hwndItem
            .if !eax
               INVOKE     ButtInfo, hFontC, 00c9c9c9h, 00ffffffh
            .else
               INVOKE     ButtInfo, hFontC, 000080ffh, 00000000h
            .endif
         .elseif eax == h55
            INVOKE     ButtInfo, hFontButt, 00b0b000h, 00000000h
         .elseif eax == h56
            INVOKE     ButtInfo, hFontButt, 006464ffh, 00000000h
         .endif

         INVOKE     SelectObject, dis.hdc, disFont
            mov     hOldFont, eax
         INVOKE     SendMessage, dis.hwndItem, WM_GETTEXT, sizeof szBuff0, addr szBuff0
         .if (dis.itemState & ODS_SELECTED)
            INVOKE     SetTextColor, dis.hdc, 00000000h ; Highlight text color
            INVOKE     SetBkColor, dis.hdc, 00929292h   ; Highlight text background color
            INVOKE     CreateSolidBrush, 00929292h      ; Highlight background color
               mov     disBrush, eax
            INVOKE     FillRect, dis.hdc, addr dis.rcItem, disBrush
            INVOKE     DrawEdge, dis.hdc, addr dis.rcItem, EDGE_SUNKEN, BF_RECT
               add     dis.rcItem.left, 2
               add     dis.rcItem.top, 2
               sub     dis.rcItem.bottom, 2

         .else
            INVOKE     SetTextColor, dis.hdc, disText   ; Text color
            INVOKE     SetBkColor, dis.hdc, disBack     ; Text background color
            INVOKE     CreateSolidBrush, disBack        ; Background color
               mov     disBrush, eax
            INVOKE     FillRect, dis.hdc, addr dis.rcItem, disBrush
            INVOKE     DrawEdge, dis.hdc, addr dis.rcItem, BDR_RAISEDOUTER, BF_TOPLEFT
            INVOKE     DrawEdge, dis.hdc, addr dis.rcItem, BDR_RAISEDOUTER, BF_BOTTOMRIGHT
         .endif
         INVOKE     DrawText, dis.hdc, addr szBuff0, -1, addr dis.rcItem,
                    DT_CENTER or DT_SINGLELINE or DT_VCENTER
         .if (dis.itemState & ODS_FOCUS)
               inc     dis.rcItem.left
               inc     dis.rcItem.top

;            .if !(dis.itemState & ODS_SELECTED)
;                  inc     dis.rcItem.left
;                  inc     dis.rcItem.top
;            .else
;                  sub     dis.rcItem.right, 2
;            .endif
;               sub     dis.rcItem.right, 2
;               sub     dis.rcItem.bottom, 2
;            INVOKE     DrawFocusRect, dis.hdc, addr dis.rcItem

               mov     dis.rcItem.right, 5
               mov     dis.rcItem.bottom, 5
            INVOKE     DeleteObject, disBrush
            INVOKE     CreateSolidBrush, 0000ff00h      ; Background color
               mov     disBrush, eax
            INVOKE     FillRect, dis.hdc, addr dis.rcItem, disBrush
         .endif
         INVOKE     SelectObject, dis.hdc, hOldFont
         INVOKE     DeleteObject, disBrush
      .endif
         mov     dis.itemState, ODS_DEFAULT
         mov     dis.hdc, 0
         mov     eax, 1
         ret

DrawButt ENDP

;=========================================================================
; Splitter Bar PROCEDURE
;=========================================================================
SplitBarProc PROC hdlg:DWORD, wMsg, wParam, lParam

         cmp     wMsg, WM_INITDIALOG   ; If message is INITDIALOG then
         jne     NotInit               ; check wMsg
         mov     eax, hdlg
         mov     hSplitBar, eax
         jmp     DlgDone

NotInit:
         cmp     wMsg, WM_CTLCOLORDLG
         je      ColorDlg
         cmp     wMsg, WM_COMMAND      ; Is message a WM_COMMAND?
         mov     eax, wParam           ; Otherwise, see if it's OK or CANCEL
         cmp     eax, IDCANCEL         ; that was pressed
         je      CancleIt              ; and if not either of these
         jmp     DlgDone

ColorDlg:
      INVOKE     CreateSolidBrush, 0000ff00h


         mov     hBrush, eax
         ret

CancleIt:
      INVOKE     DeleteObject, hBrush
;      INVOKE     EndDialog, hdlg, wParam
      INVOKE     DestroyWindow, hdlg     ; End the dialog
         mov     eax, TRUE             ; Return
         jmp     DlgRet                ; with TRUE

DlgDone:
         mov     eax, FALSE            ; Return with FALSE

DlgRet:
         ret                           ; Return
SplitBarProc ENDP

;=========================================================================
; Check splitter PROCEDURE
;=========================================================================
ChkSplitter PROC uses esi wParam:DWORD, lParam
LOCAL    rect:RECT
LOCAL    xPos:DWORD, yPos

;---------- [Capture the mouse if within an area] ----------
      INVOKE     GetClientRect, hWnd, addr rect
         mov     eax, lParam
         mov     edx, eax
         and     eax, 0ffffh
         inc     eax
         mov     xPos, eax
         shr     edx, 16
         inc     edx
;add     edx, ToolH
         mov     yPos, edx

      .if eax > SplitH && eax < SplitH[8] && edx >= SplitH[4] && edx <= SplitH[12] && BarType != 2
         INVOKE     LoadCursor, hInst, 899
         INVOKE     SetCursor, eax
         INVOKE     SetCapture, hWnd
            mov     BarType, 1
      .elseif eax >= SplitV && eax <= SplitV[8] && edx > SplitV[4] && edx < SplitV[12] && BarType != 1
         INVOKE     LoadCursor, hInst, 898
         INVOKE     SetCursor, eax
         INVOKE     SetCapture, hWnd
            mov     BarType, 2
      .else

;---------- [Release the mouse if out of the area] ----------
         .if wParam != MK_LBUTTON
               xor     esi, esi
            .if BarType == 1
                  lea     esi, SplitH
            .elseif BarType == 2
                  lea     esi, SplitV
            .endif
            .if esi
               .if eax < [esi] || eax > [esi+8] || edx < [esi+4] || edx > [esi+12]
                     and     BarType, 0
                  INVOKE     ReleaseCapture
               .endif
            .endif
         .endif
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
      .endif

      .if wParam == MK_LBUTTON
         INVOKE     GetClientRect, hWnd, addr rect
            mov     ecx, xPos
            mov     edx, yPos
            add     rect.top, 24
            sub     rect.bottom, 41
         .if ecx > rect.left && ecx < rect.right && edx > rect.top && edx < rect.bottom
         .else
               jmp     Ret0
         .endif

;---------- [Create and drag the Splitter bar] ----------
         .if BarType == 1                   ; Horizontal
               mov     ecx, SplitV
            .if xPos < ecx
               INVOKE     LoadCursor, hInst, 899
               INVOKE     SetCursor, eax
               .if !hSplitBar
                  INVOKE     CreateDialogParam, hInst, 4803, hWnd, offset SplitBarProc, 0
               .endif
                  mov     eax, yPos
                  dec     eax
                  dec     eax
                  mov     SplitH[4], eax
                  add     eax, 2
                  mov     SplitH[12], eax
               INVOKE     GetWindowRect, hWnd, addr rect
                  add     rect.left, 6
                  mov     eax, rect.top
                  add     eax, 44
                  add     eax, SplitH[4]
                  inc     eax
                  mov     rect.top, eax
                  mov     edx, SplitH[8]
                  sub     edx, 2
               INVOKE     MoveWindow, hSplitBar, rect.left, rect.top, edx, 2, TRUE
            .endif
         .endif

         .if BarType == 2                       ; Vertical
            INVOKE     LoadCursor, hInst, 898
            INVOKE     SetCursor, eax
            .if !hSplitBar
               INVOKE     CreateDialogParam, hInst, 4803, hWnd, offset SplitBarProc, 0
            .endif
               mov     eax, xPos
               dec     eax
               dec     eax
               mov     SplitV, eax
               add     eax, 2
               mov     SplitV[8], eax
            INVOKE     GetClientRect, hREdit, addr rect
             MOVmd     dwBot, rect.bottom
            INVOKE     GetWindowRect, hWnd, addr rect
               mov     eax, dwTop
               add     rect.top, eax
               add     rect.left, 6
               mov     ecx, rect.left
               add     ecx, SplitV
               inc     ecx
            INVOKE     MoveWindow, hSplitBar, ecx, rect.top, 2, dwBot, TRUE
         .endif
      .endif

Ret0:
         ret
ChkSplitter ENDP

;===================================================
; About PROCEDURE
;===================================================
GetSysInfo PROC uses ebx hdlg:DWORD, wMsg, wParam, lParam
LOCAL    ms:MEMORYSTATUS
LOCAL    fts:FINDTEXT
LOCAL    crs:CHARRANGE
LOCAL    trs:TEXTRANGE
LOCAL    hTemp:DWORD
LOCAL    szBuff0[256]:BYTE, szBuff1[256]:BYTE, szWork[10]:BYTE

      .if wMsg == WM_INITDIALOG
         .if lParam == 1
               mov     ms.dwLength, sizeof ms
            INVOKE     GlobalMemoryStatus, addr ms
            INVOKE     BaseAscii, ms.dwTotalPhys, addr szBuff0, 10, 10, 1, 0, 1
            INVOKE     SetDlgItemText, hdlg, 401, addr szBuff0
            INVOKE     BaseAscii, ms.dwAvailPhys, addr szBuff0, 10, 10, 1, 0, 1
            INVOKE     SetDlgItemText, hdlg, 402, addr szBuff0
            INVOKE     BaseAscii, ms.dwMemoryLoad, addr szBuff0, 2, 10, 0, 0, 1
            INVOKE     SetDlgItemText, hdlg, 403, addr szBuff0
            INVOKE     GetDlgItem, hdlg, IDOK
               mov     h42, eax
            INVOKE     GetDlgItem, hdlg, 431
            INVOKE     SetFocus, eax

         .else
            INVOKE     GetDlgItem, hdlg, IDOK
               mov     h42, eax

            INVOKE     CreateWindowEx, 0, addr RichEdit, 0, WS_POPUP or ES_MULTILINE,\
                       100, 100, 300, 400, 0, 0, hInst, 0
               mov     hTemp, eax
            INVOKE     SendMessage, hTemp, EM_EXLIMITTEXT, 0, 50000
            INVOKE     lstrcpy, addr szBuff0, addr AsmRootDir
            INVOKE     lstrcat, addr szBuff0, addr szHelpFiles
            INVOKE     lstrcat, addr szBuff0, addr szLangCode
               mov     ecx, hBuff
            INVOKE     lstrcpy, ecx, addr szBuff0
              call     ReadF
            .if eax == -1
                  jmp     EndIt
            .else
               INVOKE     SendMessage, hTemp, WM_SETTEXT, 0, fpMem
            .endif
            .if hpMem
               INVOKE     GlobalUnlock, fpMem
               INVOKE     GlobalFree, hpMem
                  mov     hpMem, 0
            .endif

;---------- [Operating system] ----------
               mov     byte ptr szBuff1, 0
            INVOKE     BaseAscii, osv.dwMajorVersion, addr szWork, 2, 10, 0, 1, 1
            INVOKE     lstrcat, addr szBuff1, addr szWork
            INVOKE     BaseAscii, osv.dwMinorVersion, addr szWork, 2, 10, 0, 1, 1
            INVOKE     lstrcat, addr szBuff1, addr szWork
            INVOKE     BaseAscii, osv.dwPlatformId, addr szWork, 2, 10, 0, 1, 1
            INVOKE     lstrcat, addr szBuff1, addr szWork

               mov     fts.chrg.cpMin, 0
               mov     fts.chrg.cpMax, -1
               lea     eax, szBuff1
               mov     fts.lpstrText, eax
            INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr fts
            .if eax != -1
                  add     eax, 10
                  mov     fts.chrg.cpMin, eax
                  mov     trs.chrg.cpMin, eax
                  lea     eax, szCR
                  mov     fts.lpstrText, eax
               INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN, addr fts
                  .if eax != -1
                        mov     trs.chrg.cpMax, eax
                        lea     eax, szBuff1
                        mov     trs.lpstrText, eax
                     INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
                  .endif
            .endif
            INVOKE     SetDlgItemText, hdlg, 821, addr szBuff1

;---------- [Platform] ----------
            INVOKE     BaseAscii, osv.dwPlatformId, addr szWork, 2, 10, 0, 1, 1
            INVOKE     lstrcpy, addr szBuff1, addr szWork
               mov     fts.chrg.cpMin, 0
               mov     fts.chrg.cpMax, -1
               lea     eax, szBuff1
               mov     fts.lpstrText, eax
            INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr fts
            .if eax != -1
                  add     eax, 3
                  mov     trs.chrg.cpMin, eax
                  add     eax, 26
                  mov     trs.chrg.cpMax, eax
                  lea     eax, szBuff1
                  mov     trs.lpstrText, eax
               INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
            .endif
            INVOKE     SetDlgItemText, hdlg, 822, addr szBuff1
   
;---------- [Build number] ----------
               mov     ecx, osv.dwBuildNumber
            .if osvID == 1
                  and     ecx, 0000ffffh
            .endif
            INVOKE     BaseAscii, ecx, addr szWork, 1, 10, 0, 1, 1
            INVOKE     lstrcpy, addr szBuff1, addr szWork

               mov     fts.chrg.cpMin, 0
               mov     fts.chrg.cpMax, -1
               lea     eax, szBuff1
               mov     fts.lpstrText, eax
            INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr fts
            .if eax != -1
                  add     eax, 2
                  mov     trs.chrg.cpMin, eax
                  add     eax, 25
                  mov     trs.chrg.cpMax, eax
                  lea     eax, szBuff1
                  mov     trs.lpstrText, eax
               INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
            .endif
            INVOKE     SetDlgItemText, hdlg, 823, addr szBuff1
            INVOKE     SetDlgItemText, hdlg, 824, addr osv.szCSDVersion

;---------- [Language] ----------
               mov     ecx, LangID
            INVOKE     BaseAscii, ecx, addr szWork, 4, 16, 0, 1, 1
            INVOKE     lstrcpy, addr szBuff0, addr sz0x
            INVOKE     lstrcat, addr szBuff0, addr szWork
               mov     fts.chrg.cpMin, 0
               mov     fts.chrg.cpMax, -1
               lea     eax, szBuff0
               mov     fts.lpstrText, eax
            INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr fts
            .if eax != -1
                  add     eax, 13
                  mov     trs.chrg.cpMin, eax
                  add     eax, 19
                  mov     trs.chrg.cpMax, eax
                  lea     eax, szBuff1
                  mov     trs.lpstrText, eax
               INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
            .endif
            INVOKE     lstrcat, addr szBuff0, addr szSpace2
            INVOKE     lstrcat, addr szBuff0, addr szBuff1
            INVOKE     SetDlgItemText, hdlg, 825, addr szBuff0

;---------- [Country] ----------
               add     trs.chrg.cpMin, 20
               add     trs.chrg.cpMax, 28
               lea     eax, szBuff1
               mov     trs.lpstrText, eax
            INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
            INVOKE     SetDlgItemText, hdlg, 826, addr szBuff1

;---------- [OEM Code page] ----------
;               mov     eax, cpi.CodePage
               mov     ecx, cpOEM
            INVOKE     BaseAscii, ecx, addr szWork, 0, 10, 0, 1, 1
            INVOKE     lstrcpy, addr szBuff0, addr szWork

               mov     fts.chrg.cpMin, 0
               mov     fts.chrg.cpMax, -1
               lea     eax, szBuff1
               mov     fts.lpstrText, eax
            INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr fts
            .if eax != -1
                  add     eax, 13
                  mov     trs.chrg.cpMin, eax
                  add     eax, 19
                  mov     trs.chrg.cpMax, eax
                  lea     eax, szBuff1
                  mov     trs.lpstrText, eax
               INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
            .endif
            INVOKE     lstrcat, addr szBuff0, addr szSpace2
            INVOKE     lstrcat, addr szBuff0, addr szBuff1
            INVOKE     SetDlgItemText, hdlg, 827, addr szBuff0

;---------- [ANSI Code page] ----------
               mov     ecx, cpANSI
            INVOKE     BaseAscii, ecx, addr szWork, 0, 10, 0, 1, 1
            INVOKE     lstrcpy, addr szBuff0, addr szWork

               mov     fts.chrg.cpMin, 0
               mov     fts.chrg.cpMax, -1
               lea     eax, szBuff0
               mov     fts.lpstrText, eax
            INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr fts
            .if eax != -1
                  add     eax, 13
                  mov     fts.chrg.cpMin, eax
                  mov     trs.chrg.cpMin, eax
                  lea     eax, szCR
                  mov     fts.lpstrText, eax
               INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN, addr fts
               .if eax != -1
                     mov     trs.chrg.cpMax, eax
                     lea     eax, szBuff1
                     mov     trs.lpstrText, eax
                  INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
               .endif
               INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
            .endif
            INVOKE     lstrcat, addr szBuff0, addr szSpace2
            INVOKE     lstrcat, addr szBuff0, addr szBuff1
            INVOKE     SetDlgItemText, hdlg, 828, addr szBuff0

;            INVOKE     SetDlgItemText, hdlg, 827, addr cpi.CodePageName

;---------- [Character set] ----------
               xor     ecx, ecx
               mov     cl, lf.lfCharSet
            INVOKE     BaseAscii, ecx, addr szWork, 3, 10, 0, 1, 1
            INVOKE     lstrcpy, addr szBuff0, addr szWork

               mov     fts.chrg.cpMin, 0
               mov     fts.chrg.cpMax, -1
               lea     eax, szBuff0
               mov     fts.lpstrText, eax
            INVOKE     SendMessage, hTemp, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr fts
            .if eax != -1
                  add     eax, 4
                  mov     trs.chrg.cpMin, eax
                  add     eax, 20
                  mov     trs.chrg.cpMax, eax
                  lea     eax, szBuff1
                  mov     trs.lpstrText, eax
               INVOKE     SendMessage, hTemp, EM_GETTEXTRANGE, 0, addr trs
            .endif
            .if lf.lfCharSet
               INVOKE     lstrcat, addr szBuff0, addr szSpace2
               INVOKE     lstrcat, addr szBuff0, addr szBuff1
            .else
               INVOKE     lstrcpy, addr szBuff0, addr szBuff1
            .endif
            INVOKE     SetDlgItemText, hdlg, 829, addr szBuff0

            INVOKE     DestroyWindow, hTemp
            INVOKE     GetDlgItem, hdlg, 431
            INVOKE     SetFocus, eax
         .endif

      .elseif wMsg == WM_CTLCOLORDLG || wMsg == WM_CTLCOLORSTATIC
         INVOKE     SetBkColor, wParam, Color.DialogBC
         INVOKE     SetTextColor, wParam, 00000000h
            mov     eax, hBRD
            ret

      .elseif wMsg == WM_CTLCOLOREDIT
         INVOKE     SetBkColor, wParam, 00000000h   ; Background color is black
         INVOKE     SetTextColor, wParam, 00ffff00h ; Text color of edit box is lt blue
         INVOKE     GetStockObject, BLACK_BRUSH     ; Select the black brush for background
            ret

      .elseif wMsg == WM_DRAWITEM
         INVOKE     DrawButt, lParam
            jmp     SysInfoDone

      .elseif wMsg == WM_CLOSE
            jmp     EndIt

      .elseif wMsg != WM_COMMAND
            jmp     SysInfoDone
      .endif
         mov     eax, wParam
         mov     ebx, wParam
         shr     ebx, 16

      .if ebx == BN_CLICKED
         INVOKE     GetFocus
         INVOKE     GetDlgCtrlID, eax
      .endif

      .if eax == IDOK
            jmp     EndIt
      .endif
         jmp     SysInfoDone

EndIt:
         and     hWndDlg, 0
;      INVOKE     EndDialog, hdlg, wParam
      INVOKE     DestroyWindow, hdlg
      INVOKE     SetFocus, hREdit
         mov     eax, TRUE               ; Return
         jmp     SysInfoRet              ; with TRUE

SysInfoDone:
         mov     eax, FALSE              ; Return with FALSE

SysInfoRet:
         ret
GetSysInfo ENDP

;===================================================
; Set editor values
;===================================================
SetValues PROC uses ebx uMsg:DWORD, wParam, lParam
LOCAL    Cnt:DWORD, Incr

      INVOKE     SendMessage,  hWndTab, TCM_GETITEMCOUNT, 0, 0
         dec     eax
         mov     Cnt, eax
         mov     Incr, 1
      .while (Cnt)
            mov     eax, Incr                    ; Tab number
            mov     ebx, hTabSeL[eax*8]          ; Extract REdit handle
            mov     ecx, hTabSeL[eax*8+4]        ; FileType
         .if ebx && ebx != 1234
              push     ecx
            INVOKE     SendMessage, ebx, uMsg, wParam, lParam
               pop     ecx
            .if ecx == 3                         ; HTML
               INVOKE     SendMessage, ebx, UM_HTMLCOLOR, 0, addr Color01+64
            .endif
         .endif
            inc     Incr
            dec     Cnt
      .endw

         ret
SetValues ENDP

;===================================================
; Registry Query for text strings
;===================================================
RegQuerySZ PROC ValueName:DWORD, Default
LOCAL    hRegQ:DWORD

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hRegQ, addr lpdwDisp
      INVOKE     RegQueryValueEx, hRegQ, ValueName, 0, addr lpType, Default, addr lpcbData
        push     eax
      INVOKE     RegCloseKey, hRegQ
         pop     eax
         ret

RegQuerySZ  ENDP

;===================================================
; Return the integer value in eax from the registry
;===================================================
RegQuery PROC  uses ebx  ValueName:DWORD, Default
LOCAL     hRegQ:DWORD

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hRegQ, addr lpdwDisp
         mov     lpcbData, 4
      INVOKE     RegQueryValueEx, hRegQ, ValueName, 0, addr lpType, Default, addr lpcbData
      INVOKE     RegCloseKey, hRegQ
         ret

RegQuery ENDP

;===================================================
; Registry set for text strings
;===================================================
RegSetSZ PROC ValueName:DWORD, Default
LOCAL    hRegS:DWORD

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hRegS, addr lpdwDisp
      INVOKE     RegSetValueEx, hRegS, ValueName, 0, REG_SZ, Default, lpcbData
        push     eax
      INVOKE     RegCloseKey, hRegS
         pop     eax
         ret

RegSetSZ  ENDP

;===================================================
; Sets the integer value in the registry
;===================================================
RegSet PROC  uses ebx  ValueName:DWORD, Value
LOCAL     hRegS:DWORD

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hRegS, addr lpdwDisp
         mov     lpcbData, 4
      INVOKE     RegSetValueEx, hRegS, ValueName, 0, REG_DWORD, Value, lpcbData
      INVOKE     RegCloseKey, hRegS
         ret

RegSet ENDP

;===================================================
; Saves information about AsmEdit to the registry
;===================================================
RegSave PROC  uses ebx esi edi
LOCAL    rect:RECT
LOCAL    hRegS:DWORD

      .if NoSetup
            and     NoSetup, 0
            mov     ecx, 50
           call     ExpImpRegistory
      .endif

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hRegS, addr lpdwDisp

        call     GetDesktopWindow
         mov     ecx, eax
      INVOKE     GetWindowRect, ecx, addr rect
         mov     esi, rect.right
         mov     edi, rect.bottom
      INVOKE     GetWindowRect, hWnd, addr rect
         cmp     esi, rect.right
         jle     NoSavePos              ; If window is maximized or past right
         cmp     edi, rect.bottom
         jle     NoSavePos              ; If window is maximized or past bottom
         mov     eax, rect.top
         shr     eax, 16
         cmp     eax, 0000ffffh
          je     NoSavePos              ; If window is minimized
         mov     eax, rect.left
         sub     rect.right, eax
         mov     eax, rect.top
         sub     rect.bottom, eax
       MOVmd     WndPos, rect.left
       MOVmd     WndPos+4, rect.top
       MOVmd     WndPos+8, rect.right
       MOVmd     WndPos+12, rect.bottom
      INVOKE     RegSetValueEx, hRegS, addr szWndPos, 0, REG_BINARY, addr WndPos, 16

NoSavePos:
       MOVmd     SyntaxOn, SavSyntaxOn
      INVOKE     RegSet, addr szAuto, addr AutoSave
      INVOKE     RegSet, addr szCloseOn, addr CloseBuild
      INVOKE     RegSet, addr szFilterOn, addr FilterOn
      INVOKE     RegSet, addr szFontZoomOn, addr FontZoomOn
      INVOKE     RegSet, addr szItalicOn, addr ItalicOn
      INVOKE     RegSet, addr szLeadingOn, addr LeadingOn
      INVOKE     RegSet, addr szIndentOn, addr IndentOn
      INVOKE     RegSet, addr szAutoRefOn, addr AutoRefOn
      INVOKE     RegSet, addr szMaxWin, addr MaxWin
      INVOKE     RegSet, addr szNoHiLiteBW, addr NoHiLiteBW
      INVOKE     RegSet, addr szProjWnd, addr ProjOn
      INVOKE     RegSet, addr szDrvWnd, addr DriveOn
      INVOKE     RegSet, addr szCodeHelper, addr CodeHelperOn
      INVOKE     RegSet, addr szBeepOn, addr BeepOn
      INVOKE     RegSet, addr szSpaceAfter, addr SpaceAfter
      INVOKE     RegSet, addr szRightAlign, addr RightAlign
      INVOKE     RegSet, addr szMinMatch, addr MinMatch
      INVOKE     RegSet, addr szIndent, addr Indent
      INVOKE     RegSet, addr szOutdent, addr Outdent
      INVOKE     RegSet, addr szQuick, addr QuickOn
      INVOKE     RegSet, addr szUser, addr UserOn
      INVOKE     RegSet, addr szSmoothOn, addr SmoothOn
      INVOKE     RegSet, addr szSyntaxOn, addr SyntaxOn
      INVOKE     RegSet, addr szShiftT, addr SHIFT
      INVOKE     RegSet, addr szSpaceN, addr SPACE
      INVOKE     RegSet, addr szSpeed, addr Speed
      INVOKE     RegSet, addr szTabWth, addr TAB
      INVOKE     RegSet, addr szLineWth, addr LineWth
      INVOKE     RegSet, addr szWheelNum, addr WheelNum


      INVOKE     RegSet, addr szProjGroup, addr ProjGroup
      INVOKE     RegSet, addr szFilterGroup, addr FilterGroup

      INVOKE     RegSetValueEx, hRegS, addr szSplitterH, 0, REG_BINARY, addr SplitH, 16
      INVOKE     RegSetValueEx, hRegS, addr szSplitterV, 0, REG_BINARY, addr SplitV, 16

      INVOKE     RegSetValueEx, hRegS, addr szFontEdit, 0, REG_BINARY, addr FontEdit, sizeof FontEdit
      INVOKE     RegSetValueEx, hRegS, addr szFontLine, 0, REG_BINARY, addr FontLine, sizeof FontLine
      INVOKE     RegSetValueEx, hRegS, addr szFontTree, 0, REG_BINARY, addr FontTree, sizeof FontTree
      INVOKE     RegSetValueEx, hRegS, addr szColor, 0, REG_BINARY, addr Color, sizeof Color
      INVOKE     RegSetValueEx, hRegS, addr szColor01, 0, REG_BINARY, addr Color01, sizeof Color01
      INVOKE     RegSetValueEx, hRegS, addr szCustClrs, 0, REG_BINARY, addr CustClrs, sizeof CustClrs

         mov     lpcbData, sizeof szLoadPath
      INVOKE     RegSetValueEx, hRegS, addr rDEFl, 0, REG_SZ, addr szLoadPath, lpcbData
         mov     lpcbData, sizeof szLoadPathD
      INVOKE     RegSetValueEx, hRegS, addr DrivePath, 0, REG_SZ, addr szLoadPathD, lpcbData

;      INVOKE     lstrlen, addr szProject
;         mov     lpcbData, eax
;      INVOKE     RegSetValueEx, hRegS, addr szProjN, 0, REG_SZ, addr szProject, lpcbData

         xor     ebx, ebx
         mov     esi, 6
      .while (esi)
            mov     lpcbData, sizeof szProject
         INVOKE     RegSetValueEx, hRegS, ProjNArray[ebx*4], 0, REG_SZ, ProjNamArray[ebx*4], lpcbData
            inc     ebx
            dec     esi
      .endw

      INVOKE     lstrlen, addr Userkeyw01
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hRegS, addr szKeywU01, 0, REG_SZ, addr Userkeyw01, lpcbData
      INVOKE     lstrlen, addr Userkeyw02
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hRegS, addr szKeywU02, 0, REG_SZ, addr Userkeyw02, lpcbData

         mov     lpcbData, sizeof UserFilt01
      INVOKE     RegSetValueEx, hRegS, addr szFiltU01, 0, REG_SZ, addr UserFilt01, lpcbData
         mov     lpcbData, sizeof UserFilt02
      INVOKE     RegSetValueEx, hRegS, addr szFiltU02, 0, REG_SZ, addr UserFilt02, lpcbData

      INVOKE     RegCloseKey, hRegS
         ret
RegSave ENDP

;=====================================================
; Export or Import the AsmEdit registory settings PROCEDURE
;=====================================================
ExpImpRegistory PROC
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    stin:STARTUPINFO
LOCAL    prin:PROCESS_INFORMATION
LOCAL    szBuff0[256]:BYTE

      .if ecx == 50
;---------- [Backup the AsmEdit registry if it has not been done] ----------
         INVOKE     lstrcpy, addr szBuff0, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff0, addr szRegistryDir
         INVOKE     lstrcat, addr szBuff0, addr szRegAsmEdit
         INVOKE     FindFirstFile, addr szBuff0, addr FindData
         .if eax == -1
               mov     ecx, 51
         .else
            INVOKE     FindClose, eax
         .endif
      .endif

      .if ecx == 51
         INVOKE     lstrcpy, addr szBuff0, addr szExpAsmEdit1
         INVOKE     lstrcat, addr szBuff0, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff0, addr szRegistryDir
         INVOKE     lstrcat, addr szBuff0, addr szRegAsmEdit
         INVOKE     lstrcat, addr szBuff0, addr szExpAsmEdit2
; regedit.exe /e L:\MASM32V1\Programs\AsmEdit\Registry\RegAsmEdit.reg
; "HKEY_CURRENT_USER\Software\EW Software\AsmEdit V5"

      .elseif ecx == 52
         INVOKE     lstrcpy, addr szBuff0, addr szImpAsmEdit1
         INVOKE     lstrcat, addr szBuff0, addr AsmRootDir
         INVOKE     lstrcat, addr szBuff0, addr szRegistryDir
         INVOKE     lstrcat, addr szBuff0, addr szRegAsmEdit
 ; regedit.exe /s L:\MASM32V1\Programs\AsmEdit\Registry\RegAsmEdit.reg
      .else
            ret
      .endif

      INVOKE     RtlZeroMemory, addr stin, sizeof STARTUPINFO
         mov     stin.cb, sizeof STARTUPINFO
      INVOKE     GetStartupInfo, addr stin
         mov     stin.wShowWindow, SW_HIDE
      INVOKE     CreateProcess, 0, addr szBuff0, 0, 0, FALSE,\
                 NORMAL_PRIORITY_CLASS, 0, addr AsmRootDir, addr stin, addr prin
.if !eax
; Do message
INVOKE     MessageBox, NULL, addr szBuff0, addr AppName, MB_OK
.endif
      INVOKE     CloseHandle, prin.hThread
      INVOKE     CloseHandle, prin.hProcess

         ret

ExpImpRegistory ENDP

end start
