   title   ResEdit - DLL Normal Window With (.rc)
         comment '======================================================|'
         comment '* ResEdit v1.0                                        *'
         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  L:\AsmEdit\include\windows.inc
            include  user32.inc
            include  gdi32.inc
            include  kernel32.inc
            include  comdlg32.inc
            include  comctl32.inc
            include  advapi32.inc
            include  ole32.inc
            include  oleaut32.inc

   include  L:\AsmEdit\include\DSPMACRO.asm

         includelib  user32.lib
         includelib  gdi32.lib
         includelib  kernel32.lib
         includelib  comdlg32.lib
         includelib  comctl32.lib
         includelib  advapi32.lib
         includelib  ole32.lib
         includelib  oleaut32.lib

            include  ResEdit.inc

WinMain         PROTO  :DWORD, :DWORD, :DWORD, :DWORD
TabCtlDlg       PROTO  :DWORD, :DWORD, :DWORD, :DWORD
ResourceDlg     PROTO  :DWORD, :DWORD, :DWORD, :DWORD
MenuDlg         PROTO  :DWORD, :DWORD, :DWORD, :DWORD
DialogDlg       PROTO  :DWORD, :DWORD, :DWORD, :DWORD
ExtractDlg      PROTO  :DWORD, :DWORD, :DWORD, :DWORD
BuildDlg        PROTO  :DWORD, :DWORD, :DWORD, :DWORD
SampleDlg       PROTO  :DWORD, :DWORD, :DWORD, :DWORD
RichEditProc    PROTO  :DWORD, :DWORD, :DWORD, :DWORD
WorkProc        PROTO  :DWORD, :DWORD, :DWORD, :DWORD
FillBuffer      PROTO  :DWORD, :DWORD, :BYTE, :DWORD
REditP          PROTO  :DWORD, :DWORD, :DWORD, :DWORD
ControlButtP    PROTO  :DWORD, :DWORD, :DWORD, :DWORD
SizeDataProc    PROTO  :DWORD, :DWORD, :DWORD, :DWORD
StyleProc       PROTO  :DWORD, :DWORD, :DWORD, :DWORD
OptionsProc     PROTO  :DWORD, :DWORD, :DWORD, :DWORD
PosProc         PROTO  :DWORD, :DWORD, :DWORD, :DWORD
ListBoxProc     PROTO  :DWORD, :DWORD, :DWORD, :DWORD
ListPopProc     PROTO  :DWORD, :DWORD, :DWORD, :DWORD
SizeProc        PROTO  :DWORD, :DWORD, :DWORD, :DWORD
MultiProc       PROTO  :DWORD, :DWORD, :DWORD, :DWORD
MouseMUD        PROTO  :DWORD, :DWORD, :DWORD, :DWORD
BaseAscii       PROTO  :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
AsciiBase       PROTO  :DWORD, :DWORD
ControlRect     PROTO  :DWORD, :DWORD, :DWORD
GetOffset       PROTO  :DWORD
GetSizes        PROTO  :DWORD
LoadGrabbers    PROTO  :DWORD
MoveGrabbers    PROTO  :DWORD, :DWORD
CreateControls  PROTO  :DWORD, :DWORD
CreateWin       PROTO  :DWORD, :DWORD, :DWORD
SaticProcR      PROTO  :DWORD, :DWORD, :DWORD, :DWORD
SampleDlgS      PROTO  :DWORD, :DWORD, :DWORD, :DWORD
GetDefines      PROTO  :DWORD, :DWORD, :DWORD
ReloadCtrl      PROTO  :DWORD
ProcessMRUFiles PROTO  :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
GetRegPath      PROTO  :DWORD, :DWORD
ExtractRsrc     PROTO  :DWORD, :DWORD, :DWORD, :DWORD

;MoveSize        PROTO  :DWORD

TBSep    MACRO hTool
           mov     tbb.iBitmap, 0
           mov     tbb.idCommand, 0
           mov     tbb.fsState, TBSTATE_ENABLED
           mov     tbb.fsStyle, TBSTYLE_SEP
        INVOKE     SendMessage, hTool, TB_ADDBUTTONS, 1, addr tbb
          ENDM

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

MOVmd    MACRO Var1, Var2
         push     Var2
          pop     Var1
         ENDM

.const
EditID         equ 1
IDM_CUT        equ 1005
IDM_COPY       equ 1006
IDM_PASTE      equ 1007
IDM_DEL        equ 1008
IDM_SELALL     equ 1009
IDB_TOOL       equ 7002
IDB_TOOLS      equ 7003

.data
AppName        db  'Resource Editor',0
ClassName      db  'Resource Editor',0
WorkClass      db  'Work Window',0
SizeClassV     db  'SizeClassV',0
SizeClassH     db  'SizeClassH',0
MultiClass     db  'MultiClass',0

RichEdDLL      db  'RICHED20.DLL',0
GroupClass     db  'GroupClass',0

FormClass      db  'Form Builder',0
StaticClass    db  'static',0
ButtClass      db  'button',0
EditClass      db  'edit',0
RichEdit       db  'RichEdit20A',0
ComboClass     db  'combobox',0
ListboxClass   db  'listbox',0
TreeClass      db  'SysTreeView32',0   
ListViewClass  db  'SysListView32',0
ToolClass      db  'ToolbarWindow32',0
StatClass      db  'msctls_statusbar32',0
ScrollHClass   db  'SCROLLBAR',0
ScrollVClass   db  'SCROLLBAR',0
ProgressClass  db  'msctls_progress32',0
TrackbarClass  db  'msctls_trackbar32',0
UpDownClass    db  'msctls_updown32',0
TabCtrlClass   db  'SysTabControl32',0
SysMonthClass  db  'SysMonthCal32',0
SysPickClass   db  'SysDateTimePick32',0
BitmapClass    db  'static',0
IconClass      db  'static',0
IconAniClass   db  'static',0
AnimateClass   db  'SysAnimate32',0
IPAddressClass db  'SysIPAddress32',0
HotkeyClass    db  'msctls_hotkey32',0
CustClass      db  'CustClass',0
RichEdit44     db  'RichEdit44',0
DummyClass     db  'DummyClass',0

ClassArray     dd  FormClass,StaticClass,ButtClass,ButtClass,ButtClass,ButtClass,EditClass,RichEdit,
                   ComboClass,ListboxClass,TreeClass,ListViewClass,ToolClass,StatClass,
                   ScrollHClass,ScrollVClass,ProgressClass,TrackbarClass,UpDownClass,TabCtrlClass,
                   SysMonthClass,SysPickClass,BitmapClass,IconClass,IconAniClass,AnimateClass,
                   IPAddressClass,HotkeyClass,ButtClass,RichEdit44,DummyClass

MenuName       db  'MainMenu',0
PopupMenu      db  'PopupMenu',0
ResourceMenu   db  'ResourceMenu',0
FileMenu       db  'FileMenu',0

FontName       db  'Courier New',0
FontMS         db  'MS Sans Serif',0  ;'Arial',0
FontSYS        db  'System',0
FontMSD        db  '8, "MS Sans Serif"',0
szGlobe        db  'globe.ani',0
szAnimateAvi   db  'globe.avi',0

szRedit        db  'ResEdit',0
szREGSZ        db  'REG_SZ',0
szDlgD         db  'DefDlg',0
szStaD         db  'DefSta',0
szGrpD         db  'DefGrp',0
szRadD         db  'DefRad',0
szChkD         db  'DefChk',0
szButD         db  'DefBut',0
szEdiD         db  'DefEdi',0
szRedD         db  'DefRed',0
szCobD         db  'DefCob',0
szLibD         db  'DefLib',0
szTrvD         db  'DefTrv',0
szLivD         db  'DefLiv',0
szGridOn       db  'Show Grid',0
szGrid         db  'Size Grid',0
szSnapOn       db  'Snap To',0
szResL         db  'Last Resource',0

szError1       db  'The RICHED20.DLL was not found!',0
szError2       db  'There is a mismatch between the numbers',0dh,0ah
               db  ' of BEGIN and END statements',0
szError3       db  'The MAXIMUM number of controls has been reached',0
szError5       db  'The above dialog name already exists.',0dh,0ah
               db  '         Do you wish to replace it?',0

szSample       db  '\SampleRC.txt',0
szStyles       db  '\Res\Styles.sty',0
szWS           db  'WS_OVERLAPPED',0
szDS           db  'DS_ABSALIGN',0
szDivider      db  ' **** Control Styles ****',0

ddDlg          dd  0h,0h,0h,0h,0h,0h,0h,0h,10C80000h,00000080h
ddSta          dd  100h,0h,0h,0h,0h,0h,0h,0h,50000000h,00000000h
ddGrp          dd  7h,0h,0h,0h,0h,0h,0h,0h,50000000h,00000000h
ddRad          dd  9h,0h,0h,0h,0h,0h,0h,0h,50010000h,00000000h
ddChk          dd  3h,0h,0h,0h,0h,0h,0h,0h,50010000h,00000000h
ddBut          dd  0h,0h,0h,0h,0h,0h,0h,0h,50010000h,00000000h
ddEdi          dd  0h,0h,0h,0h,0h,0h,0h,0h,50010000h,00000000h
ddRed          dd  4h,0h,0h,0h,0h,0h,0h,0h,50310000h,00000200h
ddCob          dd  3h,100h,200h,400h,0h,0h,0h,0h,50200000h,00000000h
ddLib          dd  1h,40h,100h,0h,0h,0h,0h,0h,50200000h,00000000h
ddTrv          dd  1h,4h,20h,0h,0h,0h,0h,0h,50000000h,00000200h
ddLiv          dd  1h,8h,10h,0h,0h,0h,0h,0h,50000000h,00000200h
;Defs           dd  ddDlg,ddSta,ddGrp,ddRad,ddChk,ddBut,ddEdi,ddRed,ddCob,ddLib,ddTrv,ddLiv

ddDlgD         dd  10    dup(?)
ddStaD         dd  10    dup(?)
ddGrpD         dd  10    dup(?)
ddRadD         dd  10    dup(?)
ddChkD         dd  10    dup(?)
ddButD         dd  10    dup(?)
ddEdiD         dd  10    dup(?)
ddRedD         dd  10    dup(?)
ddCobD         dd  10    dup(?)
ddLibD         dd  10    dup(?)
ddTrvD         dd  10    dup(?)
ddLivD         dd  10    dup(?)
;DefsD          dd  ddDlgD,ddStaD,ddGrpD,ddRadD,ddChkD,ddButD,ddEdiD,ddRedD,ddCobD,ddLibD,ddTrvD,ddLivD

szOpenTitle    db  'Open A Resource File',0
szSaveTitle    db  'Save File As',0
szFilter       db  'RC Files',0,'*.rc',0,0
szRC           db  'xxxx.rc',0

szDlg          db  'IDD_DLG',0      ; 7501
szSta          db  'IDC_STATIC',0   ; 7502 static
szGrp          db  'IDC_GRP',0      ; 7503 button
szRad          db  'IDC_RAD',0      ; 7504 button
szChk          db  'IDC_CHK',0      ; 7505 button
szBut          db  'IDC_BUTT',0     ; 7506 button
szEdit         db  'IDC_EDIT',0     ; 7507 edit
szREdit        db  'IDC_REDIT',0    ; 7508 RichEdit20A
szCombo        db  'IDC_COMBO',0    ; 7509 combobox
szListB        db  'IDC_LISTBOX',0  ; 7510 listbox
szTreeV        db  'IDC_TREE',0     ; 7511 SysTreeView32
szListV        db  'IDC_LISTVIEW',0 ; 7512 SysListView32
szTool         db  'IDC_TOOL',0
szStatus       db  'IDC_STATUS',0
szScrollH      db  'IDC_SCROLLH',0
szScrollV      db  'IDC_SCROLLV',0
szProgress     db  'IDC_PROGRESS',0
szTrack        db  'IDC_TRACKBAR',0
szUpDown       db  'IDC_UPDOWN',0
szTab          db  'IDC_TAB',0
szMonth        db  'IDC_MONTH',0
szPick         db  'IDC_PICK',0
szBitmap       db  'IDC_BITMAP',0
szIcon         db  'IDC_ICON',0
szIconAni      db  'IDC_ICONANI',0
szAnimate      db  'IDC_ANIMATE',0
szIPAdress     db  'IDC_IPADDR',0
szHotKey       db  'IDC_HOTKEY',0
szCustom       db  'IDC_CUSTOM',0
szGrp4         db  'IDC_GRP4',0

TextArray      dd  szDlg,szSta,szGrp,szRad,szChk,szBut,szEdit,szREdit,
                   szCombo,szListB,szTreeV,szListV,szTool,szStatus,szScrollH,
                   szScrollV,szProgress,szTrack,szUpDown,szTab,szMonth,szPick,
                   szBitmap,szIcon,szIconAni,szAnimate,szIPAdress,szHotKey,szCustom,szGrp4

SizeArray      dd  6,3,6,6,6,5,5,4,4,2,5,1,5,3,2,2,2,1,3,6,4,5,2,5
RStartID       dd  200
MStartID       dd  300

szComID0       db  'IDC_STATIC',0
szComID1       db  'IDOK',0
szComID2       db  'IDCANCEL',0
szComID3       db  'IDABORT',0
szComID4       db  'IDRETRY',0
szComID5       db  'IDIGNORE',0
szComID6       db  'IDYES',0
szComID7       db  'IDNO',0
szComID8       db  'IDCLOSE',0
szComID9       db  'IDHELP',0

ComIDArray     dd  szComID0,szComID1,szComID2,szComID3,szComID4,
                   szComID5,szComID6,szComID7,szComID8,szComID9

szMoveGrp      db  'Move the groupbox',0
szKeepSel      db  'Keep toolbar selection',0
szUseID        db  'Use (ID) for (Name)',0
szNoMove       db  'Lock position - size',0
szOption       db  'Options',0
szAlign        db  'Align/Size',0
szSave         db  'Save Dlg',0
szSelect       db  'Select A Dialog If Available',0

TabTitle1      db  'Resource',0
TabTitle2      db  'Menu',0
TabTitle3      db  'Dialog',0
;TabTitle4      db  'Load a .rc file',0
TabTitle4      db  'Load a resource',0
TabTitle5      db  'Build',0
TabTitle6      db  'Sample',0

szCRLF         db  0dh,0ah,0
szCR           db  0dh,0
szNULL         db  0
szSpace        db  ' ',0
szx            db  '0x',0
szQuote        db  '"',0
szComma        db  ',',0
szUnder        db  '_',0
szAstr         db  '*',0
szBackS        db  '\Res\',0
szSlashB       db  '\t',0
szVK           db  'VK_',0
szCS           db  ', ',0
szEndP         db  '*.*',0
szEndR         db  '\*.rc',0
szALL          db  'All Files',0,'*.*',0,0

szResB         db  'BITMAP  DISCARDABLE    ',0
szResI         db  'ICON    DISCARDABLE    ',0
szResC         db  'CURSOR  DISCARDABLE    ',0
szResW         db  'WAVE    DISCARDABLE    ',0
szResM         db  'MIDI    DISCARDABLE    ',0
szTxtB         db  'IDB_',0
szTxtI         db  'IDI_',0
szTxtC         db  'IDC_',0
szTxtW         db  'IDW_',0
szTxtM         db  'IDM_',0
TxtArray       dd  szTxtB,szTxtI,szTxtC,szTxtW,szTxtM
szExtB         db  '.bmp',0
szExtI         db  '.ico',0
szExtC         db  '.cur',0
szExtW         db  '.wav',0
szExtM         db  '.mid',0
ExtArray       dd  szExtB,szExtI,szExtC,szExtW,szExtM

szFilterR      db  'Resource Files',0,'*.*',0,0

szMenuN        db  '  MENU DISCARDABLE',0dh,0ah ;,0dh,0ah
               db  'BEGIN',0dh,0ah,0
szPopup        db  'POPUP ',0
szBegin        db  'BEGIN',0dh,0ah,0
szMenuI        db  'MENUITEM ',0
szSep          db  'MENUITEM SEPARATOR',0dh,0ah,0
szEnd          db  'END',0dh,0ah,0
szFindB        db  'BEGIN',0
szFindE        db  'END',0
szFixit        db  'BEGIN',0dh,0ah
               db  'END',0dh,0ah,0
szAccel        db  'IDR_ACCEL ACCELERATORS',0dh,0ah
               db  'BEGIN',0dh,0ah,0
szVKey         db  'VIRTKEY',0
szControl      db  ',  CONTROL',0

szResource     db  '#include <RESOURCE.H> ;May need to add path',0dh,0ah,0dh,0ah,0
szStatic       db  0dh,0ah,'#define   IDC_STATIC         -1',0dh,0ah,0dh,0ah,0
szEquHeader    db  '** Copy and Paste the following equates to your application program **',0dh,0ah,0
szEqu          db  'equ ',0
szDefine       db  '#define   ',0
szDlgEX        db  ' DIALOGEX LOADONCALL MOVEABLE DISCARDABLE ',0
szCont         db  '    CONTROL ',0
szCapt         db  'CAPTION ',0
szFont         db  'FONT    ',0  
szSty          db  'STYLE   ',0  
szEXSty        db  'EXSTYLE ',0  
szClass        db  'CLASS   ',0  

szDIALOG       db  'DIALOG',0

XNum           db  5 dup(?)
szX            db  ' x ',0 
YNum           db  5 dup(?)

mmsg           db  ' X: '
mmsgx          db  4 dup(' ')
               db  '   Y: '
mmsgy          db  4 dup(' '),0

szDlgNum       db  2 dup(' ')
               db  '  Dialog(s) have been extracted.',0dh,0ah
szCtrlNum      db  2 dup(' ')
               db  '  Controls(s) have been extracted.',0dh,0ah,0dh,0ah
               db  'Select the Dialog tab and then',0dh,0ah
               db  'select the Dialog from the dropdown.',0

szID           db  '(ID)',0
szName         db  '(Name)',0
szCaption      db  'Caption',0
szExStyle      db  'ExStyle',0
szStyle        db  'Style',0
szLeft         db  'Left',0
szTop          db  'Top',0
szWidth        db  'Width',0
szHeight       db  'Height',0

szTrue         db  'True',0
szFalse        db  'False',0

;szH            db  'Have',0
;szA            db  'A',0
;szN            db  'Nice',0
;szD            db  'Day',0

Base4          dd  4
Base8          dd  8
CWRound      WORD  037fh
CWNoRound    WORD  0f7fh
Round      REAL10  0.5
TestUnitX1 REAL10  6.0
TestUnitY1 REAL10  13.0
TestUnitX  REAL10  6.0273972602
TestUnitY  REAL10  13.333333333
BaseUnitX  REAL10  1.5
BaseUnitY  REAL10  1.6230366492146596859 ;1.6666666666

.data?
hLib           dd  ?
hInst          dd  ?
CommandLine    dd  ?
hREdDll        dd  ?
MainExit       dd  ?
hWnd           dd  ? 
hREdit         dd  ?
hUnder         dd  ?
hWork          dd  ?
hForm          dd  ?
hEdit          dd  ?
hGrp           dd  ?
hText          dd  ?
MenuCnt        dd  ?
hREditTab      dd  10  dup(?)
lpRichEdit     dd  ?
lpGroupBox     dd  ?
lpStaticR      dd  ?

lpStatic       dd  ?
lpButton       dd  ?
lpEdit         dd  ?
lpREdit        dd  ?
lpCombo        dd  ?
lpListbox      dd  ?
lpTreeview     dd  ?
lpListview     dd  ?
lpToolbar      dd  ?
lpStatusbar    dd  ?
lpScroll       dd  ?
lpProgess      dd  ?
lpTrackbar     dd  ?
lpUpDown       dd  ?
lpTabCtrl      dd  ?
lpSysMonth     dd  ?
lpSysPick      dd  ?
lpAnimate      dd  ?
lpIPAdress     dd  ?
lpHotKey       dd  ?

hParent        dd  ?
hWndTab        dd  ?
hDlg0          dd  ?
hDlg1          dd  ?
hDlg2          dd  ?
hDlg3          dd  ?
hDlg4          dd  ?
hDlgS          dd  ?
hREditE        dd  ?
hStatic402     dd  ?
hStatic403     dd  ?
hStatic404     dd  ?
hEdit704       dd  ?
hWndTree       dd  ?
hOpt           dd  ?
hSizePos       dd  ?
hDef           dd  ?
hWndGrp        dd  ?
hKeepSel       dd  ?
hUseID         dd  ?
hNoMove        dd  ?
hWndTool       dd  ?
hWndCombo      dd  ?
hWndComboD     dd  ?
hWndList       dd  ?
lpListBox      dd  ?
lpListPop      dd  ?
hREditP        dd  ?
hButtP         dd  ?
hListP         dd  ?
hWndStat       dd  ?
hWndStatic     dd  ?
hSavGrp        dd  ?
hCtrl          dd  ?
hList11        dd  ?
hList12        dd  ?
hList13        dd  ?

lpType         dd  ?
lpcbData       dd  ?
lpdwDisp       dd  ?

hParentA       dd  ?
hAsmEdit       dd  ?
hAsmREdit      dd  ?
hRetParent     dd  ?
hRetForm       dd  ?
FromParent     dd  ?
ParCode        dd  ?

hFont          dd  ?
hFontE         dd  ?
hFontL         dd  ?
hFontS         dd  ?
hFontT         dd  ?
hFontIP        dd  ?
hFontDlg       dd  ?
hFontSYS       dd  ?
hPat2          dd  ?
hPat3          dd  ?
hPat4          dd  ?
hPat6          dd  ?
hBRG           dd  ?
hBRR           dd  ?
hBmpB          dd  ?
hBmpR          dd  ?
hTBBmp         dd  ?
hTBBmpS        dd  ?
hBRD           dd  ?  ;
hBRP           dd  ?  ;
hIcoR          dd  ?
hIcon          dd  ?

hSMenu         dd  ?
hRMenu         dd  ?
hFMenu         dd  ?
hMenuN         dd  ?
hSubMenu       dd  ?
hSMove         dd  ?
h502           dd  ?
h503           dd  ?
h898           dd  ?
h899           dd  ?
hStyle         dd  ?
hSizeData      dd  ?
hPat           dd  ?

hDefHeap       dd  ?
Defines        dd  ?
DefinesDlg     dd  ?
Equates        dd  ?
Accelerator    dd  ?
UnDoArray      dd  ?
hString        dd  ?
hError         dd  ?
hBuff          dd  ?

;TempACnt       dd  ?
;hTempA         dd  512  dup(?)

hDlgMem        dd  30    dup(?)
ArrayCnt       dd  ?
hArray         dd  16386 dup(?)
GrpCnt         dd  ?
hGrpArray      dd  514   dup(?)
MultiCnt       dd  ?
hMultiArray    dd  64    dup(?)
hWorkArray     dd  64    dup(?)
AniCnt         dd  ?
hAniArray      dd  64    dup(?)
hDC            dd  ?
hBR            dd  ?
hBRS           dd  ?
hBrush         dd  ?
hBlackBR       dd  ?
hNewBR         dd  ?
hOldBR         dd  ?

SubREditP      dd  ?
SubBmpP        dd  ?
InputType      dd  ?
CtrlType       dd  ?
SavCtrl        dd  ?
TabIDCnt       dd  ?
IDCnt          dd  ?
IndexCnt       dd  ?
Output         dd  ?
LinitReached   dd  ?
sw1            dd  ?
sw2            dd  ?
sw3            dd  ?
sw4            dd  ?
sw5            dd  ?
sw6            dd  ?
sw44           dd  ?
Cnt            dd  ?
Len            dd  ?
GridOn         dd  ?
SnapOn         dd  ?
DlgOn          dd  ?
CtrlOn         dd  ?
ToolOn         dd  ?
StatusOn       dd  ?
ComboOn        dd  ?
GroupOn        dd  ?
KeepOn         dd  ?
UseIDOn        dd  ?
NoMoveOn       dd  ?
BorderOn       dd  ?
ConvertOn      dd  ?
hGrpOn         dd  ?
ParentOn       dd  ?
DownOn         dd  ?
FontOn         dd  ?
NameOn         dd  ?
RevOn          dd  ?
DblOn          dd  ?
HexCode        dd  ?
HaveDlg        dd  ?
SavHnd         dd  ?
CtrlHnd        dd  ?
SaveLimit      dd  ?
ErrorOn        dd  ?
NoMsg          dd  ?
vSpace         dd  ?
hSpace         dd  ?
UpID           dd  ?
UpCtrl         dd  ?
UpType         dd  ?
Grid           dd  ?
xOff           dd  ?
yOff           dd  ?
xGrp           dd  ?
yGrp           dd  ?
PosX           dd  ?
PosY           dd  ?
PosR           dd  ?
PosB           dd  ?
ParR           dd  ?
ParB           dd  ?
sPos           dd  ?
ePos           dd  ?
FormX          dd  ?
FormY          dd  ?
SizeB          dd  ?
SizeT          dd  ?
ResB           dd  ?
ResT           dd  ?
ConvX          dd  ?
ConvY          dd  ?
sbParts        dd  4   dup(?)

Test4          dd  ?
Test8          dd  ?

hTab           dd  ?
hTabSeL        equ $
hTabSeL1       dd  ?
hTabSeL2       dd  ?
hTabSeL3       dd  ?
hTabSeL4       dd  ?
hTabSeL5       dd  ?
hTabSeL6       dd  ?
TabSelect      dd  ?
SavSelect      dd  ?

hSizeL         dd  ?
hSizeT         dd  ?
hSizeR         dd  ?
hSizeB         dd  ?
lpSizeProc     dd  ?

hDlg           dd  512  dup(?)
StartID        dd  512  dup(?)
CtrlCnt        dd  512  dup(?)
CtrlID         dd  ?
StrSize        dd  ?

hRect          dd  4   dup(?)
IDStart        dd  ?
hStyles        dd  ?
hDefaults      dd  ?
DlgNum         dd  ?
CtrlNum        dd  ?
HoldM          dd  ?
StatCnt        dd  ?
TextLen        dd  ?
BytesOut       dd  ?
hMemM          dd  ?
pMemM          dd  ?

hFormDC        dd  ?
hFormMemDC     dd  ?
hFormBmp       dd  ?
hScrFormDC     dd  ?
hFormRgn       dd  ?
hOldFormRgn    dd  ?

hWorkDC        dd  ?
hWorkMemDC     dd  ?
hWorkBmp       dd  ?
hScrWorkDC     dd  ?
hWorkRgn       dd  ?
hOldWorkRgn    dd  ?

szFill         db  256 dup(?)
szBuffP        db  30  dup(?)
szBuffQ        db  10  dup(?)
szBuffR        db  512 dup(?)
szBuffT        db  512 dup(?)
Code           db  40  dup(?)
DefCode        db  32  dup(?)
szFilt         db  6   dup(?)
PathName       db  256 dup(?)
RootPath       db  256 dup(?)
WorkBuff       db  256 dup(?)
szResPath      db  256 dup(?)
FileName       db  64  dup(?)
szError        db  64  dup(?)

.Data
szExS          db  ' , , , , , , , , , , , , ,WS_EX_APPWINDOW,WS_EX_STATICEDGE,',
                   'WS_EX_CONTROLPARENT, ,WS_EX_LEFTSCROLLBAR,WS_EX_RTLREADING,',
                   'WS_EX_RIGHT, ,WS_EX_CONTEXTHELP,WS_EX_CLIENTEDGE,WS_EX_WINDOWEDGE,',
                   'WS_EX_TOOLWINDOW,WS_EX_MDICHILD,WS_EX_TRANSPARENT,WS_EX_ACCEPTFILES,',
                   'WS_EX_TOPMOST,WS_EX_NOPARENTNOTIFY, ,WS_EX_DLGMODALFRAME,',0

szSWin         db  'WS_POPUP,WS_CHILD,WS_MINIMIZE,WS_VISIBLE,WS_DISABLED,WS_CLIPSIBLINGS,',
                   'WS_CLIPCHILDREN,WS_MAXIMIZE,WS_BORDER,WS_DLGFRAME,WS_VSCROLL,WS_HSCROLL,',
                   'WS_SYSMENU,WS_THICKFRAME,WS_MINIMIZEBOX,WS_MAXIMIZEBOX,',0

szSWinCtrlS    db  'WS_POPUP,WS_CHILD, ,WS_VISIBLE,WS_DISABLED,WS_CLIPSIBLINGS,',
                   'WS_CLIPCHILDREN, ,WS_BORDER, ,WS_VSCROLL,WS_HSCROLL, , ,WS_GROUP,WS_TABSTOP,',0

szSWinCtrl     db  'WS_POPUP,WS_CHILD, ,WS_VISIBLE,WS_DISABLED,WS_CLIPSIBLINGS,',
                   'WS_CLIPCHILDREN, ,WS_BORDER, , , , , ,WS_GROUP,WS_TABSTOP,',0

szSDLG         db  ' , ,DS_CONTEXTHELP,DS_CENTERMOUSE,',
                   'DS_CENTER,DS_CONTROL,DS_SETFOREGROUND,DS_NOIDLEMSG,',
                   'DS_MODALFRAME,DS_SETFONT,DS_LOCALEDIT,DS_NOFAILCREATE,',
                   'DS_FIXEDSYS,DS_3DLOOK,DS_SYSMODAL,DS_ABSALIGN,',0

szSSta         db  'SS_PATHELLIPSIS,SS_ENDELLIPSIS, ,SS_SUNKEN,SS_REALSIZEIMAGE,SS_RIGHTJUST,',
                   'SS_CENTERIMAGE,SS_NOTIFY,SS_NOPREFIX, , ,SS_ETCHEDHORZ,',
                   'SS_GRAYFRAME,SS_BLACKRECT,SS_RIGHT,SS_CENTER,',0

szSGrp         db  ' ,BS_NOTIFY, , , , ,',
                   ' , , , , , , , , , ,',0

szSRad         db  'BS_FLAT,BS_NOTIFY,BS_MULTILINE,BS_PUSHLIKE,BS_BOTTOM,BS_TOP,',
                   'BS_RIGHT,BS_LEFT, , ,BS_LEFTTEXT, ,',
                   ' ,BS_RADIOBUTTON, , ,',0

szSChk         db  'BS_FLAT,BS_NOTIFY,BS_MULTILINE,BS_PUSHLIKE,BS_BOTTOM,BS_TOP,',
                   'BS_RIGHT,BS_LEFT, , ,BS_LEFTTEXT, ,',
                   ' , ,BS_CHECKBOX, ,',0

szSBut         db  'BS_FLAT,BS_NOTIFY,BS_MULTILINE, ,BS_BOTTOM,BS_TOP,',
                   'BS_RIGHT,BS_LEFT,BS_BITMAP,BS_ICON, , ,',
                   ' , , ,BS_DEFPUSHBUTTON,',0

szSEdi         db  'ES_SAVESEL,ES_SUNKEN,ES_NUMBER,ES_WANTRETURN,ES_READONLY,ES_OEMCONVERT,',
                   ' ,ES_NOHIDESEL,ES_AUTOHSCROLL,ES_AUTOVSCROLL,ES_PASSWORD,ES_LOWERCASE,',
                   'ES_UPPERCASE,ES_MULTILINE,ES_RIGHT,ES_CENTER,',0

szSCBS         db  ' ,CBS_LOWERCASE,CBS_UPPERCASE, ,CBS_DISABLENOSCROLL,CBS_NOINTEGRALHEIGHT,',
                   'CBS_HASSTRINGS,CBS_SORT,CBS_OEMCONVERT,CBS_AUTOHSCROLL,CBS_OWNERDRAWVARIABLE,',
                   'CBS_OWNERDRAWFIXED, , ,CBS_DROPDOWN, ,',0

szSLBS         db  ' ,LBS_NOSEL,LBS_NODATA,LBS_DISABLENOSCROLL,LBS_EXTENDEDSEL,LBS_WANTKEYBOARDINPUT,',
                   'LBS_MULTICOLUMN,LBS_NOINTEGRALHEIGHT,LBS_USETABSTOPS,LBS_HASSTRINGS,',
                   'LBS_OWNERDRAWVARIABLE,LBS_OWNERDRAWFIXED,LBS_MULTIPLESEL,LBS_NOREDRAW,',
                   'LBS_SORT,LBS_NOTIFY,',0

szSTVS         db  ' , , , , , , , , , ,TVS_SHOWSELALWAYS,TVS_DISABLEDRAGDROP,',
                   'TVS_EDITLABELS,TVS_LINESATROOT,TVS_HASLINES,TVS_HASBUTTONS,',0

szSLVS         db  'LVS_NOSORTHEADER,LVS_NOCOLUMNHEADER,LVS_NOSCROLL,LVS_OWNERDATA,',
                   'LVS_ALIGNLEFT,LVS_OWNERDRAWFIXED,LVS_EDITLABELS,LVS_AUTOARRANGE,',
                   'LVS_NOLABELWRAP,LVS_SHAREIMAGELISTS,LVS_SORTDESCENDING,LVS_SORTASCENDING,',
                   'LVS_SHOWSELALWAYS,LVS_SINGLESEL,LVS_SMALLICON,LVS_REPORT,',0

szSTBSTYLE     db  'TBSTYLE_TRANSPARENT,TBSTYLE_REGISTERDROP,TBSTYLE_CUSTOMERASE,TBSTYLE_LIST,',
                   'TBSTYLE_FLAT,TBSTYLE_ALTDRAG,TBSTYLE_WRAPABLE,TBSTYLE_TOOLTIPS,',
                   ' , , , ,',
                   ' ,TBSTYLE_GROUP,TBSTYLE_CHECK,TBSTYLE_SEP,',0

szSSBARS       db  ' , , , ,',
                   'SBARS_TOOLTIPS, , ,SBARS_SIZEGRIP,',
                   ' , , , ,',
                   ' , , , ,',0

szSSBS         db  ' , , , , , , , , ,',
                   ' , ,SBS_SIZEGRIP,',
                   'SBS_SIZEBOX,SBS_RIGHTALIGN,SBS_LEFTALIGN,SBS_VERT,',0

szSPBS         db  ' , , , , , ,',
                   ' , , , , , ,',
                   ' ,PBS_VERTICAL, ,PBS_SMOOTH,',0

szSTBS         db  ' , , , , , ,TBS_REVERSED,TBS_TOOLTIPS,TBS_NOTHUMB,',
                   'TBS_FIXEDLENGTH,TBS_ENABLESELRANGE,TBS_NOTICKS,',
                   'TBS_BOTH,TBS_TOP,TBS_VERT,TBS_AUTOTICKS,',0

szSUDS         db  ' , , , , , , ,UDS_HOTTRACK,UDS_NOTHOUSANDS,',
                   'UDS_HORZ,UDS_ARROWKEYS,UDS_AUTOBUDDY,',
                   'UDS_ALIGNLEFT,UDS_ALIGNRIGHT,UDS_SETBUDDYINT,UDS_WRAP,',0

szSTCS         db  'TCS_FOCUSNEVER,TCS_TOOLTIPS,TCS_OWNERDRAWFIXED,TCS_FOCUSONBUTTONDOWN,',
                   'TCS_RAGGEDRIGHT,TCS_FIXEDWIDTH,TCS_MULTILINE,TCS_BUTTONS,',
                   ' , ,TCS_FORCELABELLEFT,TCS_FORCEICONLEFT,',
                   'TCS_FLATBUTTONS,TCS_MULTISELECT,TCS_BOTTOM,TCS_SCROLLOPPOSITE,',0

szSMCS         db  ' , , , , , , , , ,',
                   ' , ,MCS_NOTODAY,',
                   'MCS_NOTODAYCIRCLE,MCS_WEEKNUMBERS,MCS_MULTISELECT,MCS_DAYSTATE,',0

szSDTS         db  ' , , , ,',
                   ' , , , ,',
                   ' , ,DTS_RIGHTALIGN,DTS_APPCANPARSE,',
                   ' ,DTS_LONGDATEFORMAT,DTS_SHOWNONE,DTS_UPDOWN,',0

szSANI         db  ' , , , , , , , , ,',
                   ' , , ,',
                   'ACS_TIMER,ACS_AUTOPLAY,ACS_TRANSPARENT,ACS_CENTER,',0

szSNA          db  ' , , , ,',
                   ' , , , ,',
                   ' , , , ,',
                   ' , , , ,',0

StyleArray     dd  szSDLG,szSSta,szSGrp,szSRad,szSChk,szSBut,szSEdi,szSEdi,
                   szSCBS,szSLBS,szSTVS,szSLVS,szSTBSTYLE,szSSBARS,szSSBS,
                   szSSBS,szSPBS,szSTBS,szSUDS,szSTCS,szSMCS,szSDTS,szSSta,
                   szSSta,szSSta,szSANI,szSNA,szSNA,szSNA,szSNA

szSS           db  'BITMAP     = 1110  WHITEFRAME = 1001',0dh,0ah
               db  'OWNERDRAW  = 1101  BLACKFRAME = 0111',0dh,0ah
               db  'NOWORDWRAP = 1100  WHITERECT  = 0110',0dh,0ah
               db  'SIMPLE     = 1011  GRAYRECT   = 0101',0dh,0ah
               db  'USERITEM   = 1010  ICON       = 0011',0
;               db  'ETCHEDHORZ = 10000 ETCHEDVERT = 10001',0dh,0ah
;               db  'ETCHEDFRAME= 10010',0

szBSG          db  'BS_OWNERDRAW        = 1011',0dh,0ah
               db  'BS_GROUPBOX         = 0111',0

szBSR          db  'BS_OWNERDRAW       = 1011',0dh,0ah
               db  'BS_AUTORADIOBUTTON = 1001',0dh,0ah
               db  'BS_RADIOBUTTON     = 0100',0

szBSC          db  'BS_OWNERDRAW    = 1011',0dh,0ah
               db  'BS_AUTO3STATE   = 0110',0dh,0ah
               db  'BS_3STATE       = 0101',0dh,0ah
               db  'BS_AUTOCHECKBOX = 0011',0dh,0ah
               db  'BS_CHECKBOX     = 0010',0

szBSB          db  'BS_OWNERDRAW = 1011',0

szCBS          db  'CBS_DROPDOWNLIST = 0011',0dh,0ah
               db  'CBS_DROPDOWN     = 0010',0

szLVS          db  'LVS_LIST = 0011',0dh,0ah
               db  'LVS_ICON = 0010',0

szTBSTYLE      db  'TBSTYLE_CHECKGROUP = 0110',0

szSBS          db  'SBS_HORZ                    = 0000',0dh,0ah
               db  'SBS_TOPALIGN                = 0010',0dh,0ah
               db  'SBS_SIZEBOXTOPLEFTALIGN     = 0010',0dh,0ah
               db  'SBS_SIZEBOXBOTTOMRIGHTALIGN = 0100',0dh,0ah
               db  'SBS_BOTTOMALIGN             = 0100',0

szTBS          db  'TBS_BOTTOM = 0000',0dh,0ah
               db  'TBS_HORZ   = 0000',0dh,0ah
               db  'TBS_RIGHT  = 0000',0

szTCS          db  'TCS_TABS         = 0000',0dh,0ah
               db  'TCS_SINGLELINE   = 0000',0dh,0ah
               db  'TCS_RIGHTJUSTIFY = 0000',0dh,0ah
               db  'TCS_RIGHT        = 0010',0

szDTS          db  'DTS_SHORTDATEFORMAT        = 0000',0dh,0ah
               db  'DTS_TIMEFORMAT             = 0009',0dh,0ah
               db  'DTS_SHORTDATECENTURYFORMAT = 000c',0

szTest         db  'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890',0

szDialog       db  '(ID),(Start ID),(Font),(Menu),(Name),Class,Caption,ExStyle,Style,',
                   'Left,Top,Width,Height,',0

szCtrl         db  '(ID),(Name),Class,Caption,ExStyle,Style,TabIndex,Left,Top,Width,Height,',0 ;^^^^^^^

;   Nice        dd 0          ; +432 688
Dialog         STRUCT
   ID          dd 2000
   StartID     dd 2001       ; +4
   lpFont      db 64 dup(?)  ; +8
   lpMenu      db 32 dup(?)  ; +72
   lpName      db 32 dup(?)  ; +104
   Class       db 32 dup(?)  ; +136
   lpCaption   db 512 dup(?) ; +168
   ExStyle     dd 0          ; +424 680
   Style       dd 0          ; +428 684
   Left        dd 55         ; +436 692
   Top         dd 65         ; +440 696
   Wth         dd 40         ; +444 700
   Hgt         dd 20         ; +448 704
   LeftOrg     dd 0          ; +336 592  -60
   TopOrg      dd 0          ; +340 596  -56
   WthOrg      dd 0          ; +344 600  -52
   HgtOrg      dd 0          ; +348 604  -48
   Chg         dd 0
   Code        db 'eefttttxseeee0000000000000000000' ; +452 708
   Border      dd 0          ; +484 740
   CntType     dd 0          ; +488 744
   Handle      dd 0          ; +492 748 + 4 = 752
Dialog         ENDS
Dlg            Dialog         <>

Controls       STRUCT
   ID          dd 2001
   lpName      db 32 dup(?)  ; +4
   Class       db 32 dup(?)  ; +36
   lpCaption   db 512 dup(?) ; +68
   ExStyle     dd 0          ; +324 580
   Style       dd 0          ; +328 584
   TabIndex    dd 5          ; +332 588
   Left        dd 50         ; +336 592  -60
   Top         dd 50         ; +340 596  -56
   Wth         dd 40         ; +344 600  -52
   Hgt         dd 20         ; +348 604  -48
   LeftOrg     dd 0          ; +336 592  -60
   TopOrg      dd 0          ; +340 596  -56
   WthOrg      dd 0          ; +344 600  -52
   HgtOrg      dd 0          ; +348 604  -48
   Chg         dd 0
   Code        db 'etttxseeeee000000000000000000000' ; +352 608 -16
   Border      dd 0          ; +384 640 -12
   CntType     dd 0          ; +388 644 -8
   Handle      dd 0          ; +392 648 + 4 = 652 + 224 == 364
Controls       ENDS
Ctrls          Controls       <>

.data?

CopyPaste      STRUCT
   ID          dd ?
   Class       db 32 dup(?)
   ExStyle     dd ?
   Style       dd ?
   Left        dd ?
   Top         dd ?
   Wth         dd ?
   Hgt         dd ?
   Border      dd ?
CopyPaste      ENDS
CopyP          CopyPaste      <?>

PasteOn        dd ?

DlgStart       dd ?
DlgClass       dd ?
DlgStyle       dd ?
DlgLeftOrg     dd ?
DlgCode        dd ?
DlgBorder      dd ?
DlgCntType     dd ?
DlgHandle      dd ?

CtrlsStart     dd ?
CtrlsStyle     dd ?
CtrlsLeft      dd ?
CtrlsLeftOrg   dd ?
CtrlsCode      dd ?
CtrlsBorder    dd ?
CtrlsCntType   dd ?
CtrlsHandle    dd ?

SavOff         dd ?
sEXStyle       dd ?
sStyle         dd ?
osvMaj         dd ?
osvMin         dd ?

hStatic        dd ?

osv            OSVERSIONINFO        <?>
tci            TC_ITEM              <?>
lf             LOGFONT              <?>
rect           RECT                 <?>
Prect          RECT                 <?>
Srect          RECT                 <?>
CBrect         RECT                 <?>
Savrect        RECT                 <?>
tbab           TBADDBITMAP          <?>
dis            DRAWITEMSTRUCT       <?>
icc            INITCOMMONCONTROLSEX <?>
nmhdr          NMHDR                <?>

.code

;________________________________________________________________________________
DllEntry PROC hInstance:DWORD, reason:DWORD, reserved1:DWORD

      .if reason == DLL_PROCESS_ATTACH  ; When the dll is loaded
           push     hInstance
            pop     hInst
            mov     eax, TRUE

      .elseif reason == DLL_PROCESS_DETACH

;---------- [Unregister our user classes] ----------
         INVOKE     UnregisterClass, offset WorkClass, hInst
         INVOKE     UnregisterClass, offset FormClass, hInst
         INVOKE     UnregisterClass, offset GroupClass, hInst
         INVOKE     UnregisterClass, offset SizeClassV, hInst
         INVOKE     UnregisterClass, offset SizeClassH, hInst
         INVOKE     UnregisterClass, offset MultiClass, hInst
;            xor     eax, eax
            mov     eax, TRUE
      .endif
         ret
DllEntry ENDP

;________________________________________________________________________________
CloseIt PROC     fromparent:DWORD

        push     fromparent
         pop     FromParent
         mov     sw1, 2244
      INVOKE     SendMessage, hWnd, WM_CLOSE, 0, 0

         ret
CloseIt Endp

;________________________________________________________________________________
FunctionEntry PROC  hwnd:DWORD, hedit, hretparent, hretform

        push     hwnd
         pop     hParentA
        push     hedit
         pop     hAsmREdit
      .if hedit
            mov     ecx, hedit
            mov     eax, [ecx]
            mov     hAsmEdit, eax
      .else
            and     hAsmEdit, 0
      .endif
        push     hretparent
         pop     hRetParent
        push     hretform
         pop     hRetForm
      .if hretform
            mov     ecx, hRetParent
            mov     eax, [ecx]
            mov     ParCode, eax
      .endif

      INVOKE     GetCommandLine
         mov     CommandLine, eax

;        call     InitCommonControls          ; Initialize the common ctrl lib
         mov     icc.dwSize, sizeof INITCOMMONCONTROLSEX
         mov     icc.dwICC, ICC_LISTVIEW_CLASSES or ICC_TREEVIEW_CLASSES or\
                 ICC_TAB_CLASSES or ICC_BAR_CLASSES or ICC_COOL_CLASSES or\
                 ICC_DATE_CLASSES or ICC_INTERNET_CLASSES
      INVOKE     InitCommonControlsEx, addr icc

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

      INVOKE     GetProcessHeap
         mov     hDefHeap, eax

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

NoGo:
      .if FromParent ;|| !hAsmEdit
         INVOKE     ExitProcess, MainExit
      .endif
         ret
FunctionEntry Endp

;=====================================================
; WndMain PROCEDURE
;=====================================================
WinMain PROC  uses ebx  hinst:DWORD, hPrevInst, CmdLine, CmdShow
LOCAL    wc:WNDCLASSEX
LOCAL    msg:MSG
LOCAL    Rmsg:MSG
LOCAL    hwnd:DWORD, Wth, Hgt, Temp

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

         mov     wc.style, CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW
         mov     wc.lpfnWndProc, offset WorkProc
         mov     wc.lpszClassName, offset WorkClass
         mov     wc.hbrBackground, COLOR_SCROLLBAR+1
      INVOKE     LoadCursor, 0, IDC_CROSS
         mov     wc.hCursor, eax
      INVOKE     RegisterClassEx, addr wc

; Need CS_PARENTDC for drawing moving frame
         mov     wc.style, CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW or CS_PARENTDC ;or CS_DBLCLKS
         mov     wc.lpfnWndProc, offset FormProc
         mov     wc.lpszClassName, offset FormClass
         mov     wc.hbrBackground, COLOR_BTNFACE+1
      INVOKE     LoadCursor, 0, IDC_CROSS
         mov     wc.hCursor, eax
      INVOKE     RegisterClassEx, addr wc

         mov     wc.style, CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW or CS_PARENTDC ;or CS_DBLCLKS
         mov     wc.lpfnWndProc, offset FormProc
         mov     wc.lpszClassName, offset GroupClass
         mov     wc.hbrBackground, COLOR_BTNFACE+1
      INVOKE     LoadCursor, 0, IDC_CROSS
         mov     wc.hCursor, eax
      INVOKE     RegisterClassEx, addr wc

;---------- [Register our sizing handle classes] ----------
         mov     wc.style, CS_GLOBALCLASS
         mov     wc.lpfnWndProc, offset SizeProc
         mov     wc.lpszClassName, offset SizeClassV
         mov     wc.hIcon, 0
         mov     wc.hIconSm, 0
      INVOKE     CreateSolidBrush, 0000ff00h
         mov     hBRG, eax
         mov     wc.hbrBackground, eax
      INVOKE     LoadCursor, hInst, 898
         mov     wc.hCursor, eax
         mov     h898, eax
      INVOKE     RegisterClassEx, addr wc

         mov     wc.lpfnWndProc, offset SizeProc
         mov     wc.lpszClassName, offset SizeClassH
      INVOKE     LoadCursor, hInst, 899
         mov     wc.hCursor, eax
         mov     h899, eax
      INVOKE     RegisterClassEx, addr wc

;---------- [Register our selection class] ----------
      INVOKE     CreateSolidBrush, 000000ffh
         mov     hBRR, eax
         mov     wc.hbrBackground, eax
         mov     wc.lpfnWndProc, offset MultiProc
         mov     wc.lpszClassName, offset MultiClass
      INVOKE     LoadCursor, 0, IDC_ARROW
         mov     wc.hCursor, eax
      INVOKE     RegisterClassEx, addr wc

      .if hAsmEdit
         INVOKE     GetWindowRect, hAsmEdit, addr rect
          MOVmd     Wth, rect.right
            mov     eax, rect.left
            sub     Wth, eax
          MOVmd     Hgt, rect.bottom
            mov     eax, rect.top
            sub     Hgt, eax
            mov     ebx, rect.left
            mov     eax, rect.top
      .endif

      .if hAsmEdit && Wth > 721 && Hgt > 542 ;529
            jmp     NoCenter
      .endif

.if hAsmEdit     ; hAsmEdit = from AsmEdit
      jmp     NoCenter
.endif

;---------- [Center the window] ----------
         mov     Wth, 721
         mov     Hgt, 542 ;529
      INVOKE     GetSystemMetrics, SM_CXSCREEN
         sub     eax, 721
         shr     eax, 1
        push     eax
      INVOKE     GetSystemMetrics, SM_CYSCREEN
         sub     eax, 529
         shr     eax, 1
         pop     ebx

NoCenter:
      .if hAsmEdit
            xor     eax, eax
            xor     ebx, ebx
      .endif
         mov     ResB, 6
         mov     ResT, 22

;         mov     ecx, WS_EX_TOOLWINDOW or WS_EX_CLIENTEDGE
;         mov     edx, WS_OVERLAPPEDWINDOW or WS_CLIPSIBLINGS
;      .if !hAsmEdit
;             or     ecx, WS_EX_APPWINDOW
;             or     edx, WS_CLIPCHILDREN
;      .endif


         mov     ecx, 0
         mov     edx, WS_CLIPSIBLINGS
      .if !hAsmEdit
             or     ecx, WS_EX_TOOLWINDOW or WS_EX_APPWINDOW or WS_EX_CLIENTEDGE
             or     edx, WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN
      .elseif hAsmEdit
            and     ResB, 0
            and     ResT, 0
             or     edx, WS_CHILD ;WS_POPUP
      .endif

      INVOKE     CreateWindowEx, ecx, addr ClassName, addr AppName, edx,\
                 ebx, eax, Wth, Hgt, hAsmEdit, NULL, hInst, NULL
         mov     hWnd, eax
      .if hAsmEdit                      ; Calling programs parent
            mov     ecx, hRetParent
            mov     [ecx], eax
         INVOKE     SetParent, hWnd, hAsmEdit
      .endif
      INVOKE     ShowWindow, hWnd, SW_SHOWNORMAL
      INVOKE     UpdateWindow, hWnd

;02-09
;      INVOKE     SetWindowPos, hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW

      .while TRUE
         INVOKE     GetMessage, addr msg, 0, 0, 0
         .break .if (!eax)

         INVOKE     IsDialogMessage, hTabSeL2, addr msg
            cmp     eax, 0
            jne     Pass

         INVOKE     TranslateMessage, addr msg
         .if hAsmREdit
               mov     ecx, hAsmREdit
               mov     eax, [ecx]
               mov     hAsmEdit, eax
         .endif
         INVOKE     GetFocus  ; Does not work with XP ?????????
         .if hAsmEdit && eax == hAsmEdit || hAsmEdit
            .if msg.wParam == (VK_CONTROL or VK_F4) && msg.lParam == 203f0001h
;                  mov     edx, 6008
;                  jmp     PostIt
            .endif
               mov     eax, msg.lParam
               shr     eax, 16
               and     eax, 000000ffh
               mov     ecx, msg.lParam
               and     ecx, 0f0000000h
            .if eax == 3fh && ecx == 0c0000000h || eax == 40h && ecx == 0c0000000h ||\
                eax == 41h && ecx == 0c0000000h
                 push     msg.wParam
               INVOKE     PeekMessage, addr msg, hWnd, VK_F5, VK_F7, PM_REMOVE
                  pop     ecx
               .if ecx == VK_F5
                  .if ParCode == 44
                        mov     edx, 6033
                  .else
                        mov     edx, 6024
                  .endif
               .elseif ecx == VK_F6
                  .if ParCode == 44
                        mov     edx, 6034
                  .else
                        mov     edx, 6025
                  .endif
               .else
                  .if ParCode == 44
                        mov     edx, 6035
                  .else
                        mov     edx, 6026
                  .endif
               .endif

PostIt:
;DSPValue hWnd, edx, 1, 't'
               INVOKE     PostMessage, hParentA, WM_COMMAND, edx, 0
                  jmp     Pass
            .endif
         .endif

         INVOKE     DispatchMessage, addr msg
Pass:
      .endw

         mov     eax, msg.wParam
         ret

WinMain ENDP

;=====================================================
; WndProc PROCEDURE
;=====================================================
WndProc PROC uses ebx edi esi hwnd:DWORD, wmsg, wparam, lparam
LOCAL    Erect:RECT
LOCAL    cm:COLORMAP
LOCAL    Wth:DWORD, Hgt, hReg
LOCAL    szBuff[256]:BYTE

      .if wmsg == WM_CREATE

         mov     osv.dwOSVersionInfoSize, sizeof OSVERSIONINFO
      INVOKE     GetVersionEx, addr osv
       MOVmd     osvMaj, osv.dwMajorVersion
       MOVmd     osvMin, osv.dwMinorVersion

;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

;---------- [Create the status bar window] ----------
         INVOKE     CreateWindowEx, 0, addr StatClass, 0,\
                    WS_CHILD or WS_BORDER or WS_VISIBLE or SBS_SIZEGRIP,\
                    0, 0, 0, 0, hwnd, 0, hInst, 0  
            mov     hWndStat, eax

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

         INVOKE     LoadMenu, hInst, addr ResourceMenu   
         INVOKE     GetSubMenu, eax, 0
            mov     hRMenu, eax

         INVOKE     LoadMenu, hInst, addr FileMenu  
         INVOKE     GetSubMenu, eax, 0
            mov     hFMenu, eax

         INVOKE     LoadMenu, hInst, 601  
         INVOKE     GetSubMenu, eax, 0
            mov     hSubMenu, eax

         INVOKE     GetStockObject, BLACK_BRUSH
            mov     hBlackBR, eax

         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontName
            mov     lf.lfHeight, -12
            mov     lf.lfWeight, 500
         INVOKE     CreateFontIndirect, addr lf
            mov     hFont, eax    ; Edit font

            mov     lf.lfHeight, -9
            mov     lf.lfWeight, 400
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontT, eax    ; Text font

         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontMS
            mov     lf.lfHeight, -12
            mov     lf.lfWeight, 500
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontL, eax   ; ListBox font

            mov     lf.lfHeight, -9
            mov     lf.lfWeight, 400
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontE, eax    ; Edit font

         INVOKE     CreateFontIndirect, addr lf
            mov     hFontIP, eax  ; IPAdress font

         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontMS
            mov     lf.lfHeight, -8
            mov     lf.lfWeight, 400
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontS, eax   ; SizeBox font

            mov     lf.lfHeight, 8
            mov     lf.lfWeight, 400
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontDlg, eax   ; Dialog font

         INVOKE     lstrcpy, addr lf.lfFaceName, addr FontSYS
            mov     lf.lfHeight, 0
            mov     lf.lfWeight, 0
         INVOKE     CreateFontIndirect, addr lf
            mov     hFontSYS, eax   ; System font
         INVOKE     lstrcpy, addr Dlg.lpFont, addr FontMSD

         INVOKE     LoadImage, hInst, 901, IMAGE_BITMAP, 12, 12, LR_DEFAULTCOLOR
            mov     hPat2, eax
         INVOKE     LoadImage, hInst, 902, IMAGE_BITMAP, 12, 12, LR_DEFAULTCOLOR
            mov     hPat3, eax
         INVOKE     LoadImage, hInst, 903, IMAGE_BITMAP, 12, 12, LR_DEFAULTCOLOR
            mov     hPat4, eax
         INVOKE     LoadImage, hInst, 904, IMAGE_BITMAP, 12, 12, LR_DEFAULTCOLOR
            mov     hPat6, eax

         INVOKE     LoadImage, hInst, 8809, IMAGE_BITMAP, 32, 32, LR_DEFAULTCOLOR   
            mov     hBmpR, eax
         INVOKE     LoadImage, hInst, 8810, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR     
            mov     hIcoR, eax

         INVOKE     CreateDialogParam, hInst, 4000, hwnd, offset TabCtlDlg, hwnd
            mov     hWndTab, eax

;---------- [Allocate memory from the default heap] ----------
         INVOKE     HeapAlloc, hDefHeap, 0, 500000 ;200000 ;100000
            mov     Defines, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 500000 ;200000 ;100000
            mov     DefinesDlg, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 500000 ;200000 ;100000
            mov     Equates, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 2000
            mov     Accelerator, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 2000
            mov     UnDoArray, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 2000
            mov     hString, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 2000
            mov     hError, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 51200
            mov     hBuff, eax
         INVOKE     RtlZeroMemory, Defines, 1024
         INVOKE     RtlZeroMemory, Equates, 1024
         INVOKE     RtlZeroMemory, Accelerator, 1024

         INVOKE     lstrcpy, addr szBuff, CommandLine
         .if byte ptr szBuff == '"'
            INVOKE     lstrcpy, addr szBuff, addr szBuff+1
            INVOKE     lstrlen, addr szBuff
            .while (eax)
               .if byte ptr szBuff[eax] == '\'
                  .break
               .endif
                  dec     eax
            .endw
               inc     eax
            INVOKE     lstrcpyn, addr PathName, addr szBuff, eax
            INVOKE     lstrcpy, addr RootPath, addr PathName

         .else
            INVOKE     GetCurrentDirectory, lengthof PathName, addr PathName
            INVOKE     GetCurrentDirectory, lengthof RootPath, addr RootPath

         .endif

         INVOKE     lstrcpy, addr szBuff, addr RootPath
         INVOKE     lstrcat, addr szBuff, addr szBackS
         INVOKE     lstrcat, addr szBuff, addr szGlobe
         INVOKE     LoadImage, 0, addr szBuff, IMAGE_ICON, 0, 0,
                    LR_LOADFROMFILE or LR_LOADMAP3DCOLORS
            mov     hIcon, eax

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

            mov     lpcbData, 255
         INVOKE     RegQueryValueEx, hReg, addr szResL, 0, addr lpType, addr szResPath, addr lpcbData
         .if !szResPath
            INVOKE     lstrcpy, addr szResPath, addr PathName
            INVOKE     lstrlen, addr szResPath
               mov     lpcbData, eax
            INVOKE     RegSetValueEx, hReg, addr szResL, 0, REG_SZ, addr szResPath, lpcbData
         .endif
         INVOKE     RegCloseKey, hReg

         INVOKE     FillBuffer, addr szFill, sizeof szFill, ' ', 1
            mov     vSpace, 2
            mov     hSpace, 2

      .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
            mov     sbParts, eax      ; Make part 1 1/4 the width
            add     eax, ecx
            mov     [sbParts+4], eax  ; and also part2, .. etc
            add     eax, ecx
            mov     [sbParts+8], eax
            mov     [sbParts+12], -1  ; The last part extends to the end
         INVOKE     SendMessage, hWndStat, SB_SETPARTS, 4, addr sbParts
         INVOKE     MoveWindow, hWndStat, 0, 0, 0, 0, TRUE

         INVOKE     GetWindowRect, hWndTab, addr rect
            mov     eax, rect.left
            sub     rect.right, eax
           push     rect.right
            mov     eax, lparam
            mov     edx, eax
            shr     edx, 16
            and     eax, 0ffffh
            sub     eax, rect.right
            mov     Wth, eax

         .if hAsmEdit
            INVOKE     GetWindowRect, hAsmEdit, addr Prect
               mov     eax, Prect.left
               add     eax, 3
               sub     Prect.right, eax
               mov     eax, Prect.right
               sub     eax, rect.right
               sub     eax, ResB ;6
               mov     Wth, eax
               mov     eax, Prect.top
               add     eax, 3
               sub     Prect.bottom, eax
             MOVmd     Hgt, Prect.bottom
               sub     Hgt, 21
            INVOKE     MoveWindow, hWnd, 0, 0, Prect.right, Prect.bottom, TRUE
            INVOKE     GetWindowRect, hWndStat, addr rect
               mov     ecx, rect.right
               sub     ecx, rect.left
               mov     edx, rect.bottom
               sub     edx, rect.top
            INVOKE     MoveWindow, hWndStat, 0, Hgt, ecx, edx, TRUE
               jmp     NoCheck
         .endif

         .if edx < 514 && !hAsmEdit         ; Height
            INVOKE     GetWindowRect, hWnd, addr rect
               mov     eax, rect.left
               sub     rect.right, eax
               mov     eax, rect.top
               add     eax, 542
               mov     rect.bottom, eax
            INVOKE     MoveWindow, hWnd, rect.left, rect.top, rect.right, 542, TRUE
               mov     edx, 514
               sub     edx, 20    ; Statusbar
               mov     Hgt, edx

         .elseif !hAsmEdit
               sub     edx, 20    ; Statusbar
               mov     Hgt, edx
         .endif

NoCheck:
         .if TabSelect == 2
            INVOKE     MoveWindow, hWork, 0, 0, Wth, Hgt, TRUE
            .if DlgOn
               INVOKE     GetWindowRect, hForm, addr Erect
                  mov     eax, Erect.left
                  sub     Erect.right, eax
                  mov     eax, Erect.top
                  sub     Erect.bottom, eax
               INVOKE     GetWindowRect, hwnd, addr rect
                  mov     eax, xOff
                  add     rect.left, eax
                  mov     eax, yOff
                  add     rect.top, eax
               INVOKE     MoveWindow, hForm, rect.left, rect.top, Erect.right, Erect.bottom, TRUE
               INVOKE     GetWindowRect, hForm, addr Erect
               INVOKE     GetWindowRect, hwnd, addr rect
                  mov     eax, Erect.left
                  sub     eax, rect.left
                  mov     xOff, eax
                  mov     eax, Erect.top
                  sub     eax, rect.top
                  mov     yOff, eax
            .endif

         .else
            INVOKE     MoveWindow, hREdit, 0, 0, Wth, Hgt, TRUE
         .endif

         INVOKE     GetWindowRect, hwnd, addr rect
            pop     ecx
            sub     rect.right, ecx
            mov     eax, ResB
            sub     rect.right, eax ;6
            mov     eax, ResT
            add     rect.top, eax ;22
         INVOKE     MoveWindow, hWndTab, Wth, 0, ecx, Hgt, TRUE

         .if hAsmEdit && hWndList
            .if Hgt < 479
                  sub     Hgt, 281 ;266
            .else
                  mov     Hgt, 198 ;213
            .endif
            INVOKE     MoveWindow, hWndList, 10, 239, 180, Hgt, TRUE ;213
         .endif

         INVOKE     ShowWindow, hWndTab, SW_SHOWDEFAULT
;         INVOKE     SetFocus, hMenuN
;INVOKE     SendMessage, hWndTab, WM_PAINT, 0, 0
INVOKE     UpdateWindow, hWndTab

      .elseif wmsg == WM_MOVE
         .if hAsmEdit
            INVOKE     GetWindowRect, hWnd, addr Prect
            .if Prect.top > 1000
                MOVmd     SavSelect, TabSelect
               .if TabSelect == 2
                     mov     sw2, 44
                  INVOKE     SendMessage, hTab, TCM_SETCURSEL, 0, 0
                     mov     nmhdr.code, TCN_SELCHANGE
                     lea     eax, nmhdr
                  INVOKE     SendMessage, hWndTab, WM_NOTIFY, 0, eax
                     jmp     Ret0
               .endif

            .elseif Prect.top < 1000
                  and     sw2, 0
               .if SavSelect == 2
                     mov     eax, ResB
                     add     FormX, eax ;6
                     mov     eax, ResT
                     add     FormY, eax ;22
               .endif
               INVOKE     SendMessage, hTab, TCM_SETCURSEL, SavSelect, 0
                  and     SavSelect, 0
                  mov     nmhdr.code, TCN_SELCHANGE
                  lea     eax, nmhdr
               INVOKE     SendMessage, hWndTab, WM_NOTIFY, 0, eax
            .endif
            INVOKE     GetClientRect, hAsmEdit, addr rect

         .else
            INVOKE     GetClientRect, hWnd, addr rect
         .endif
            mov     edx, rect.bottom
            shl     edx, 16
            mov     ecx, rect.right
            mov     dx, cx
         INVOKE     SendMessage, hWnd, WM_SIZE, 0, edx

      .elseif wmsg == WM_ACTIVATEAPP ;&& !hAsmEdit
         INVOKE     DefWindowProc, hWnd, WM_NCACTIVATE, wparam, 0 
            ret

      .elseif wmsg == WM_NCACTIVATE ;&& !hAsmEdit
            mov     eax, TRUE 
            ret

      .elseif wmsg == WM_COMMAND
            mov     eax, wparam
           cwde

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

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

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

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

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

         .endif

      .elseif wmsg == WM_CLOSE ;WM_DESTROY
         INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                    KEY_WRITE or KEY_READ, 0, addr hReg, addr lpdwDisp
         INVOKE     RegSetValueEx, hReg, addr szGridOn, 0, REG_DWORD, addr GridOn, 4
         INVOKE     RegSetValueEx, hReg, addr szSnapOn, 0, REG_DWORD, addr SnapOn, 4
         INVOKE     RegSetValueEx, hReg, addr szGrid, 0, REG_DWORD, addr Grid, 4
         INVOKE     lstrlen, addr szResPath
            mov     lpcbData, eax
         INVOKE     RegSetValueEx, hReg, addr szResL, 0, REG_SZ, addr szResPath, lpcbData
         INVOKE     RegCloseKey, hReg

;         .if hAsmEdit && sw1 == 2244       ; Return from AsmEdit close Tab
;             jmp     GetOut
;         .endif

         .if hImage
            INVOKE     SendMessage, hImage, WM_COMMAND, 405, 0
         .endif
         .if hOpt
            INVOKE     SendMessage, hOpt, WM_CLOSE, 0, 0
         .endif
         .if hSizePos
            INVOKE     SendMessage, hSizePos, WM_CLOSE, 0, 0
         .endif
         .if hStyle
            INVOKE     StyleProc, hStyle, WM_COMMAND, 5006, 0
         .endif
         .if hIC
            INVOKE     DestroyIcon, hIC
               and     hIC, 0
         .endif

         .if RsrcInfo
            INVOKE     HeapFree, hDefHeap, 0, RsrcInfo
            INVOKE     HeapFree, hDefHeap, 0, RsrcInfoGrp
            INVOKE     HeapFree, hDefHeap, 0, MemRsrc
               and     RsrcInfo, 0
         .endif
         .if pMap
            INVOKE     UnmapViewOfFile, pMap
            INVOKE     CloseHandle, hMap
               and     pMap, 0
         .endif

            and     Len, 0
            mov     Cnt, 8
         .while (Cnt)
               mov     ecx, Len
            .if dword ptr Defines[ecx*4] != 0
               INVOKE     HeapFree, hDefHeap, 0, Defines[ecx*4]
                  mov     ecx, Len
                  mov     dword ptr Defines[ecx*4], 0
            .endif
               inc     Len
               dec     Cnt
         .endw

            and     Len, 0
            mov     Cnt, 30
         .while (Cnt)
               mov     ecx, Len
            .if dword ptr hDlgMem+[ecx*4] != 0
               INVOKE     HeapFree, hDefHeap, 0, dword ptr hDlgMem+[ecx*4]
                  mov     ecx, Len
                  mov     dword ptr hDlgMem+[ecx*4], 0
            .endif
               inc     Len
               dec     Cnt
         .endw

            INVOKE     DestroyWindow, hWndTool
         .if hAsmEdit  ; Calling programs parent
            INVOKE     BringWindowToTop, hAsmEdit
            INVOKE     SetFocus, hAsmEdit
         .endif

            and     Len, 0
            mov     Cnt, 18 ;20
         .while (Cnt)
               mov     eax, Len
            INVOKE     DeleteObject, hFont[eax*4]
               inc     Len
               dec     Cnt
         .endw

         INVOKE     DestroyCursor, hIcoR
         INVOKE     DestroyIcon, hIcon

         INVOKE     DestroyWindow, hSizeL
         INVOKE     DestroyWindow, hSizeT
         INVOKE     DestroyWindow, hSizeR
         INVOKE     DestroyWindow, hSizeB
         INVOKE     DestroyWindow, hWndStatic

         INVOKE     UnregisterClass, offset SizeClassV, hInst
         INVOKE     UnregisterClass, offset SizeClassH, hInst
         INVOKE     UnregisterClass, offset MultiClass, hInst

         .if hBRD
            INVOKE     DeleteObject, hBRD
         .endif
         .if hBR
            INVOKE     DeleteObject, hBR
         .endif
         .if hBRP
            INVOKE     DeleteObject, hBRP
         .endif
         .if hBRG
            INVOKE     DeleteObject, hBRG
         .endif
         .if hBRR
            INVOKE     DeleteObject, hBRR
         .endif

            and     Cnt, 0
         .while AniCnt
               mov     ecx, Cnt
            .if hAniArray+[ecx*4]
               INVOKE     DestroyWindow, hAniArray+[ecx*4]
            .endif
               inc     Cnt
               dec     AniCnt
         .endw

            and     Cnt, 0
         .while (ArrayCnt)
               mov     eax, Cnt
            .if hArray+[eax*8+4]                ; Check for valid handle
                  mov     edx, hArray+[eax*8+4] ; Extract handle
                  mov     ebx, hArray+[eax*8]   ; Extract array count type
                  and     ebx, 0ffffh
               .if ebx == 7501
                  INVOKE     DestroyWindow, edx
               .endif
            .endif
               inc     Cnt
               dec     ArrayCnt
         .endw

         .if hAsmEdit  ; Calling programs parent
               and     InputType, 0
               and     hUnder, 0
               and     DlgOn, 0
               and     CtrlOn, 0
               and     CtrlNum, 0
               and     IDCnt, 0
               mov     Dlg.ID, 2000
               mov     Dlg.StartID, 2001
and     hWork, 0
and     hGrp, 0
and     CtrlType, 0

            .if hForm
;               INVOKE     DestroyWindow, hForm
                  mov     ecx, hRetForm
                  xor     eax, eax
                  mov     [ecx], eax
                  and     hForm, 0
            .endif
            INVOKE     RtlZeroMemory, addr hDlgMem, 124
            INVOKE     RtlZeroMemory, addr hArray, 65544
            INVOKE     RtlZeroMemory, addr GrpCnt, 2576
            INVOKE     RtlZeroMemory, addr hDlg, 6152

               mov     ecx, 3333
            .if FromParent || sw1 != 2244
                  xor     ecx, ecx
            .endif
;            INVOKE     SendMessage, hParentA, WM_COMMAND, 6004, ecx

GetOut:
               mov     ecx, hRetParent
               xor     eax, eax
               mov     [ecx], eax

         .endif
         INVOKE     DestroyWindow, hwnd

      .elseif wmsg == WM_DESTROY
         INVOKE     PostQuitMessage, NULL

      .else

DefWin:
         INVOKE     DefWindowProc, hwnd, wmsg, wparam, lparam
            ret
      .endif

Ret0:
         xor    eax, eax
         ret
WndProc ENDP

;=====================================================
; Work window PROCEDURE
;=====================================================
WorkProc PROC  hwnd:DWORD, wmsg, wparam, lparam
LOCAL    Frect:RECT
LOCAL    Wrect:RECT

      .if wmsg == WM_LBUTTONDOWN && !DlgOn
            mov     CtrlType, 7501
         .if !hSizeData
            INVOKE     CreateDialogParam, hInst, 4902, hWnd, offset SizeDataProc, 0
         .endif
         INVOKE     GetClientRect, hwnd, addr Prect

            xor     ecx, ecx
            mov     eax, lparam
            mov     cx, ax
            shr     eax, 16
            mov     rect.left, ecx
            mov     rect.top, eax
            and     rect.right, 0
            and     rect.bottom, 0
         INVOKE     LoadGrabbers, hwnd
            xor     eax, eax
            ret

      .elseif wmsg == WM_MOUSEMOVE && DlgOn && hUnder && hForm && !hDef
         INVOKE     SetFocus, hForm

      .elseif wmsg == WM_MOUSEMOVE && !DlgOn

;---------- [Display the cursor x - y position] ----------
            mov     eax, lparam          ; Get the y   
            shr     eax, 16              ; position in hiword(lparam)
         .if ax > 9000
               xor     eax, eax
         .endif
            mov     PosY, eax
         INVOKE     BaseAscii, eax, addr mmsgy, 4, 10, 1, 1, 0
            mov     eax, lparam          ; Get the x
            cwde                         ; position in loword(lparam)
         .if ax > 9000
                xor     eax, eax
         .endif
            mov     PosX, eax
         INVOKE     BaseAscii, eax, addr mmsgx, 4, 10, 1, 0, 0
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 1, addr mmsg

         .if wparam != MK_LBUTTON
           .if hSizeData
               INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
                  and     hSizeData, 0
           .endif

            INVOKE     GetFocus
           .if eax != hForm && !hDef
               INVOKE     SetFocus, hwnd
           .endif
            jmp     Ret0

         .elseif wparam == MK_LBUTTON
            .if InputType == 7501 && !hUnder
            .else
                  jmp     Ret0
            .endif
            .if !hSizeData
               INVOKE     CreateDialogParam, hInst, 4902, hWnd, offset SizeDataProc, 0
            .endif
            INVOKE     SetCapture, hwnd
               xor     ecx, ecx
               mov     edx, lparam
               mov     cx, dx
               shr     edx, 16
            .if ecx > 7fffh
                  mov     ecx, 0
            .endif
            .if ecx < rect.left 
                  inc     ecx
            .endif
            .if edx > 7fffh
                  mov     edx, 0
            .endif
            .if edx < rect.top 
                  inc     edx
            .endif

            .if rect.left == ecx || rect.top == edx

            .else
               .if ecx > Prect.right
                     mov     ecx, Prect.right
               .endif
               .if edx > Prect.bottom
                     mov     edx, Prect.bottom
               .endif

                  mov     rect.right, ecx
                  mov     rect.bottom, edx
               INVOKE     PosProc, hwnd, 0, 0, 6
   INVOKE     UpdateWindow, hwnd

               INVOKE     CopyRect, addr Wrect, addr rect
                  mov     eax, Wrect.right
               .if eax < Wrect.left
                     mov     ecx, Wrect.left
                     mov     Wrect.left, eax
                     mov     Wrect.right, ecx
               .endif
                  mov     eax, Wrect.bottom
               .if eax < Wrect.top
                     mov     ecx, Wrect.top
                     mov     Wrect.top, eax
                     mov     Wrect.bottom, ecx
               .endif

                  mov     ecx, Wrect.right
                  sub     ecx, Wrect.left
                  mov     edx, Wrect.bottom
                  sub     edx, Wrect.top
               INVOKE     MoveWindow, hWndStatic, Wrect.left, Wrect.top, ecx, edx, 1
                  mov     CtrlOn, 1
           .endif
         .endif

      .elseif wmsg == WM_LBUTTONUP && DlgOn && hUnder && hForm
         INVOKE     SetFocus, hForm

      .elseif wmsg == WM_LBUTTONUP && !DlgOn
         INVOKE     MoveWindow, hWndStatic, 0, 0, 0, 0, 1
         .if hSizeData
            INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
               and     hSizeData, 0
         .endif
         INVOKE     ReleaseCapture
         .if rect.right && TabSelect == 2 && CtrlOn
         .else
               jmp     Ret0
         .endif
            mov     eax, rect.right
         .if eax < rect.left
               dec     eax
               mov     ecx, rect.left
               mov     rect.left, eax
               mov     rect.right, ecx
         .endif
            mov     eax, rect.bottom
         .if eax < rect.top
               dec     eax
               mov     ecx, rect.top
               mov     rect.top, eax
               mov     rect.bottom, ecx
         .endif

            mov     ecx, rect.right
            sub     ecx, rect.left
            mov     edx, rect.bottom
            sub     edx, rect.top
         .if ecx < 20 || edx < 20
               jmp     Ret0
         .endif
         .if InputType == 7501
            .if hUnder
                  jmp     Ret0
            .endif
              push     ecx
              push     edx

;---------- [Create the form control] ----------
            INVOKE     GetWindowRect, hWnd, addr Prect
               mov     eax, ResB 
               add     Prect.left, eax ;6
               mov     eax, ResT 
               add     Prect.top, eax ;22
               mov     eax, Prect.left
               add     rect.left, eax
               mov     eax, Prect.top
               add     rect.top, eax

             MOVmd     hUnder, hwnd
               pop     rect.bottom
               pop     rect.right
              push     Prect.left
              push     Prect.top
            INVOKE     CreateControls, hwnd, 0

;---------- [Create the grabber controls] ----------
            INVOKE     LoadGrabbers, hForm
            INVOKE     GetSizes, hCtrl
            INVOKE     GetWindowRect, hForm, addr Frect
               pop     Prect.top
               pop     Prect.left
               mov     eax, Frect.left
               sub     eax, Prect.left
               mov     xOff, eax
               mov     FormX, eax
               mov     eax, Frect.top
               sub     eax, Prect.top
               mov     yOff, eax
               mov     FormY, eax

            INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, 7501, FALSE
             MOVmd     hCtrl, hForm
             MOVmd     CtrlType, InputType
               and     InputType, 0
               mov     DlgOn, 1
            INVOKE     GetClientRect, hForm, addr Srect
            INVOKE     MoveGrabbers, 2, 0
             MOVmd     CtrlID, Dlg.StartID
;NOTE $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    MOVmd     hSMove, hForm
    MOVmd     CtrlHnd, hForm
      mov     SavCtrl, 7501
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
         .endif

      .else
         INVOKE     DefWindowProc, hwnd, wmsg, wparam, lparam
            ret
      .endif

Ret0:
         xor     eax, eax
         ret
WorkProc ENDP

;=====================================================
; Align - Size - Shift - Space mult selection PROCEDURE
;=====================================================
ASMC PROC uses ebx wparam:DWORD, lparam, sL, sU, sR, sD, swth, shgt, vS, hS
LOCAL    hChild:DWORD, Incr, Cnt1, Len1, Secx, sWth, sHgt, TabIndex

;---------- [Position or size the multiple selections] ----------
         and     sPos, 0
         and     Len, 0
         and     sWth, 0
         and     sHgt, 0
         and     Incr, 0
         and     TabIndex, 0

;---------- [Get the handle of the selected control in the selection array] ----------
       MOVmd     Cnt, MultiCnt
      .while (Cnt)
            mov     eax, Len
         .if hMultiArray[eax+4]
               mov     ecx, hMultiArray[eax+4]
               and     Len1, 0
             MOVmd     Cnt1, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt1
;---------- [Get the control type and count from the control array] ----------
GetMore:
            .while (Cnt1)                          ; Find valid control handles in the array
                  mov     eax, Len1
               .if hArray+[eax*8+4] == ecx         ; Check for valid handle
                     mov     hChild, ecx
                     mov     ebx, hArray+[eax*8]   ; Extract array count
                     mov     eax, ebx
                     and     eax, 0ffffh
                     mov     CtrlType, eax
                     shr     ebx, 16
                     inc     Len1
                     dec     Cnt1
                  .if eax == 7501 || eax == 7503
                        jmp     GetMore
                  .endif
                  .break
               .endif
                  inc     Len1
                  dec     Cnt1
            .endw
            .if !Cnt1
                  jmp     AllDone
            .endif

              push     ebx
            INVOKE     GetParent, hChild
            .if eax != hForm
               .if !xGrp || !yGrp || eax != hSavGrp
                     mov     hSavGrp, eax
                  INVOKE     MouseMUD, hChild, WM_LBUTTONDOWN, 0, 5678
               .endif
            .endif
               pop     ebx

;---------- [Extract position and size from the controls structure] ----------
              push     ebx
               mov     dis.itemID, 7 ;6 ^^^^^^^^^^^^^

;---------- [Get offset in the structure array] ----------
            INVOKE     GetOffset, 1
               pop     ebx
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
              imul     edx, 4
               add     ecx, edx
               mov     Secx, ecx
               inc     TabIndex
mov     dword ptr [ecx+32], 1  ; Change

            .if wparam != 2016
                MOVmd     Srect.left, dword ptr [ecx]      ; = Left
                MOVmd     Srect.top, dword ptr [ecx+4]     ; = Top
                MOVmd     Srect.right, dword ptr [ecx+8]   ; = Right
                MOVmd     Srect.bottom, dword ptr [ecx+12] ; = Bottom
                  mov     eax, Incr
                 imul     eax, 20
                  mov     edx, UnDoArray
                MOVmd     [edx+eax+4], dword ptr [ecx]
                MOVmd     [edx+eax+8], dword ptr [ecx+4]
                MOVmd     [edx+eax+12], dword ptr [ecx+8]
                MOVmd     [edx+eax+16], dword ptr [ecx+12]
            .else
                  mov     eax, Incr
                 imul     eax, 20
                  mov     edx, UnDoArray
                MOVmd     Srect.left, [edx+eax+4]      ; = Left
                MOVmd     Srect.top, [edx+eax+8]       ; = Top
                MOVmd     Srect.right, [edx+eax+12]    ; = Right
                MOVmd     Srect.bottom, [edx+eax+16]   ; = Bottom
            .endif

            .if wparam == 2001         ; Align left
               .if !sPos
                   MOVmd     sPos, Srect.left
               .endif
                MOVmd     Srect.left, sPos
            .elseif wparam == 2002     ; Align top
               .if !sPos
                   MOVmd     sPos, Srect.top
               .endif
                MOVmd     Srect.top, sPos
            .elseif wparam == 2003     ; Align right
               .if !sPos
                   MOVmd     sPos, Srect.left
                   MOVmd     sWth, Srect.right
               .endif
                MOVmd     Srect.left, sPos
                  mov     eax, Srect.right
                  mov     ecx, sWth
               .if eax < sWth
                     sub     ecx, eax
                     add     Srect.left, ecx
               .else
                     sub     eax, ecx
                     sub     Srect.left, eax
               .endif
            .elseif wparam == 2004     ; Align bottom
               .if !sPos
                   MOVmd     sPos, Srect.top
                   MOVmd     sHgt, Srect.bottom
               .endif
                MOVmd     Srect.top, sPos
                  mov     eax, Srect.bottom
                  mov     ecx, sHgt
               .if eax < sHgt
                     sub     ecx, eax
                     add     Srect.top, ecx
               .else
                     sub     eax, ecx
                     sub     Srect.top, eax
               .endif
            .elseif wparam == 2005     ; Shift left
               .if !sPos
                     mov     eax, sL
                     mov     sPos, eax
               .endif
                  mov     eax, sPos
                  sub     Srect.left, eax
            .elseif wparam == 2006     ; Shift up
               .if !sPos
                     mov     eax, sU
                     mov     sPos, eax
               .endif
                  mov     eax, sPos
                  sub     Srect.top, eax
            .elseif wparam == 2007     ; Shift right
               .if !sPos
                     mov     eax, sR
                     mov     sPos, eax
               .endif
                  mov     eax, sPos
                  add     Srect.left, eax
            .elseif wparam == 2008     ; Shift down
               .if !sPos
                     mov     eax, sD
                     mov     sPos, eax
               .endif
                  mov     eax, sPos
                  add     Srect.top, eax
            .elseif wparam == 2009     ; Set width
               .if !sPos
                     mov     sPos, 1
                   MOVmd     sWth, Srect.right
               .endif
                MOVmd     Srect.right, sWth
            .elseif wparam == 2010     ; Set height
               .if !sPos
                     mov     sPos, 1
                   MOVmd     sHgt, Srect.bottom
               .endif
                MOVmd     Srect.bottom, sHgt
            .elseif wparam == 2011     ; Set both
               .if !sPos
                     mov     sPos, 1
                   MOVmd     sWth, Srect.right
                   MOVmd     sHgt, Srect.bottom
               .endif
                MOVmd     Srect.right, sWth
                MOVmd     Srect.bottom, sHgt
            .elseif wparam == 2012     ; Set user size
               .if !sPos
                     mov     sPos, 1
                   MOVmd     sWth, Srect.right
                   MOVmd     sHgt, Srect.bottom
                     mov     eax, swth
                  .if eax > 5
                        mov     sWth, eax
                  .else
                        and     sPos, 0
                  .endif
                     mov     eax, shgt
                  .if eax > 5
                        mov     sHgt, eax
                  .else
                        and     sPos, 0
                  .endif
               .endif
                MOVmd     Srect.right, sWth
                MOVmd     Srect.bottom, sHgt
            .elseif wparam == 2013     ; Set vertical space
               .if !sPos && !sHgt
;                     and     sHgt, 0
                     mov     eax, vS
                  .if eax
                        mov     sPos, eax
                  .else
                        mov     sPos, 0 ;2
                  .endif
               .endif
               .if sHgt
                   MOVmd     Srect.top, sHgt
                     mov     eax, sPos
                     add     Srect.top, eax
               .endif
                  mov     eax, Srect.top
                  add     eax, Srect.bottom
                  mov     sHgt, eax
            .elseif wparam == 2014     ; Set horizontal space
               .if !sPos && !sWth
;                     and     sWth, 0
                     mov     eax, hS
                  .if eax
                        mov     sPos, eax
                  .else
                        mov     sPos, 0 ;2
                  .endif
               .endif
               .if sWth
                   MOVmd     Srect.left, sWth
                     mov     eax, sPos
                     add     Srect.left, eax
               .endif
                  mov     eax, Srect.left
                  add     eax, Srect.right
                  mov     sWth, eax

            .elseif wparam == 2015     ; Renumber tab indexs
                  mov     ecx, Secx
                MOVmd     dword ptr [ecx-4], TabIndex
                  jmp     Pass

            .elseif wparam == 2016     ; UnDo last change

            .endif

            INVOKE     GetParent, hChild
            .if eax != hForm
                  mov     eax, xGrp
                  add     eax, SizeB
                  sub     Srect.left, eax
                  mov     eax, yGrp
                  add     eax, SizeT
                  sub     Srect.top, eax
            .endif

;---------- [Check to see if the control is within bounds of its parent] ----------
            INVOKE     GetParent, hChild
               mov     ecx, eax
            INVOKE     GetClientRect, ecx, addr Prect
               mov     eax, Srect.left
               add     eax, Srect.right
               mov     ebx, Srect.top
               add     ebx, Srect.bottom
            .if Srect.left > 7fffh || Srect.top > 7fffh ||\
                eax > Prect.right || ebx > Prect.bottom
                  jmp     Pass
            .endif

            INVOKE     MoveWindow, hChild, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
            INVOKE     GetParent, hChild
            .if eax != hForm
                  mov     eax, xGrp
                  add     eax, SizeB
                  add     Srect.left, eax
                  mov     eax, yGrp
                  add     eax, SizeT
                  add     Srect.top, eax
               INVOKE     RedrawWindow, hGrp, 0, 0,\
                          RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN
            .endif
               mov     ecx, Secx
             MOVmd     dword ptr [ecx], Srect.left       ; = Left
             MOVmd     dword ptr [ecx+4], Srect.top      ; = Top
             MOVmd     dword ptr [ecx+8], Srect.right    ; = Right
             MOVmd     dword ptr [ecx+12], Srect.bottom  ; = Bottom
         .endif

Pass:
            add     Len, 8
            inc     Incr
            dec     Cnt
      .endw

AllDone:
         xor     eax, eax
         ret
ASMC ENDP

;=====================================================
; Move or size the control from the keyboard PROCEDURE
;=====================================================
MoveSize PROC uses ebx wparam, lparam
LOCAL    Crect:RECT
LOCAL    Wrect:RECT
LOCAL    Cnt1:DWORD, Len1, SavC, SavT

         mov     eax, lparam
         and     eax, 0f0000000h
         mov     lparam, eax

      .if MultiCnt
         .if wparam == 76
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2001     ; Align left
            .endif
         .elseif wparam == 84
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2002     ; Align top
            .endif
         .elseif wparam == 82
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2003     ; Align right
            .endif
         .elseif wparam == 66
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2004     ; Align bottom
            .endif
         .elseif wparam == 37
            .if lparam != 20000000h && lparam != 60000000h
                  mov     wparam, 2005     ; Shift left
            .endif
         .elseif wparam == 38
            .if lparam != 20000000h && lparam != 60000000h
                  mov     wparam, 2006     ; Shift up
            .endif
         .elseif wparam == 39
            .if lparam != 20000000h && lparam != 60000000h
                  mov     wparam, 2007     ; Shift right
            .endif
         .elseif wparam == 40
            .if lparam != 20000000h && lparam != 60000000h
                  mov     wparam, 2008     ; Shift down
            .endif
         .elseif wparam == 87
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2009     ; Set width
            .endif
         .elseif wparam == 72
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2010     ; Set height
            .endif
         .elseif wparam == 83
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2011     ; Same size
            .endif
         .elseif wparam == 89
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2013     ; Vertical space
            .endif
         .elseif wparam == 88
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2014     ; Horizontal space
            .endif
         .elseif wparam == 78
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2015     ; Renumber tab index
            .endif
         .elseif wparam == 85
            .if lparam == 20000000h || lparam == 60000000h
                  mov     wparam, 2016     ; Undo
            .endif
         .else
               jmp     GetOut
         .endif
;            mov     ecx, 3
;            mov     edx, 3
;         .if vSpace
               mov     ecx, vSpace
;         .endif
;         .if hSpace
               mov     edx, hSpace
;         .endif
         .if !DblOn
            INVOKE     ASMC, wparam, lparam, 1, 1, 1, 1, 0, 0, vSpace, hSpace
         .else
            INVOKE     ASMC, wparam, lparam, 2, 2, 2, 2, 0, 0, vSpace, hSpace
         .endif
            jmp     GetOut
      .endif

       MOVmd     SavC, hCtrl
       MOVmd     SavT, CtrlType
       MOVmd     hCtrl, CtrlHnd ;hSMove
       MOVmd     CtrlType, SavCtrl
         mov     Cnt1, 4
      .if CtrlType != 7501
            mov     Len1, 7 ;6^^^^^^^^^^^^^
      .else
            mov     Len1, 10
      .endif

         mov     dis.itemID, 0
      INVOKE     GetOffset, 0
        imul     ebx, eax
         add     ecx, ebx
      .if CtrlType == 7501
         add     ecx, DlgLeftOrg
      .else
         add     ecx, CtrlsLeftOrg
      .endif
         add     ecx, 16
         mov     byte ptr[ecx], 2  ; Change


.if CtrlType == 7503
   INVOKE     GetWindow, hCtrl, GW_CHILD
      mov     hCtrl, eax
.endif

         xor     eax, eax
      .while (Cnt1)
          MOVmd     dis.itemID, Len1
;---------- [Get offset in the structure array] ----------
           push     eax
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            pop     eax
          MOVmd     Srect[eax*4], dword ptr [ecx+edx*4]
            inc     eax
            inc     Len1
            dec     Cnt1
      .endw

MOVmd     hCtrl, CtrlHnd

;.if CtrlType == 7501
;            INVOKE     GetWindowRect, hCtrl, addr Crect
;               mov     eax, Crect.right
;               sub     eax, Crect.left
;               mov     Srect.right, eax
;               mov     eax, Crect.bottom
;               sub     eax, Crect.top
;               mov     Srect.bottom, eax
;.endif

;-------- [Single selection] --------
;Left arrow   Move left
;UP arrow     Move up
;Right arrow  Move right
;Down arrow   Move down

;(Ctrl+the above will double space)

;Alt+Left arrow   Decrease width
;Alt+UP arrow     Decrease height
;Alt+Right arrow  Increase width
;Alt+Down arrow   Increase height

      .if wparam == 37
            dec     Srect.left
         .if DblOn && lparam != 20000000h && lparam != 60000000h
            dec     Srect.left
         .endif
         .if lparam == 20000000h || lparam == 60000000h
               inc     Srect.left
               dec     Srect.right
         .endif
      .elseif wparam == 38
            dec     Srect.top
         .if DblOn && lparam != 20000000h && lparam != 60000000h
            dec     Srect.top
         .endif
         .if lparam == 20000000h || lparam == 60000000h
               inc     Srect.top
               dec     Srect.bottom
         .endif
      .elseif wparam == 39
            inc     Srect.left
         .if DblOn && lparam != 20000000h && lparam != 60000000h
            inc     Srect.left
         .endif
         .if lparam == 20000000h || lparam == 60000000h
               dec     Srect.left
               inc     Srect.right
         .endif
      .elseif wparam == 40
            inc     Srect.top
         .if DblOn && lparam != 20000000h && lparam != 60000000h
            inc     Srect.top
         .endif
         .if lparam == 20000000h || lparam == 60000000h
               dec     Srect.top
               inc     Srect.bottom
         .endif
      .else
            jmp     Restore
      .endif

      INVOKE     GetParent, hCtrl
      .if !eax
         INVOKE     GetWindowRect, hWnd, addr Crect
            mov     eax, Crect.left
            add     eax, ResB
            add     Srect.left, eax
            mov     eax, Crect.top
            add     eax, ResT
            add     Srect.top, eax
         INVOKE     MoveWindow, hCtrl, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
         INVOKE     GetClientRect, hCtrl, addr Srect
         INVOKE     MoveGrabbers, 2, 1
            jmp     Restore
      .endif

      .if eax != hForm && CtrlType != 7503
         .if !xGrp || !yGrp || eax != hSavGrp
               mov     hSavGrp, eax
            INVOKE     CopyRect, addr Wrect, addr Srect
            INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 5678
            INVOKE     CopyRect, addr Srect, addr Wrect
         .endif
            mov     eax, xGrp
            add     eax, SizeB
            sub     Srect.left, eax
            mov     eax, yGrp
            add     eax, SizeT
            sub     Srect.top, eax
      .endif

;---------- [Check to see if the control is within bounds of its parent] ----------
      INVOKE     GetParent, hCtrl
         mov     ecx, eax
      INVOKE     GetClientRect, ecx, addr Prect
         mov     eax, Srect.left
         add     eax, Srect.right
         mov     ebx, Srect.top
         add     ebx, Srect.bottom
      .if Srect.left > 7fffh || Srect.top > 7fffh ||\
          eax > Prect.right || ebx > Prect.bottom
         .if Srect.left > 7fffh
               mov     Srect.left, 0
         .elseif Srect.top > 7fffh
               mov     Srect.top, 0
         .endif
            jmp     Restore
      .endif

      INVOKE     MoveWindow, hCtrl, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE

      .if CtrlType == 7503
            xor     eax, eax
            mov     edx, hGrp
            mov     ecx, GrpCnt ;32
         .while (ecx)     ; Find handle of Groupbox parent in the array
            .if hGrpArray[eax] == edx
                  mov     ecx, hGrpArray[eax+4]  ; Groupbox handle
               .break  
            .endif
               add     eax, 8
               dec     ecx
         .endw
         INVOKE     MoveWindow, ecx, 0, 0, Srect.right, Srect.bottom, TRUE
           push     hGrpOn
           call     ChkChildren
            pop     hGrpOn
      .endif

      INVOKE     GetParent, hCtrl
      .if eax != hForm && CtrlType != 7503
            mov     eax, xGrp
            add     eax, SizeB
            add     Srect.left, eax
            mov     eax, yGrp
            add     eax, SizeT
            add     Srect.top, eax
         INVOKE     RedrawWindow, hGrp, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN
      .endif

      INVOKE     MoveGrabbers, 5, 0

Restore:
       MOVmd     hCtrl, SavC
       MOVmd     CtrlType, SavT

GetOut:
         xor     eax, eax
         ret
MoveSize ENDP

;=====================================================
; Clear multiple selections PROCEDURE
;=====================================================
ClearMult PROC

      .if MultiCnt
            and     Len, 0
         .while (MultiCnt)
               mov     eax, Len
            .if hMultiArray[eax]
                  mov     ecx, hMultiArray[eax]
                  mov     hMultiArray[eax], 0
                  mov     hMultiArray[eax+4], 0
               INVOKE     DestroyWindow, ecx
            .endif
               add     Len, 8
               dec     MultiCnt
         .endw
      .endif
         and     hSMove, 0
         ret
ClearMult ENDP

;=====================================================
; Form window PROCEDURE
;=====================================================
FormProc PROC  uses ebx hwnd:DWORD, wmsg, wparam, lparam
LOCAL    Crect:RECT
LOCAL    Erect:RECT
LOCAL    TBrect:RECT
LOCAL    szBuff[100]:BYTE

      .if wmsg == WM_KEYDOWN || wmsg == WM_SYSKEYDOWN
         .if wmsg == WM_KEYDOWN && wparam == 16  ; Shift
               mov     RevOn, 1                  ; Go back
         .endif
         .if wparam == 9                         ; Tab
              Call     ClearMult
               mov     eax, ArrayCnt
               dec     eax
            .if !RevOn && eax <= IndexCnt || RevOn && !IndexCnt
               .if !RevOn
                     and     IndexCnt, 0
               .else
                     and     IndexCnt, 0
                     mov     sw6, 22
                     jmp     GetLimit
               .endif
            .endif
            .if !RevOn
                  inc     IndexCnt
            .else
               .if IndexCnt
                     dec     IndexCnt
               .else
                     and     IndexCnt, 0
                     mov     sw6, 22
                     jmp     GetLimit
               .endif
            .endif

GetLimit:
               and     Len, 0
             MOVmd     Cnt, ArrayCnt
inc     Cnt

GetMore:
            .while (Cnt)                         ; Find handle of active control in the array
                  mov     eax, Len
               .if hArray+[eax*8+4]              ; Check for valid handle
                   MOVmd     hCtrl, hArray+[eax*8+4]
                     mov     ebx, hArray+[eax*8] ; Extract array count
                     mov     eax, ebx
                     and     eax, 0ffffh
                     mov     CtrlType, eax
                     shr     ebx, 16
                  .if eax == 7501
                        inc     Len
                        dec     Cnt
                        jmp     GetMore
                  .endif

;---------- [Get offset in the structure array] ----------
                    push     ebx
                     mov     dis.itemID, 6 ;5^^^^^^^^^^^^^^
                  INVOKE     GetOffset, 1
                     pop     ebx
                     mov     StrSize, eax
                    imul     ebx, StrSize
                     add     ecx, ebx
                     mov     eax, IndexCnt
                     mov     ebx, dword ptr[ecx+edx*4+60]
                  .if ebx == hForm
                     .if sw6 == 22
                        .if eax < dword ptr[ecx+edx*4]
                              mov     eax, dword ptr[ecx+edx*4]
                              mov     IndexCnt, eax
                        .endif
                           jmp     ByPass
                     .endif
                     .if eax == dword ptr[ecx+edx*4]
                        .if CtrlType == 7503
                           INVOKE     GetParent, hCtrl
                              mov     hGrp, eax
                              mov     hCtrl, eax
                        .endif
                        INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 6969 ;0
                        INVOKE     MouseMUD, hCtrl, WM_MOUSEMOVE, MK_LBUTTON, 6969
                        INVOKE     MouseMUD, hCtrl, WM_LBUTTONUP, 0, 0
                           mov     eax, 1
                           ret
                     .endif
                  .endif
               .endif

ByPass:
                  inc     Len
                  dec     Cnt
            .endw

            .if !RevOn
                  and     IndexCnt, 0
            .else
               .if sw6 == 22
                     and     sw6, 0
                     jmp     GetLimit
               .else
                     and     IndexCnt, 0
               .endif
            .endif
               mov     eax, 1
               ret
         .endif

         .if hSMove
            .if wmsg == WM_KEYDOWN && wparam == 17
                  mov     DblOn, 1
            .endif
            .if wparam > 36 && wparam < 41 || wparam == 76 ||\
                wparam == 84 || wparam == 82 || wparam == 66 ||\
                wparam == 83 || wparam == 89 || wparam == 88 ||\
                wparam == 87 || wparam == 72 || wparam == 85 ||\
                wparam == 78
               INVOKE     MoveSize, wparam, lparam
            .endif
         .endif
            mov     eax, 1
            ret

      .elseif wmsg == WM_KEYUP && wparam == 16
            and     RevOn, 0

      .elseif wmsg == WM_KEYUP && wparam == 17
            and     DblOn, 0
      .endif

         mov     eax, hwnd
      .if eax != hForm && hForm && wmsg == WM_LBUTTONDOWN ;WM_MOUSEMOVE
            mov     hGrp, eax
      .endif

      .if wmsg == WM_LBUTTONUP && !(wparam & MK_CONTROL) && MultiCnt
           Call     ClearMult
      .endif

         mov     eax, hwnd
      .if GroupOn && eax == hGrp
         .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE

mov     CtrlType, 7503
            INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
               mov     eax, 1
               ret
         .endif
      .endif

      .if wmsg == WM_RBUTTONDOWN && wparam != MK_LBUTTON or MK_RBUTTON
         INVOKE     EnableMenuItem, hRMenu, IDM_COPY, MF_GRAYED
         INVOKE     EnableMenuItem, hRMenu, IDM_PASTE, MF_ENABLED
            jmp     PopUp

      .elseif wmsg == WM_CHAR ||\
              wmsg == WM_KEYUP ||\
              wmsg == WM_KEYDOWN ||\
              wmsg == WM_CLOSE
            mov     eax, 1
            ret

      .elseif wmsg == WM_NCMOUSEMOVE
         .if hSizeData
            INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
               and     hSizeData, 0
         .endif

      .elseif wmsg == WM_ACTIVATEAPP
         INVOKE     DefWindowProc, hwnd, WM_NCACTIVATE, wparam, 0 
            ret

      .elseif wmsg == WM_NCACTIVATE
            mov     eax, TRUE
            ret

      .elseif wmsg == WM_MOVE || wmsg == WM_SIZE
;DSPValue hWnd, wmsg, 1, 't'
         .if sw1           ; From changing styles
               mov     eax, 1
               ret
         .endif
         .if hStyle
            INVOKE     StyleProc, hStyle, WM_COMMAND, 5006, 0
               and     hStyle, 0
         .endif
         INVOKE     GetWindowRect, hForm, addr Prect
         INVOKE     GetWindowRect, hWnd, addr Crect
          MOVmd     hCtrl, hwnd

            mov     dis.itemID, 0
         INVOKE     GetOffset, 0
           imul     ebx, eax
            add     ecx, ebx

            mov     eax, hwnd
         .if eax == hForm
            add     ecx, DlgLeftOrg
         .elseif eax == hGrp
            add     ecx, CtrlsLeftOrg
         .else
               jmp     NoChg
         .endif
            add     ecx, 16
            mov     byte ptr[ecx], 3  ; Change

NoChg:
         .if eax == hForm
               mov     eax, Prect.left
               sub     eax, Crect.left
               mov     xOff, eax
               mov     FormX, eax
               mov     eax, Prect.top
               sub     eax, Crect.top
               mov     yOff, eax
               mov     FormY, eax
               mov     CtrlType, 7501
               mov     eax, ResB
               sub     FormX, eax ;6
               mov     eax, ResT
               sub     FormY, eax ;22

            INVOKE     GetWindowRect, hWork, addr Crect
              push     Prect.right
              push     Prect.bottom
               mov     ecx, Prect.left
               sub     Prect.right, ecx
               mov     edx, Prect.top
               sub     Prect.bottom, edx
            .if ecx < Crect.left || ecx > 7fffh
                MOVmd     Prect.left, Crect.left
            .endif
            .if edx < Crect.top || edx > 7fffh
                MOVmd     Prect.top, Crect.top
            .endif
               pop     edx
               pop     ecx
mov     eax, Prect.right
mov     ebx, Crect.right
sub     ebx, Crect.left
            .if ecx > Crect.right && eax < ebx
                MOVmd     Prect.left, Crect.right
                  mov     eax, Prect.right
                  sub     Prect.left, eax
            .elseif ecx > Crect.right && eax >= ebx
;MOVmd     Prect.left, Crect.left
            .endif
mov     eax, Prect.bottom
mov     ebx, Crect.bottom
sub     ebx, Crect.top
            .if edx > Crect.bottom && eax < ebx
                MOVmd     Prect.top, Crect.bottom
                  mov     eax, Prect.bottom
                  sub     Prect.top, eax
            .elseif edx > Crect.bottom && eax >= ebx
MOVmd     Prect.top, Crect.top
            .endif
            INVOKE     MoveWindow, hForm, Prect.left, Prect.top, Prect.right, Prect.bottom, TRUE

               and     Len, 0
             MOVmd     Cnt, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt
            .while (Cnt)                           ; Find handle of active control in the array
                  mov     eax, Len
                  mov     ecx, hArray+[eax*8]      ; Extract Count type
                  and     ecx, 0ffffh
               .if ecx == 7513 || ecx == 7514
                     mov     edx, hArray+[eax*8+4] ; Extract handle
                  .if ecx == 7513
                     INVOKE     SendMessage, edx, TB_AUTOSIZE, 0, 0
                  .else
                     INVOKE     MoveWindow, edx, 0, 0, 0, 0, TRUE
                  .endif
               .endif
                  inc     Len
                  dec     Cnt
            .endw

            INVOKE     GetClientRect, hwnd, addr Srect
            .if xOff
                  mov     eax, ResB
                  sub     xOff, eax
            .endif
            .if yOff
                  mov     eax, ResT
                  sub     yOff, eax
            .endif
            INVOKE     MoveGrabbers, 2, 0
            INVOKE     RedrawWindow, hWndList, 0, 0,\
                       RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_UPDATENOW or RDW_ALLCHILDREN ;NO

         .elseif eax == hGrp
            INVOKE     GetWindowRect, hwnd, addr Srect
               mov     eax, SizeB
               mov     ecx, SizeT
               add     Prect.left, eax
               sub     Prect.right, eax
               add     Prect.top, ecx
               sub     Prect.bottom, ecx
               mov     eax, Srect.left
               sub     Srect.right, eax
               mov     eax, Srect.top
               sub     Srect.bottom, eax
               mov     eax, Prect.left
               sub     Srect.left, eax
               mov     eax, Prect.top
               sub     Srect.top, eax
               mov     CtrlType, 7503 ;7524
            INVOKE     MoveGrabbers, 5, 0
         .endif
            jmp     Ret0

      .elseif wmsg == WM_LBUTTONDOWN
         .if hStyle
            INVOKE     StyleProc, hStyle, WM_COMMAND, 5006, 0
               and     hStyle, 0
         .endif
MOVmd     SavHnd, hwnd
;.if !InputType
;     mov     ParentOn, 1
;.endif

           Call     ClearMult
         INVOKE     GetClientRect, hwnd, addr Prect
         .if StatusOn
               sub     Prect.bottom, 20
         .endif

         .if TabSelect == 2
               mov     eax, hwnd
               mov     hCtrl, eax
            .if eax == hForm
                  mov     CtrlType, 7501
               INVOKE     GetWindowRect, hWnd, addr Crect
               INVOKE     SetParent, hWndStatic, hForm
            .else
                  mov     hGrp, eax
                  mov     CtrlType, 7503
               INVOKE     GetWindowRect, hForm, addr Crect
               INVOKE     SetParent, hWndStatic, hGrp
            .endif
            INVOKE     GetWindowRect, hwnd, addr TBrect
            .if !hSizeData
               INVOKE     CreateDialogParam, hInst, 4902, hWnd, offset SizeDataProc, 0
            .endif

               mov     ecx, TBrect.left
               sub     ecx, Crect.left
               mov     edx, TBrect.top
               sub     edx, Crect.top
               mov     eax, hwnd
            .if eax == hForm
                  sub     ecx, ResB ;6
                  sub     edx, ResT ;22
                  mov     FormX, ecx
                  mov     FormY, edx
               INVOKE     PosProc, hwnd, ecx, edx, 8

            .else
                  sub     ecx, SizeB
                  sub     edx, SizeT
               INVOKE     PosProc, hwnd, ecx, edx, 13
            .endif

               and     CtrlOn, 0

               xor     ecx, ecx
               mov     eax, lparam
               mov     cx, ax
               shr     eax, 16
               mov     rect.left, ecx
               mov     rect.top, eax
               and     rect.right, 0
               xor     eax, eax
               ret
         .endif

      .elseif wmsg == WM_MOUSEMOVE

;---------- [Display the cursor x - y position] ----------
            mov     eax, lparam        ; Get the y   
            shr     eax, 16            ; position in hiword(lparam)
         .if ax > 9000
               xor     eax, eax
         .endif
            mov     PosY, eax
         INVOKE     BaseAscii, eax, addr mmsgy, 4, 10, 1, 1, 0
            mov     eax, lparam          ; Get the x
            cwde                         ; position in loword(lparam)
         .if ax > 9000
                xor     eax, eax
         .endif
            mov     PosX, eax
         INVOKE     BaseAscii, eax, addr mmsgx, 4, 10, 1, 0, 0
         INVOKE     SendMessage, hWndStat, SB_SETTEXT, 1, addr mmsg

         .if wparam != MK_LBUTTON
            .if TabSelect == 2
               .if hSizeData
                     INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
                        and     hSizeData, 0
               .endif

;---------- [Show position box] ----------
;               .if hSizeData
;                  INVOKE     GetParent, hSizeData
;                     mov     ecx, hwnd
;                  .if ecx != hForm
;                     INVOKE     GetParent, hwnd
;                        mov     ecx, eax
;                  .endif
;                  .if eax != ecx
;                     INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
;                        and     hSizeData, 0
;                  .endif
;               .endif
;               .if !hSizeData
;                  INVOKE     CreateDialogParam, hInst, 4902, hwnd, offset SizeDataProc, 0
;               .endif
;               INVOKE     PosProc, hwnd, PosX, PosY, 8

               .if UpID                  ; Enter key was not pressed after change
                    call     UpdateCtrl
               .endif

               INVOKE     GetFocus
               .if eax != hForm && !sw1 && !hDef  ; sw1 is for font dialog
                  INVOKE     SetFocus, hwnd
               .endif
                  mov     eax, 1
                  ret
            .endif
               jmp     Ret0

         .elseif wparam == MK_LBUTTON
            .if TabSelect == 2 && InputType == 7501 && !hUnder ||\
                TabSelect == 2 && InputType && DlgOn
            .else
     mov     ParentOn, 1
                  jmp     Ret0
            .endif
;.if !InputType
;     mov     ParentOn, 1
;.endif
            .if CtrlType == 7526    ; Animate
                  jmp     Ret0
            .endif

            .if !hSizeData
               INVOKE     CreateDialogParam, hInst, 4902, hWnd, offset SizeDataProc, 0
            .endif
            INVOKE     SetCapture, hwnd
               xor     ecx, ecx
               mov     eax, lparam
               mov     cx, ax
               shr     eax, 16
            .if ecx > 7fffh
                  mov     ecx, 0
            .endif
            .if ecx < rect.left 
                  inc     ecx
            .endif
            .if eax > 7fffh
                  mov     eax, 0
            .endif
            .if eax < rect.top 
                  inc     eax
            .endif

            .if ecx > Prect.right
                  mov     ecx, Prect.right
            .endif
            .if eax > Prect.bottom
                  mov     eax, Prect.bottom
            .endif

               mov     rect.right, ecx
               mov     rect.bottom, eax

;---------- [No control is being drawn] ----------
            .if rect.left == ecx || rect.top == eax
                  mov     eax, hwnd
               .if eax == hForm
                  INVOKE     GetWindowRect, hWnd, addr Crect
               .else
                  INVOKE     GetWindowRect, hForm, addr Crect
               .endif
               INVOKE     GetWindowRect, hwnd, addr TBrect

                  mov     ecx, TBrect.left
                  sub     ecx, Crect.left
                  mov     edx, TBrect.top
                  sub     edx, Crect.top
                  mov     eax, hwnd
               .if eax == hForm
                     sub     ecx, ResB ;6
                     sub     edx, ResT ;22
                  INVOKE     PosProc, hwnd, ecx, edx, 8

               .else
                     sub     ecx, SizeB
                     sub     edx, SizeT
                  INVOKE     PosProc, hwnd, ecx, edx, 13
               .endif

;---------- [Control is being drawn] ----------
            .else
                  mov     eax, hwnd
               .if eax == hForm
                  INVOKE     PosProc, hwnd, 0, 0, 6
               .else
                  INVOKE     PosProc, hwnd, 0, 0, 7
               .endif

               INVOKE     CopyRect, addr Crect, addr rect
                  mov     eax, Crect.right
               .if eax < Crect.left
                     mov     ecx, Crect.left
                     mov     Crect.left, eax
                     mov     Crect.right, ecx
               .endif
                  mov     eax, Crect.bottom
               .if eax < Crect.top
                     mov     ecx, Crect.top
                     mov     Crect.top, eax
                     mov     Crect.bottom, ecx
               .endif

                  mov     ecx, Crect.right
                  sub     ecx, Crect.left
                  mov     edx, Crect.bottom
                  sub     edx, Crect.top
               INVOKE     MoveWindow, hWndStatic, Crect.left, Crect.top, ecx, edx, 1

                  mov     eax, rect.right
                  sub     eax, rect.left
                  mov     ecx, rect.bottom
                  sub     ecx, rect.top
               .if sdword ptr eax < 0       ; Check for negative number
                     neg     eax            ; and invert the value
               .endif
               .if sdword ptr ecx < 0
                     neg     ecx
               .endif
                  and     CtrlOn, 0
               .if eax > 9 && ecx > 9       ; Check to see if control is at least 10x10
                     mov     CtrlOn, 1
               .endif
            .endif
         .endif

      .elseif wmsg == WM_LBUTTONUP

            and     hGrpOn, 0
.if SavHnd
MOVmd     hwnd, SavHnd
.endif
and     SavHnd, 0
and     ParentOn, 0
and     CtrlHnd, 0
         INVOKE     MoveWindow, hWndStatic, 0, 0, 0, 0, 1
         .if hSizeData
            INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
               and     hSizeData, 0
         .endif
         INVOKE     ReleaseCapture
         .if rect.right && TabSelect == 2 && CtrlOn
         .else
;            INVOKE     RedrawWindow, hwnd, 0, 0,\
;                       RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN

            INVOKE     GetClientRect, hwnd, addr Srect
             MOVmd     hCtrl, hwnd

               mov     eax, hwnd
            .if eax == hForm
               INVOKE     MoveGrabbers, 2, 0

;NOTE $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    MOVmd     hSMove, hForm
    MOVmd     CtrlHnd, hForm
      mov     SavCtrl, 7501
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

            .else
               INVOKE     GetWindowRect, hwnd, addr Srect
               INVOKE     GetWindowRect, hForm, addr Prect
                MOVmd     hGrp, hwnd

                  xor     eax, eax
                  mov     edx, hwnd
                  mov     ecx, GrpCnt ;32
               .while (ecx)     ; Find handle of Groupbox in the array
                  .if hGrpArray[eax] == edx
                        mov     ecx, hGrpArray[eax+4]
                        mov     hCtrl, ecx
                     .break  
                  .endif
                     add     eax, 8
                     dec     ecx
               .endw

                  mov     eax, SizeB
                  mov     ecx, SizeT
                  add     Prect.left, eax
                  sub     Prect.right, eax
                  add     Prect.top, ecx
                  sub     Prect.bottom, ecx

                  mov     eax, Srect.left
                  sub     Srect.right, eax
                  mov     eax, Srect.top
                  sub     Srect.bottom, eax

                  mov     eax, Prect.left
                  sub     Srect.left, eax
                  mov     eax, Prect.top
                  sub     Srect.top, eax
 MOVmd     CtrlHnd, hwnd
 MOVmd     SavCtrl, CtrlType
               INVOKE     MoveGrabbers, 5, 0
               INVOKE     BringWindowToTop, hGrp
            .endif
               jmp     Ret0
         .endif

PasteIt:
         .if PasteOn
               mov     eax, hwnd
               mov     hCtrl, eax
            .if eax == hForm
                  mov     CtrlType, 7501
            .else
                  mov     hGrp, eax
                  mov     CtrlType, 7503
            .endif
mov     sw44, 1
;               and     PasteOn, 0
         .endif

            mov     eax, rect.right
         .if eax < rect.left
               mov     ecx, rect.left
               mov     rect.left, eax
               mov     rect.right, ecx
         .endif
            mov     eax, rect.bottom
         .if eax < rect.top
               mov     ecx, rect.top
               mov     rect.top, eax
               mov     rect.bottom, ecx
         .endif

         .if SnapOn
            INVOKE     GetWindowRect, hwnd, addr Prect
               mov     eax, Prect.left
               mov     ecx, Prect.top
               add     eax, SizeB
               add     ecx, SizeT
               add     rect.left, eax
               add     rect.top, ecx
               add     rect.right, eax
               add     rect.bottom, ecx
            INVOKE     CopyRect, addr Srect, addr rect
              call     SnapTo
            INVOKE     CopyRect, addr rect, addr Srect
               mov     eax, Prect.left
               mov     ecx, Prect.top
               add     eax, SizeB
               add     ecx, SizeT
               sub     rect.left, eax
               sub     rect.top, ecx
               sub     rect.right, eax
               sub     rect.bottom, ecx
         .endif

            mov     ecx, rect.right
            sub     ecx, rect.left
            mov     edx, rect.bottom
            sub     edx, rect.top

;---------- [Create the controls] ----------
            mov     rect.right, ecx
            mov     rect.bottom, edx

.if CtrlType == 7503 && InputType == 7503
      jmp     Ret0
.endif

         .if CtrlType == 7503
               xor     eax, eax
               mov     edx, hGrp
               mov     ecx, GrpCnt ;32
            .while (ecx)                            ; Find handle of Groupbox parent in the array
               .if hGrpArray[eax] == edx
                   MOVmd     hwnd, hGrpArray[eax+4] ; Handle of Groupbox
                     mov     hGrpOn, 1
                  .break  
               .endif
                  add     eax, 8
                  dec     ecx
            .endw
         .endif

         INVOKE     CreateControls, hwnd, 0
         INVOKE     SetFocus, hForm                 ; Added 10-24-2003
.if PasteOn
      and     PasteOn, 0
      and     sw44, 0
.endif
            jmp     Ret0

      .elseif wmsg == WM_COMMAND
            mov     eax, wparam
           cwde

         .if eax == IDM_PASTE
               mov     PasteOn, 1
             MOVmd     InputType, CopyP.ID
             MOVmd     rect.left, CopyP.Left
             MOVmd     rect.top, CopyP.Top
             MOVmd     rect.right, CopyP.Wth
             MOVmd     rect.bottom, CopyP.Hgt
               mov     eax, rect.left
               add     rect.right, eax
               mov     eax, rect.top
               add     rect.bottom, eax
               jmp     PasteIt

         .elseif eax == IDM_DEL
            .if TabSelect == 2 && DlgOn
               INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, CtrlType, FALSE

                  and     Cnt, 0
               .while AniCnt
                     mov     ecx, Cnt
                  .if hAniArray+[ecx*4]
                     INVOKE     DestroyWindow, hAniArray+[ecx*4]
                  .endif
                     inc     Cnt
                     dec     AniCnt
               .endw

                  mov     eax, hwnd
               .if eax == hForm
                     mov     hCtrl, eax
                     mov     CtrlType, 7501
                     mov     dis.itemID, 4
;---------- [Get offset in the structure array] ----------
                  INVOKE     GetOffset, 0
                     mov     StrSize, eax
                    imul     ebx, StrSize
                     add     ecx, ebx
                  INVOKE     lstrcpy, addr szBuff, addr [ecx+edx*4] 
                  INVOKE     SendMessage, hWndComboD, CB_FINDSTRINGEXACT, -1, addr szBuff
                  INVOKE     SendMessage, hWndComboD, CB_DELETESTRING, eax, 0
                  INVOKE     SendMessage, hWndComboD, CB_GETCOUNT, 0, 0
                  .if !eax
                     INVOKE     SendMessage, hWndComboD, CB_SELECTSTRING, -1, addr szNULL
                  .else
                     INVOKE     SendMessage, hWndComboD, CB_SETCURSEL, 0, 0
                  .endif
                     and     InputType, 0
                     and     hUnder, 0
                     and     hForm, 0
                     and     DlgOn, 0
                     and     CtrlOn, 0
                     and     ToolOn, 0
                     and     StatusOn, 0
                     mov     hArray, 0
                     mov     hArray+4, 0
                     and     ArrayCnt, 0
                  .if hAsmEdit
                        mov     ecx, hRetForm
                        xor     eax, eax
                        mov     [ecx], eax
                  .endif
                  INVOKE     SendMessage, hWndCombo, CB_RESETCONTENT, 0, 0
                  INVOKE     SendMessage, hWndList, LB_RESETCONTENT, 0, 0

               .else
                     mov     eax, hForm
                     mov     hCtrl, eax
                     mov     CtrlType, 7501
                  INVOKE     GetClientRect, hForm, addr Srect
                  INVOKE     MoveGrabbers, 2, 0

                     and     hParent, 0
                     xor     eax, eax
                     mov     edx, hwnd
                     mov     ecx, GrpCnt ;32
                  .while (ecx) ; Find handle of Groupbox parent in the array
                     .if hGrpArray[eax] == edx
                         MOVmd     hParent, hGrpArray[eax+4]
                        .break  
                     .endif
                        add     eax, 8
                        dec     ecx
                  .endw

                  .if hParent
                        and     Len, 0
                      MOVmd     Cnt, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt
                     .while (Cnt)               ; Get handle of controls in the array
                           mov     eax, Len
                         MOVmd     hCtrl, hArray[eax+4]
                        INVOKE     IsChild, hParent, hCtrl
                        .if eax
                              mov     eax, Len
                              mov     ecx, hArray[eax]
                              and     ecx, 0ffffh
                              mov     CtrlType, ecx

DeleteCB:
                              mov     dis.itemID, 1
;---------- [Get offset in the structure array] ----------
                           INVOKE     GetOffset, 0
                              mov     StrSize, eax
                             imul     ebx, StrSize
                              add     ecx, ebx
                           INVOKE     lstrcpy, addr szBuff, addr [ecx+edx*4]
                           INVOKE     SendMessage, hWndCombo, CB_FINDSTRINGEXACT, -1, addr szBuff
                           INVOKE     SendMessage, hWndCombo, CB_DELETESTRING, eax, 0
                              mov     eax, Len
                              mov     hArray[eax+4], 0
                           INVOKE     DestroyWindow, hCtrl
                           .if !hParent
                                 jmp     NoMore
                           .endif
                        .endif
                           add     Len, 8
                           dec     Cnt
                     .endw

NoMore:
                     .if hParent
                           and     Len, 0
                         MOVmd     Cnt, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt
                           mov     edx, hParent
                        .while (Cnt)               ; Get handle of Groupbox in the array
                              mov     eax, Len
                           .if edx == hArray[eax+4]
                                 mov     CtrlType, 7503
                                 mov     hCtrl, edx
                                 mov     Cnt, 1
                                 and     hParent, 0
                                 jmp     DeleteCB
                           .endif
                              add     Len, 8
                              dec     Cnt
                        .endw
                     .endif
                     INVOKE     SetParent, hWndStatic, hForm
                      MOVmd     hCtrl, hForm
                  .endif

               .endif
               INVOKE     ShowWindow, hREditP, SW_HIDE
               INVOKE     ShowWindow, hButtP, SW_HIDE
               INVOKE     IsWindow, hwnd
               .if eax
                  INVOKE     DestroyWindow, hwnd
               .endif
            .endif
         .endif

         jmp     ThatsAll

PopUp:
         INVOKE     GetWindowRect, hwnd, addr rect
            mov     ecx, lparam        ; x/y pos of window
            mov     edx, ecx
            and     edx, 0000ffffh     ; edx = LOWORD(lparam) = x pos
            shr     ecx, 16            ; ecx = HIWORD(lparam) = y pos
            mov     CopyP.Left, edx
            mov     CopyP.Top, ecx
            add     edx, rect.left
            add     ecx, rect.top
            mov     eax, hwnd
         .if eax == hForm
               add     edx, 5  ;10 
               add     ecx, 20 ;30
         .else
               add     edx, 0 ;6 
               add     ecx, 0 ;10
         .endif
         INVOKE     TrackPopupMenu, hRMenu, TPM_LEFTALIGN or TPM_LEFTBUTTON,\
                    edx, ecx, 0, hwnd, addr rect

      .else

ThatsAll:
         INVOKE     DefWindowProc, hwnd, wmsg, wparam, lparam
            ret
      .endif

Ret0:
         xor    eax, eax
         ret
FormProc ENDP

;=====================================================
; Get the border and titlebar sizes PROCEDURE
;=====================================================
GetSizes PROC hwnd:DWORD
LOCAL    Crect:RECT
LOCAL    Wrect:RECT

      INVOKE     GetClientRect, hwnd, addr Crect
      INVOKE     GetWindowRect, hwnd, addr Wrect
         mov     eax, Wrect.left
         sub     Wrect.right, eax
         mov     eax, Wrect.top
         sub     Wrect.bottom, eax
         mov     eax, Wrect.right
         sub     eax, Crect.right
         shr     eax, 1
         mov     SizeB, eax
         mov     eax, Wrect.bottom
         sub     eax, Crect.bottom
         sub     eax, SizeB
         mov     SizeT, eax
         xor     eax, eax
         ret
GetSizes ENDP

;=====================================================
; Load the grabber and static windows PROCEDURE
;=====================================================
LoadGrabbers PROC  hwnd:DWORD

         .if hSizeL
            INVOKE     DestroyWindow, hSizeL
            INVOKE     DestroyWindow, hSizeT
            INVOKE     DestroyWindow, hSizeR
            INVOKE     DestroyWindow, hSizeB
            INVOKE     DestroyWindow, hWndStatic
         .endif

;---------- [Size handle windows] ----------
         INVOKE     CreateWindowEx, 0, addr SizeClassV, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or WS_CLIPSIBLINGS,\
                    0, 0, 0, 0, hwnd, 0, hInst, 0
            mov     hSizeL, eax
         INVOKE     SetWindowLong, hSizeL, GWL_WNDPROC, addr SizeProc
            mov     lpSizeProc, eax

         INVOKE     CreateWindowEx, 0, addr SizeClassV, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or WS_CLIPSIBLINGS,\
                    0, 0, 0, 0, hwnd, 0, hInst, 0
            mov     hSizeR, eax
         INVOKE     SetWindowLong, hSizeR, GWL_WNDPROC, addr SizeProc
            mov     lpSizeProc, eax

         INVOKE     CreateWindowEx, 0, addr SizeClassH, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or WS_CLIPSIBLINGS,\
                    0, 0, 0, 0, hwnd, 0, hInst, 0
            mov     hSizeT, eax
         INVOKE     SetWindowLong, hSizeT, GWL_WNDPROC, addr SizeProc
            mov     lpSizeProc, eax

         INVOKE     CreateWindowEx, 0, addr SizeClassH, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or WS_CLIPSIBLINGS,\
                    0, 0, 0, 0, hwnd, 0, hInst, 0
            mov     hSizeB, eax
         INVOKE     SetWindowLong, hSizeB, GWL_WNDPROC, addr SizeProc
            mov     lpSizeProc, eax

;---------- [Create the sizing window] ----------
         INVOKE     CreateWindowEx, WS_EX_TRANSPARENT, addr StaticClass, 0,\
                    WS_CHILD or WS_VISIBLE or\
                    SS_BLACKFRAME or WS_CLIPSIBLINGS,\
                    0, 0, 0, 0, hwnd, 0, hInst, 0
            mov     hWndStatic, eax
         INVOKE     SetWindowLong, hWndStatic, GWL_WNDPROC, SaticProcR
            mov     lpStaticR, eax
         INVOKE     SetWindowPos, hWndStatic, HWND_TOP,\
                    0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE

         xor    eax, eax
         ret
LoadGrabbers ENDP

;=====================================================
; TabCtlDlg Tab Control  DIALOG BOX PROCEDURE
;=====================================================
TabCtlDlg PROC  hdlg:DWORD, wmsg, wparam, lparam

         cmp     wmsg, WM_INITDIALOG
         jne     NotInit

      INVOKE     GetDlgItem, hdlg, 702            ; Get the handle of the Tab Control
         mov     hTab, eax                        ; Save it

;---------- [Fill the Tab Control Item structure and insert the item] ----------
         mov     tci.imask, TCIF_TEXT             ; Text
         mov     tci.lpReserved1, 0               ; Reserved
         mov     tci.lpReserved2, 0               ; Reserved
         mov     tci.pszText, offset TabTitle1    ; pointer to string containing tab text 
         mov     tci.cchTextMax, sizeof TabTitle1 ; Size of TabTitle1
         mov     tci.iImage, -1                   ; Index to tab control's image 
         mov     tci.lParam, 0                    ; Extra info
      INVOKE     SendMessage, hTab, TCM_INSERTITEM, 0, offset tci

         mov     tci.pszText, offset TabTitle2
         mov     tci.cchTextMax, sizeof TabTitle2
      INVOKE     SendMessage, hTab, TCM_INSERTITEM, 1, addr tci

         mov     tci.pszText, offset TabTitle3
         mov     tci.cchTextMax, sizeof TabTitle3
      INVOKE     SendMessage, hTab, TCM_INSERTITEM, 2, addr tci

         mov     tci.pszText, offset TabTitle4
         mov     tci.cchTextMax, sizeof TabTitle4
      INVOKE     SendMessage, hTab, TCM_INSERTITEM, 3, addr tci

         mov     tci.pszText, offset TabTitle5
         mov     tci.cchTextMax, sizeof TabTitle5
      INVOKE     SendMessage, hTab, TCM_INSERTITEM, 4, addr tci

         mov     tci.pszText, offset TabTitle6
         mov     tci.cchTextMax, sizeof TabTitle6
      INVOKE     SendMessage, hTab, TCM_INSERTITEM, 5, addr tci

;---------- [Load the dialog boxes in the Tab Controls] ----------
      INVOKE     CreateDialogParam, hInst, 4801, hTab, offset ResourceDlg, 0
         mov     hTabSeL1, eax

      INVOKE     CreateDialogParam, hInst, 4802, hTab, offset MenuDlg, 0
         mov     hTabSeL2, eax

      INVOKE     CreateDialogParam, hInst, 4803, hTab, offset DialogDlg, 0
         mov     hTabSeL3, eax

      INVOKE     CreateDialogParam, hInst, 4804, hTab, offset ExtractDlg, 0
         mov     hTabSeL4, eax

      INVOKE     CreateDialogParam, hInst, 4805, hTab, offset BuildDlg, 0
         mov     hTabSeL5, eax

      INVOKE     CreateDialogParam, hInst, 4806, hTab, offset SampleDlg, 0
         mov     hTabSeL6, eax

      INVOKE     SendMessage, hTab, TCM_SETCURSEL, TabSelect, 0
         mov     eax, TabSelect                   ; Previous selected Tab
         mov     ecx, hTabSeL+[eax*4]             ; Extract previous Tabs handle
      INVOKE     ShowWindow, ecx, SW_SHOWDEFAULT
;WS_EX_TOPMOST
; or WS_CLIPCHILDREN or WS_CLIPSIBLINGS     ; Removed 02-11-2002 7:40
   INVOKE     CreateWindowEx, 0, addr WorkClass, 0,\
              WS_CHILD or WS_VISIBLE,\
              0, 0, 0, 0, lparam, 48, hInst, NULL
      mov     hWork, eax

         and     Cnt, 0
      .while (Cnt < 6)
         .if Cnt == 2
               mov     eax, hWork
               mov     ecx, Cnt
               mov     hREditTab+[ecx*4], eax
         .else   ; or WS_CLIPCHILDREN
            INVOKE     CreateWindowEx, NULL, addr RichEdit, NULL,\
                       WS_CHILD or WS_VISIBLE or ES_MULTILINE or\
                       ES_NOHIDESEL or ES_SAVESEL or\
                       WS_HSCROLL or ES_AUTOHSCROLL or WS_VSCROLL or ES_AUTOVSCROLL,\
                       0, 0, 0, 0, lparam, EditID, hInst, NULL
               mov     hREdit, eax
               mov     ecx, Cnt
               mov     hREditTab+[ecx*4], eax

            INVOKE     SendMessage, hREdit, EM_SETOPTIONS, ECOOP_XOR, ECO_SELECTIONBAR
            INVOKE     SendMessage, hREdit, EM_EXLIMITTEXT, 0, 500000

;---------- [Control window subclassed] ----------
            INVOKE     SetWindowLong, hREdit, GWL_WNDPROC, RichEditProc
               mov     lpRichEdit, eax
            INVOKE     SendMessage, hREdit, WM_SETFONT, hFont, TRUE
         .endif
            inc     Cnt
      .endw
       MOVmd     hREdit, hREditTab
      INVOKE     SetFocus, hREdit
         jmp     GetOut

NotInit:
         cmp     wmsg, WM_NOTIFY
          je     wmnotify
         cmp     wmsg, WM_CLOSE
          je     CancelOut
         cmp     wmsg, WM_COMMAND
         jne     GetOut
         mov     eax, wparam
        cwde
         cmp     eax, IDCANCEL
          je     CancelOut
         jmp     GetOut

wmnotify:
         mov     eax, lparam                         ; lparam is a pointer to a NMHDR Struct
         mov     eax, (NMHDR ptr [eax]).code         ; Check for TCN_SELCHANGE notify message
         cmp     eax, TCN_SELCHANGE
          je     SelectTab
         jmp     GetOut

SelectTab:
      .if hImage
         INVOKE     SendMessage, hImage, WM_COMMAND, 405, 0
      .endif

         mov     ecx, TabSelect                      ; Previous selected Tab
         mov     eax, hREditTab+[ecx*4]              ; Extract previous REdit handle
      INVOKE     ShowWindow, eax, SW_HIDE            ; Hide its window
         mov     ecx, TabSelect                      ; Previous selected Tab
         mov     eax, hTabSeL+[ecx*4]                ; Extract previous Tabs handle
      INVOKE     ShowWindow, eax, SW_HIDE            ; Hide its window
      INVOKE     SendMessage, hTab, TCM_GETCURSEL, 0, 0  ; New selected Tab
         mov     TabSelect, eax                      ; Save the Tab ID
      .if TabSelect == 2
          MOVmd     hWork, hREditTab+[eax*4]
         INVOKE     ShowWindow, hWork, SW_SHOW
      .else
         .if hStyle
            INVOKE     StyleProc, hStyle, WM_COMMAND, 5006, 0
               and     hStyle, 0
         .endif
            mov     eax, TabSelect                   ; New selected Tab
          MOVmd     hREdit, hREditTab+[eax*4]
         INVOKE     ShowWindow, hREdit, SW_SHOW
.if sw2 != 44
         INVOKE     SetFocus, hREdit
.endif
      .endif
         mov     eax, TabSelect                      ; New selected Tab
         mov     ecx, hTabSeL+[eax*4]                ; Extract new Tabs handle
      INVOKE     ShowWindow, ecx, SW_SHOWDEFAULT     ; Show its window
;         and     GridOn, 0

      .if TabSelect == 2
;            and     GridOn, 0
;         INVOKE     IsDlgButtonChecked, hOpt, 601
;         .if eax
;               mov     GridOn, 1
;         .endif
         .if DlgOn
            .if hAsmEdit
                  mov     ecx, hRetForm
                  mov     eax, hForm
                  mov     [ecx], eax
            .endif
            INVOKE     ShowWindow, hForm, SW_SHOW
         .endif
      .else
         .if hAsmEdit
               mov     ecx, hRetForm
               xor     eax, eax
               mov     [ecx], eax
         .endif
         .if DlgOn
            INVOKE     ShowWindow, hForm, SW_HIDE
         .endif
      .endif
.if sw2 == 44
      and     sw2, 0
      jmp     GetOut
.endif
      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
         jmp     GetOut

CancelOut:
;---------- [Clear any open resources] ----------
      INVOKE     DestroyWindow, hdlg
         mov     eax, TRUE
         jmp     TabCtlRet

GetOut:
         mov     eax, FALSE

TabCtlRet:
         RET
TabCtlDlg ENDP

;=======================================
; ResourceDlg Dialog
;=======================================
ResourceDlg PROC  uses ebx  hdlg:DWORD, wmsg, wparam, lparam
LOCAL    ofn:OPENFILENAME
LOCAL    szBuff0[256]:BYTE, szBuff1[256]:BYTE

      .if wmsg == WM_INITDIALOG
          MOVmd     hDlg0, hdlg
         INVOKE     SetDlgItemInt, hdlg, 511, RStartID, 0

      .elseif wmsg != WM_COMMAND
            jmp     ResourceDone
      .endif

         mov     eax, wparam
        cwde

      .if eax > 600 && eax < 606
            sub     eax, 601
           push     eax
         INVOKE     SetDlgItemText, hdlg, 501, TxtArray[eax*4]
            pop     eax
           push     eax
         INVOKE     SetDlgItemText, hdlg, 502, ExtArray[eax*4]
            pop     eax
         INVOKE     lstrcpy, addr szFilt, ExtArray[eax*4]

      .elseif eax == 606                 ; Browse
         INVOKE     RtlZeroMemory, addr ofn, sizeof ofn

         INVOKE     lstrcpy, addr szBuff0, addr RootPath
         INVOKE     lstrcat, addr szBuff0, addr szBackS
         .if hAsmEdit
            INVOKE     lstrcat, addr szBuff0, addr szAstr
         .else
            INVOKE     lstrcpy, addr szBuff0, addr szAstr
         .endif
         INVOKE     lstrcat, addr szBuff0, addr szFilt

            mov     ofn.lStructSize, sizeof ofn
            mov     ofn.lpstrFilter, offset szFilterR
            lea     eax, szBuff0
            mov     ofn.lpstrFile, eax
            mov     ofn.nMaxFile, lengthof szBuff0
            mov     ofn.Flags, OFN_NOVALIDATE
         INVOKE     GetOpenFileName, addr ofn
            cmp     eax, FALSE        ; Cancel'ed or error occurred
             je     ResourceDone
         INVOKE     lstrlen, addr szBuff0
            xor     ecx, ecx
            xor     edx, edx
         .while (eax)
               mov     bl, byte ptr szBuff0[ecx]
               mov     byte ptr szBuff1[edx], bl
            .if bl == '\'
                  mov     byte ptr szBuff1[edx+1], '\'
                  inc     edx
            .endif
            dec     eax
            inc     ecx
            inc     edx
         .endw
            mov     byte ptr szBuff1[edx], 0
         INVOKE     SetDlgItemText, hdlg, 502, addr szBuff1
            jmp     ResourceDone

      .elseif eax == 607
         INVOKE     GetDlgItemText, hdlg, 501, addr szBuff0, lengthof szBuff0
         .if !eax
               jmp     ResourceDone
         .endif
            mov     edx, 22 ;20   ; N O T E !!!!!!!!!!!!!!!!!!!!!!!!
            sub     edx, eax
           push     edx
         INVOKE     lstrlen, addr szBuff0
            mov     ecx, eax
            pop     edx
         INVOKE     lstrcpyn, addr szBuff0[ecx], addr szFill, edx
         INVOKE     IsDlgButtonChecked, hdlg, 601
         .if eax
            INVOKE     lstrcat, addr szBuff0, addr szResB
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 602
         .if eax
            INVOKE     lstrcat, addr szBuff0, addr szResI
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 603
         .if eax
            INVOKE     lstrcat, addr szBuff0, addr szResC
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 604
         .if eax
            INVOKE     lstrcat, addr szBuff0, addr szResW
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 605
         .if eax
            INVOKE     lstrcat, addr szBuff0, addr szResM
         .endif
          INVOKE     GetDlgItemText, hdlg, 502, addr szBuff1, lengthof szBuff1
         .if !eax
               jmp     ResourceDone
         .endif

         INVOKE     lstrcat, addr szBuff0, addr szQuote
         INVOKE     lstrcat, addr szBuff0, addr szBuff1
         INVOKE     lstrcat, addr szBuff0, addr szQuote
         INVOKE     lstrcat, addr szBuff0, addr szCRLF

         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff0
         INVOKE     SetFocus, hREdit
      .endif

ResourceDone:
         mov     eax, FALSE           ; Return with FALSE

ResourceRet:
         ret
ResourceDlg ENDP

;=======================================
; MenuDlg  Dialog
;=======================================
MenuDlg PROC    hdlg:DWORD, wmsg, wparam, lparam
LOCAL    cr:CHARRANGE
LOCAL    szBuff0[256]:BYTE, szBuff1[256]:BYTE

      .if wmsg == WM_INITDIALOG
          MOVmd     hDlg1, hdlg
         INVOKE     GetDlgItem, hdlg, 501
            mov     hMenuN, eax
         INVOKE     GetDlgItem, hdlg, 502
            mov     h502, eax
         INVOKE     GetDlgItem, hdlg, 503
            mov     h503, eax

         INVOKE     SetDlgItemInt, hdlg, 511, MStartID, 0

      .elseif wmsg != WM_COMMAND
            jmp     MenuDone
      .endif

         mov     eax, wparam
        cwde
      .if eax > 602 && eax < 606 && Cnt == 0
            inc     Cnt
      .endif

      .if eax == 601
         INVOKE     GetDlgItemText, hdlg, 501, addr szBuff0, lengthof szBuff0
         INVOKE     lstrcat, addr szBuff0, addr szMenuN
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff0
         INVOKE     SetFocus, h502
            and     Cnt, 0

      .elseif eax == 602
            inc     Cnt
         INVOKE     GetDlgItemText, hdlg, 502, addr szBuff1, lengthof szBuff1
            mov     ecx, Cnt
           imul     ecx, 4
            inc     ecx
         INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
         INVOKE     lstrcat, addr szBuff0, addr szPopup
         INVOKE     lstrcat, addr szBuff0, addr szQuote
         INVOKE     lstrcat, addr szBuff0, addr szBuff1
         INVOKE     lstrcat, addr szBuff0, addr szQuote
         INVOKE     lstrcat, addr szBuff0, addr szCRLF
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff0
         INVOKE     SetFocus, h503

      .elseif eax == 603
            mov     ecx, Cnt
           imul     ecx, 4
            inc     ecx
         INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
         INVOKE     lstrcat, addr szBuff0, addr szBegin
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff0
         INVOKE     SetFocus, h503

      .elseif eax == 604
         INVOKE     GetDlgItemText, hdlg, 503, addr szBuff1, lengthof szBuff1
            mov     ecx, Cnt
           imul     ecx, 4
            add     ecx,5
         INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
         INVOKE     lstrcat, addr szBuff0, addr szMenuI
         INVOKE     lstrcat, addr szBuff0, addr szQuote
         INVOKE     lstrcat, addr szBuff0, addr szBuff1
         INVOKE     GetDlgItemText, hdlg, 504, addr szBuff1, lengthof szBuff1
         .if eax
            INVOKE     lstrcat, addr szBuff0, addr szSlashB
            INVOKE     lstrcat, addr szBuff0, addr szBuff1
         .endif
         INVOKE     lstrcat, addr szBuff0, addr szQuote
         INVOKE     lstrcat, addr szBuff0, addr szCS
         INVOKE     lstrlen, addr szBuff0
            mov     ecx, 45
         .if ecx > eax
               sub     ecx, eax
            INVOKE     lstrcpyn, addr szBuff1, addr szFill, ecx
         .endif
         INVOKE     lstrcat, addr szBuff0, addr szBuff1

         INVOKE     GetDlgItemText, hdlg, 505, addr szBuff1, lengthof szBuff1
         INVOKE     lstrcat, addr szBuff0, addr szBuff1
         INVOKE     GetDlgItemText, hdlg, 506, addr szBuff1, lengthof szBuff1
         .if eax
            INVOKE     lstrcat, addr szBuff0, addr szCS
            INVOKE     lstrcat, addr szBuff0, addr szBuff1
         .endif
         INVOKE     lstrcat, addr szBuff0, addr szCRLF
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff0
         INVOKE     SetDlgItemText, hdlg, 503, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 504, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 505, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 506, addr szNULL
         INVOKE     SetFocus, h503

      .elseif eax == 605
            mov     ecx, Cnt
           imul     ecx, 4
            add     ecx,5
         INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
         INVOKE     lstrcat, addr szBuff0, addr szSep
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff0
         INVOKE     SetFocus, h503

      .elseif eax == 606 && Cnt >= 1
            mov     ecx, Cnt
           imul     ecx, 4
            inc     ecx
         INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
         INVOKE     lstrcat, addr szBuff0, addr szEnd
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff0
         INVOKE     SetDlgItemText, hdlg, 502, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 503, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 504, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 505, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 506, addr szNULL
         INVOKE     SetFocus, h502
            dec     Cnt

      .elseif eax == 607
         INVOKE     lstrcpy, addr szBuff0, addr szEnd
         INVOKE     lstrcat, addr szBuff0, addr szCRLF
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff0
         INVOKE     SetDlgItemText, hdlg, 501, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 502, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 503, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 504, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 505, addr szNULL
         INVOKE     SetDlgItemText, hdlg, 506, addr szNULL
         INVOKE     SetFocus, hMenuN
            and     Cnt, 0
           call     ChkMatch

      .elseif eax == 608
           call     ChkMatch
         .if eax == -1
               jmp     MenuDone
         .endif
      .endif

MenuDone:
         mov     eax, FALSE           ; Return with FALSE

MenuRet:
         ret
MenuDlg ENDP

;=====================================================
; Create buttons PROCEDURE
;=====================================================
CreateButt  PROC hwnd:DWORD, dwEXStyle, dwStyle, szText, xP, yP, wS, hS, ID

          or     dwStyle, WS_CHILD or WS_VISIBLE
      INVOKE     CreateWindowEx, dwEXStyle, addr ButtClass, szText,
                 dwStyle,
                 xP, yP, wS, hS, hwnd, ID, hInst, NULL
         mov     ecx, eax
        push     eax
      INVOKE     SendMessage, ecx, WM_SETFONT, hFontS, TRUE
         pop     eax
         ret
CreateButt  ENDP

;=======================================
; Create, edit dialogs PROCEDURE
;=======================================
DialogDlg PROC  uses ebx esi edi hdlg:DWORD, wmsg, wparam, lparam
LOCAL    tbb:TBBUTTON
LOCAL    cm:COLORMAP
LOCAL    tm:TEXTMETRIC
LOCAL    pt:POINT
;LOCAL    size:SIZE
LOCAL    Crect:RECT
LOCAL    Erect:RECT
LOCAL    Frect:RECT
LOCAL    ID:DWORD, hTemp, Ypos, LenL, hReg, Cnt1, szData, Data, Base
LOCAL    szBuff[512]:BYTE, szBuff0[256]:BYTE, szBuff1[256]:BYTE

      .if wmsg == WM_INITDIALOG
          MOVmd     hDlg2, hdlg
            mov     Grid, 3
INVOKE     SendMessage, hDlg2, WM_SETFONT, hFontE, TRUE

         INVOKE     GetDC, hDlg2
            mov     hDC, eax
         INVOKE     SelectObject, hDC, hFontDlg
         INVOKE     GetTextMetrics, hDC, addr tm
         INVOKE     GetTextExtentPoint32, hDC, addr szTest, 62, addr pt
         INVOKE     ReleaseDC, hCtrl, hDC
            xor     edx, edx
            mov     eax, pt.x
            mov     ecx, 31
            div     ecx
            add     eax, 1
            xor     edx, edx
            mov     ecx, 2
            div     ecx
            mov     ConvX, eax
          MOVmd     ConvY, tm.tmHeight
           fild     ConvX
           fstp     TestUnitX1
           fild     ConvY
           fstp     TestUnitY1

            lea     eax, Dlg.ID
            mov     DlgStart, eax
            lea     ecx, Dlg.Style
            sub     ecx, eax
            mov     DlgStyle, ecx
            lea     ecx, Dlg.Class
            sub     ecx, eax
            mov     DlgClass, ecx
            lea     ecx, Dlg.LeftOrg
            sub     ecx, eax
            mov     DlgLeftOrg, ecx
            lea     ecx, Dlg.Code
            sub     ecx, eax
            mov     DlgCode, ecx
            lea     ecx, Dlg.Border
            sub     ecx, eax
            mov     DlgBorder, ecx
            lea     ecx, Dlg.CntType
            sub     ecx, eax
            mov     DlgCntType, ecx
            lea     ecx, Dlg.Handle
            sub     ecx, eax
            mov     DlgHandle, ecx

            lea     eax, Ctrls.ID
            mov     CtrlsStart, eax
            lea     ecx, Ctrls.Style
            sub     ecx, eax
            mov     CtrlsStyle, ecx
            lea     ecx, Ctrls.Left
            sub     ecx, eax
            mov     CtrlsLeft, ecx
            lea     ecx, Ctrls.LeftOrg
            sub     ecx, eax
            mov     CtrlsLeftOrg, ecx
            lea     ecx, Ctrls.Code
            sub     ecx, eax
            mov     CtrlsCode, ecx
            lea     ecx, Ctrls.Border
            sub     ecx, eax
            mov     CtrlsBorder, ecx
            lea     ecx, Ctrls.CntType
            sub     ecx, eax
            mov     CtrlsCntType, ecx
            lea     ecx, Ctrls.Handle
            sub     ecx, eax
            mov     CtrlsHandle, ecx

         INVOKE     CreateButt, hdlg, 0, BS_AUTOCHECKBOX, addr szMoveGrp, 10, 6, 124, 12, 610
            mov     hWndGrp, eax

         INVOKE     CreateButt, hdlg, 0, BS_AUTOCHECKBOX, addr szKeepSel, 10, 19, 124, 12, 611
            mov     hKeepSel, eax

         INVOKE     CreateButt, hdlg, 0, BS_AUTOCHECKBOX, addr szUseID, 10, 32, 124, 12, 612
            mov     hUseID, eax

         INVOKE     CreateButt, hdlg, 0, BS_AUTOCHECKBOX, addr szNoMove, 10, 44, 124, 15, 613
            mov     hNoMove, eax

         INVOKE     CreateButt, hdlg, 0, BS_PUSHBUTTON, addr szOption, 135, 6, 54, 15, 614

         INVOKE     CreateButt, hdlg, 0, BS_PUSHBUTTON, addr szAlign, 135, 24, 54, 15, 615

         INVOKE     CreateButt, hdlg, 0, BS_PUSHBUTTON, addr szSave, 135, 42, 54, 15, 616

;---------- [Create the dialog Combobox] ----------
         INVOKE     CreateWindowEx, 0, addr ComboClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_VSCROLL or\
                    CBS_HASSTRINGS or CBS_DROPDOWN or CBS_SORT or CBS_NOINTEGRALHEIGHT or WS_CLIPSIBLINGS,\
                    10, 61, 180, 210, hdlg, 97, hInst, NULL ;10, 58, 180, 210
            mov     hWndComboD, eax
         INVOKE     SendMessage, hWndComboD, WM_SETFONT, hFontL, TRUE
         INVOKE     SendMessage, hWndComboD, CB_SETITEMHEIGHT, -1, 14       ; Selection field
         INVOKE     SendMessage, hWndComboD, CB_SETITEMHEIGHT, 0, 13        ; List items
         INVOKE     SendMessage, hWndComboD, WM_SETTEXT, 0, addr szSelect

         INVOKE     CreateWindowEx, 0, 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_WRAPABLE or\
                    WS_BORDER or WS_CLIPSIBLINGS,\
                    18, 83, 164, 132, hdlg, NULL, hInst, NULL ;18, 83, 164, 106
            mov     hWndTool, eax

;         INVOKE     LoadBitmap, hInst, IDB_TOOL
   
            mov     cm.From, 00c0c0c0h
         INVOKE     GetSysColor, COLOR_BTNFACE
            mov     cm.To, eax
         INVOKE     CreateMappedBitmap, hInst, IDB_TOOL, 0, addr cm, 1 ;CMB_MASKED
            mov     hTBBmp, eax
         INVOKE     CreateMappedBitmap, hInst, IDB_TOOLS, 0, addr cm, 1
            mov     hTBBmpS, eax

         INVOKE     SendMessage, hWndTool, 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, hWndTool, TB_SETBITMAPSIZE, 0, ecx
            pop     ecx
         INVOKE     SendMessage, hWndTool, TB_SETBUTTONSIZE, 0, ecx
   
            mov     tbab.hInst, 0
           push     hTBBmp
            pop     tbab.nID
         INVOKE     SendMessage, hWndTool, TB_ADDBITMAP, 1, addr tbab ;23
   
;---------- [Create the Quick Code Toolbar structures] ----------
            mov     Cnt, 0
            mov     ID, 7501
         .while (Cnt < 30) ;24
               mov     ecx, Cnt
               mov     edx, ID
            TBButt     hWndTool, ecx, edx, 0
               inc     Cnt
               inc     ID
         .endw
            mov     pt.x, 5
            mov     pt.y, 1
         INVOKE     SendMessage, hWndTool, TB_SETROWS, addr pt , addr rect
         INVOKE     MoveWindow, hWndTool, 18, 83, 164, 132, TRUE ;18, 83, 164, 106

;---------- [Create the control Combobox] ----------
         INVOKE     CreateWindowEx, 0, addr ComboClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_VSCROLL or\
                    CBS_HASSTRINGS or CBS_DROPDOWN or CBS_SORT or\
                    CBS_NOINTEGRALHEIGHT or WS_CLIPSIBLINGS,\
                    10, 217, 180, 210, hdlg, 87, hInst, NULL ;10, 191, 180, 210
            mov     hWndCombo, eax
         INVOKE     SendMessage, hWndCombo, WM_SETFONT, hFontL, TRUE
         INVOKE     SendMessage, hWndCombo, CB_SETITEMHEIGHT, -1, 14       ; Selection field
         INVOKE     SendMessage, hWndCombo, CB_SETITEMHEIGHT, 0, 13        ; List items

;---------- [Create the Listbox] ----------
         INVOKE     CreateWindowEx, 0, addr ListboxClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER or WS_VSCROLL or\
                    LBS_HASSTRINGS or LBS_OWNERDRAWFIXED or LBS_NOTIFY or\
                    LBS_NOINTEGRALHEIGHT or WS_CLIPSIBLINGS or WS_CLIPCHILDREN,\
                    10, 239, 180, 198, hdlg, 88, hInst, 0  ;10, 213, 180, 213
            mov     hWndList, eax
;---------- [Control window subclassed] ----------
         INVOKE     SetWindowLong, hWndList, GWL_WNDPROC, ListBoxProc
            mov     lpListBox, eax

;---------- [Create the Listbox Edit] ----------
         INVOKE     CreateWindowEx, NULL, addr RichEdit, NULL,\
                    WS_CHILD or\
                    ES_NOHIDESEL or ES_SAVESEL or ES_AUTOHSCROLL,\
                    71, 0, 83, 14, hWndList, 84, hInst, NULL
            mov     hREditP, eax
;---------- [Control window subclassed] ----------
         INVOKE     SetWindowLong, hREditP, GWL_WNDPROC, REditP
            mov     SubREditP, eax
         INVOKE     SendMessage, hREditP, EM_SETBKGNDCOLOR, 0, 00ffffe0h

;---------- [Create the Listbox Button] ----------
         INVOKE     CreateWindowEx, NULL, addr ButtClass, NULL,
                    WS_CHILD or BS_PUSHBUTTON or BS_BITMAP or WS_CLIPCHILDREN,
                    91, 0, 14, 14, hWndList, 82, hInst, 0
            mov     hButtP, eax
         INVOKE     LoadImage, hInst, 8808, IMAGE_BITMAP, 14, 14, LR_LOADMAP3DCOLORS
            mov     hBmpB, eax
;---------- [Control window subclassed] ----------
         INVOKE     SetWindowLong, hButtP, GWL_WNDPROC, ControlButtP
            mov     SubBmpP, eax

;---------- [Create the Popup Listbox] ----------
         INVOKE     CreateWindowEx, 0, addr ListboxClass, 0, WS_POPUP or\
                    WS_BORDER or WS_VSCROLL or LBS_HASSTRINGS or\
                    LBS_NOTIFY or LBS_NOINTEGRALHEIGHT,
                    71, 0, 83, 100, hdlg, 0, hInst, 0
            mov     hListP, eax
;---------- [Control window subclassed] ----------
         INVOKE     SetWindowLong, hListP, GWL_WNDPROC, ListPopProc
            mov     lpListPop, eax

         INVOKE     SendMessage, hWndList, WM_SETFONT, hFontL, TRUE
         INVOKE     SendMessage, hWndList, LB_SETITEMHEIGHT, 0, 15      ; List items
         INVOKE     SendMessage, hREditP, WM_SETFONT, hFontE, TRUE
         INVOKE     SendMessage, hListP, WM_SETFONT, hFontL, TRUE
         INVOKE     SendMessage, hListP, LB_SETITEMHEIGHT, 0, 15        ; List items

         INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                    KEY_WRITE or KEY_READ, 0, addr hReg, addr lpdwDisp
            mov     lpcbData, 4
         INVOKE     RegQueryValueEx, hReg, addr szGridOn, 0, addr lpType, addr GridOn, addr lpcbData
            mov     lpcbData, 4
         INVOKE     RegQueryValueEx, hReg, addr szSnapOn, 0, addr lpType, addr SnapOn, addr lpcbData
            mov     lpcbData, 4
         INVOKE     RegQueryValueEx, hReg, addr szGrid, 0, addr lpType, addr Grid, addr lpcbData
           and     hPat, 0
         .if GridOn
            .if Grid == 2
                MOVmd     hPat, hPat2
            .elseif Grid == 3
                MOVmd     hPat, hPat3
            .elseif Grid == 4
                MOVmd     hPat, hPat4
            .elseif Grid == 6
                MOVmd     hPat, hPat6
            .endif
         .endif
            mov     lpcbData, 40
         INVOKE     RegQueryValueEx, hReg, addr szButD, 0, addr lpType, addr ddButD, addr lpcbData
         .if eax == ERROR_FILE_NOT_FOUND
              call     SetAllDefaults
         .endif

            lea     eax, offset szDlgD
            mov     szData, eax
            lea     eax, ddDlgD
            mov     Data, eax
            mov     Cnt1, 12
         .while (Cnt1)
               mov     lpcbData, 40
            INVOKE     RegQueryValueEx, hReg, szData, 0, addr lpType, Data, addr lpcbData
               add     szData, 7
               add     Data, 40
               dec     Cnt1
         .endw
         INVOKE     RegCloseKey, hReg

            jmp     DialogDone

;      .elseif wmsg == WM_SETCURSOR
;         INVOKE     SetFocus, hMenuN

      .elseif wmsg == WM_CTLCOLORLISTBOX || wmsg == WM_CTLCOLOREDIT
            mov     eax, lparam
         .if hBR
            INVOKE     DeleteObject, hBR
               and     hBR, 0
         .endif
         INVOKE     SetBkColor, wparam, 00ffffe0h
         INVOKE     SetTextColor, wparam, 0
         INVOKE     CreateSolidBrush, 00ffffe0h
            mov     hBR, eax
            ret

      .elseif wmsg == WM_DRAWITEM
         INVOKE     IsWindowVisible, hForm
         .if wparam == 88 && eax
               mov     esi, lparam
               lea     edi, dis
               mov     ecx, sizeof dis
               rep     movsb

            .if dis.itemID != -1
               INVOKE     SendMessage, hWndList, LB_GETTEXT, dis.itemID, addr szBuff
                  mov     LenL, eax
               INVOKE     GetTextMetrics, dis.hdc, addr tm
                  mov     eax, dis.rcItem.bottom
                  add     eax, dis.rcItem.top
                  sub     eax, tm.tmHeight
                  shr     eax, 1
                  dec     eax
                  mov     Ypos, eax
               .if (dis.itemState & ODS_SELECTED)
                  INVOKE     CreateSolidBrush, 00800000h      ; Highlight background color
                     mov     hBrush, eax
                    push     dis.rcItem.right
                     mov     dis.rcItem.right, 70
                  INVOKE     FillRect, dis.hdc, addr dis.rcItem, hBrush
                  INVOKE     SetTextColor, dis.hdc, 00ffffffh ; Highlight text color
                  INVOKE     SetBkColor, dis.hdc, 00800000h   ; Highlight text background color
                     pop     dis.rcItem.right

                    Call     GetCode

                     mov     eax, dis.itemID
                  .if byte ptr Code[eax] == 'e' || byte ptr Code[eax] == 't'
                        mov     ecx, dis.rcItem.right
                        sub     ecx, 71
                     INVOKE     SetWindowPos, hREditP, HWND_NOTOPMOST,\
                                71, dis.rcItem.top, ecx, 14, SWP_NOZORDER
                     INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr szBuffR
                     INVOKE     ShowWindow, hREditP, SW_SHOWDEFAULT

                  .elseif byte ptr Code[eax] == 'z'

                  .else
                        mov     ecx, dis.rcItem.right
                        sub     ecx, 71+14
                       push     ecx
                     INVOKE     SetWindowPos, hREditP, HWND_NOTOPMOST,\
                                71, dis.rcItem.top, ecx, 14, SWP_NOZORDER
                        pop     ecx
                        add     ecx, 71
                     INVOKE     SetWindowPos, hButtP, HWND_NOTOPMOST,\
                                ecx, dis.rcItem.top, 14, 14, SWP_NOZORDER
                     INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr szBuffR
                     INVOKE     ShowWindow, hREditP, SW_SHOWDEFAULT
                     INVOKE     ShowWindow, hButtP, SW_SHOWDEFAULT
                  .endif

               .else
                  INVOKE     ShowWindow, hREditP, SW_HIDE
                  INVOKE     ShowWindow, hButtP, SW_HIDE
                  INVOKE     ShowWindow, hListP, SW_HIDE

                  INVOKE     CreateSolidBrush, 00ffffe0h      ; Background color
                     mov     hBrush, eax
                  INVOKE     FillRect, dis.hdc, addr dis.rcItem, hBrush
                  INVOKE     SetTextColor, dis.hdc, 000000ffh ; Text color - dis.itemData
                  INVOKE     SetBkColor, dis.hdc, 00ffffe0h   ; Text background color
               .endif        
                  mov     dis.rcItem.left, 2
               INVOKE     TextOut, dis.hdc, dis.rcItem.left, Ypos, addr szBuff, LenL

                 call     GetCode

               .if eax                                        ; Valid text length
                     mov     LenL, eax
                  INVOKE     SetTextColor, dis.hdc, 0h        ; Text color - dis.itemData
                  INVOKE     SetBkColor, dis.hdc, 00ffffe0h   ; Highlight text background color
                     mov     dis.rcItem.left, 72
                  INVOKE     TextOut, dis.hdc, dis.rcItem.left, Ypos, addr szBuffR, LenL
               .endif

               INVOKE     DeleteObject, hBrush
               INVOKE     CreateSolidBrush, 00000000h         ; Frame color
                  mov     hBrush, eax

                  mov     dis.rcItem.left, -1
                  dec     dis.rcItem.top
                 push     dis.rcItem.right
                  mov     dis.rcItem.right, 70
               INVOKE     FrameRect, dis.hdc, addr dis.rcItem, hBrush
                  pop     dis.rcItem.right

                  inc     dis.rcItem.right
                  mov     dis.rcItem.left, 69
               INVOKE     FrameRect, dis.hdc, addr dis.rcItem, hBrush
                  inc     dis.rcItem.top
               INVOKE     DeleteObject, hBrush
            .endif
               mov     dis.itemState, ODS_DEFAULT
               mov     dis.hdc, 0
               mov     eax, 1
               ret
         .endif

      .elseif wmsg == WM_MOUSEMOVE && !hDef
         INVOKE     IsWindowVisible, hREditP
         .if eax
            INVOKE     SetFocus, hREditP
         .else
            INVOKE     GetFocus
            .if eax != hMenuN
;               INVOKE     SetFocus, hMenuN
            .endif
INVOKE     SetFocus, hWndTool ;hForm
         .endif

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

      .elseif wmsg != WM_COMMAND
            jmp     DialogDone
      .endif
         mov     eax, wparam
         and     eax, 0ffffh
         mov     ecx, wparam
         shr     ecx, 16

;---------- [Check the control combobox for control selection] ----------
      .if eax == 87 && ecx == CBN_SELCHANGE
         .if UpID                  ; Enter key was not pressed after change
              call     UpdateCtrl
         .endif

         INVOKE     SendMessage, hWndCombo, CB_GETCURSEL, 0, 0
         INVOKE     SendMessage, hWndCombo, CB_GETITEMDATA, eax, 0
            mov     edx, eax
            mov     ID, eax
            xor     eax, eax
            mov     ecx, ArrayCnt ;2048 ;1024 ;512 ;64
inc     ecx
         .while (ecx)                           ; Find handle of active control in the array
            .if hArray+[eax*8] == edx           ; Check for count & type
                  mov     edx, hArray+[eax*8+4] ; Extract handle
                  mov     hCtrl, edx
               .break
            .endif
               inc     eax
               dec     ecx
         .endw
         .if ecx
               mov     eax, ID
               and     eax, 0ffffh
               mov     CtrlType, eax

            .if CtrlType == 7501
               INVOKE     GetClientRect, hCtrl, addr Srect
               INVOKE     MoveGrabbers, 2, 0
;NOTE $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    MOVmd     hSMove, hCtrl
    MOVmd     CtrlHnd, hCtrl
      mov     SavCtrl, 7501
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

            .else
               .if CtrlType == 7503

                     xor     eax, eax
                     mov     edx, hCtrl
                     mov     ecx, GrpCnt ;32
                  .while (ecx)     ; Find handle of Groupbox parent in the array
                     .if hGrpArray[eax+4] == edx
                           mov     ecx, hGrpArray[eax]
                           mov     hGrp, ecx
                        .break  
                     .endif
                        add     eax, 8
                        dec     ecx
                  .endw

               .endif

    MOVmd     hSMove, hCtrl
    MOVmd     CtrlHnd, hCtrl
    MOVmd     SavCtrl, CtrlType

               INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234

               .if CtrlType == 7503
                  INVOKE     BringWindowToTop, hParent
               .endif

                  mov     eax, hParent
               .if eax == hGrp && CtrlType != 7503
                     mov     eax, xGrp
                     add     eax, SizeB
                     add     Srect.left, eax
                     mov     eax, yGrp
                     add     eax, SizeT
                     add     Srect.top, eax
               .endif
               .if CtrlType == 7509       ;Combobox
                     mov     eax, CBrect.bottom
;                     add     eax, 6
                     mov     ecx, Srect.top
                     mov     Srect.bottom, ecx
                     add     Srect.bottom, eax
                     sub     Srect.bottom, ecx
               .endif
               INVOKE     MoveGrabbers, 5, 0
            .endif
         .endif
         INVOKE     SetFocus, hForm
            jmp     DialogDone

      .elseif eax == 87 && ecx == CBN_CLOSEUP
         INVOKE     RedrawWindow, hWndList, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_UPDATENOW or RDW_ALLCHILDREN ;NO
         INVOKE     SetFocus, hForm
            jmp     DialogDone

;---------- [Check the dialog combobox for dialog selection] ----------
      .elseif eax == 97 && ecx == CBN_SELCHANGE
         .if UpID                  ; Enter key was not pressed after change
              call     UpdateCtrl
         .endif

            mov     IndexCnt, 0
         INVOKE     SendMessage, hWndCombo, CB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hWndList, LB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hWndComboD, CB_GETCURSEL, 0, 0
            mov     ecx, eax
           push     ecx
         INVOKE     SendMessage, hWndComboD, CB_GETLBTEXT, ecx, addr szBuff
            pop     ecx

           push     ecx
         INVOKE     SendMessage, hWndComboD, CB_GETITEMDATA, ecx, 0
           push     eax

         .if DlgOn
;---------- [Save the displayed dialog to memory and reset] ----------
            INVOKE     DialogDlg, hDlg2, WM_COMMAND, 616, 0
         .endif

            pop     hCtrl
            pop     ecx
         INVOKE     SendMessage, hWndComboD, CB_SETCURSEL, ecx, 0

         .if hForm
            INVOKE     ShowWindow, hForm, SW_HIDE
         .endif
          MOVmd     hForm, hCtrl
            mov     CtrlType, 7501
         .if hAsmEdit
               mov     ecx, hRetForm
               mov     eax, hForm
               mov     [ecx], eax
         .endif
         INVOKE     ShowWindow, hForm, SW_SHOW

;---------- [Create the grabber controls] ----------
         INVOKE     LoadGrabbers, hForm
         INVOKE     GetSizes, hForm

         INVOKE     GetWindowRect, hWnd, addr Prect
            mov     eax, ResB
            add     Prect.left, eax ;6
            mov     eax, ResT
            add     Prect.top, eax ;22
         INVOKE     GetWindowRect, hForm, addr Frect
            mov     eax, Frect.left
            sub     eax, Prect.left
            mov     xOff, eax
            mov     FormX, eax
            mov     eax, Frect.top
            sub     eax, Prect.top
            mov     yOff, eax
            mov     FormY, eax

         INVOKE     GetClientRect, hForm, addr Srect
         INVOKE     MoveGrabbers, 2, 0
            mov     DlgOn, 1
          MOVmd     hUnder, hWork
;INVOKE     SetParent, hGrpArray, hForm

            mov     CtrlType, 7501
            mov     dis.itemID, 0
;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
          MOVmd     IDCnt, StartID+[ebx*4+4]
           imul     ebx, StrSize
            add     ecx, ebx
            add     ecx, StrSize
            sub     ecx, 8
            mov     eax, dword ptr [ecx]    ; CntType
           push     eax
         INVOKE     SendMessage, hWndCombo, CB_ADDSTRING, 0, addr szBuff
            pop     ecx
           push     eax
         INVOKE     SendMessage, hWndCombo, CB_SETITEMDATA, eax, ecx  ; = CntType
            pop     eax
         INVOKE     SendMessage, hWndCombo, CB_SETCURSEL, eax, 0

            and     hSMove, 0
            and     CtrlHnd, 0
            and     SavCtrl, 0

;NOTE $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    MOVmd     hSMove, hForm
    MOVmd     CtrlHnd, hForm
      mov     SavCtrl, 7501
   INVOKE     SetFocus, hForm
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

            and     Len, 0
            mov     edx, hCtrl
          MOVmd     Cnt, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt

GetMore:
         .while (Cnt)                         ; Find handle of active control in the array
               mov     eax, Len
            .if hArray+[eax*8+4]              ; Check for valid handle
                  mov     ebx, hArray+[eax*8] ; Extract array count
                  mov     eax, ebx
                  and     eax, 0ffffh
                  mov     CtrlType, eax
                  shr     ebx, 16
               .if eax != 7501
                     inc     Len
                     dec     Cnt
                  .break
               .endif
            .endif
               inc     Len
               dec     Cnt
         .endw
         .if !Cnt
             MOVmd     hCtrl, hForm
               mov     CtrlType, 7501
               jmp     DialogDone
         .endif

;---------- [Get offset in the structure array] ----------
           push     ebx
         INVOKE     GetOffset, 1
            pop     ebx
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            add     ecx, StrSize
            mov     eax, dword ptr [ecx-4]    ; Matching parent handle
         .if eax == hCtrl
               mov     eax, dword ptr [ecx-8] ; = CntType
              push     eax
               sub     ecx, StrSize
               add     ecx, 4
            INVOKE     lstrcpy, addr szBuff, ecx
            INVOKE     SendMessage, hWndCombo, CB_ADDSTRING, 0, addr szBuff
               pop     ecx
            INVOKE     SendMessage, hWndCombo, CB_SETITEMDATA, eax, ecx  ; = CntType
         .endif
         .if Cnt
               jmp     GetMore
         .endif

      .elseif eax == 97 && ecx == CBN_CLOSEUP
         INVOKE     SetFocus, hForm
            jmp     DialogDone
      .endif

         mov     eax, wparam
        cwde

      .if eax == 610         ; Move Groupbox
         INVOKE     SendMessage, hWndGrp, BM_GETCHECK, 0, 0
         .if eax == BST_CHECKED
               mov     GroupOn, 1
         INVOKE     LoadCursor, 0, IDC_ARROW
         .else
               and     GroupOn, 0
         INVOKE     LoadCursor, 0, IDC_CROSS
         .endif
         INVOKE     SetClassLong, hGrp, GCL_HCURSOR, eax
         INVOKE     SetFocus, hMenuN

      .elseif eax == 611     ; Keep toolbar selection
         INVOKE     SendMessage, hKeepSel, BM_GETCHECK, 0, 0
         .if eax == BST_CHECKED
               mov     KeepOn, 1
         .else
            INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, CtrlType, FALSE
               and     InputType, 0
               and     KeepOn, 0
         .endif
         INVOKE     SetFocus, hMenuN

      .elseif eax == 612     ; Use num ID
         INVOKE     SendMessage, hUseID, BM_GETCHECK, 0, 0
         .if eax == BST_CHECKED
               mov     UseIDOn, 1
         .else
               and     UseIDOn, 0
         .endif
         INVOKE     SetFocus, hMenuN

      .elseif eax == 613     ; No move - size
         INVOKE     SendMessage, hNoMove, BM_GETCHECK, 0, 0
         .if eax == BST_CHECKED
               mov     NoMoveOn, 1
         .else
               and     NoMoveOn, 0
         .endif
         INVOKE     SetFocus, hMenuN

      .elseif eax == 614     ; Options dialog
         .if !hOpt && !hSizePos
            INVOKE     CreateDialogParam, hInst, 6000, hDlg2, offset OptionsProc, 0
            INVOKE     SetFocus, hMenuN
         .endif

      .elseif eax == 615     ; Alignment
         .if !hOpt && !hSizePos
            INVOKE     CreateDialogParam, hInst, 8000, hDlg2, offset OptionsProc, 42
            INVOKE     SetFocus, hMenuN
         .endif

      .elseif eax == 616     ; Save the dialog to memory
            mov     IndexCnt, 0
         .if hForm && hUnder && DlgOn
         .else
               jmp     DialogDone
         .endif
         .if hAsmEdit
               mov     ecx, hRetForm
               xor     eax, eax
               mov     [ecx], eax
         .endif

          MOVmd     hCtrl, hForm
            mov     CtrlType, 7501
            mov     dis.itemID, 4
;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
           imul     edx, 4
            add     ecx, edx
         INVOKE     lstrcpy, addr szBuff, ecx
            and     NoMsg, 0
         INVOKE     SendMessage, hWndComboD, CB_FINDSTRINGEXACT, -1, addr szBuff

         .if eax != CB_ERR && lparam != 1234        ; != CB_ERR Name already exsist
               jmp     NoAdd
         .elseif eax != CB_ERR && lparam == 1234    ; 1234 is from extract
              push     eax
            INVOKE     MessageBox, NULL, addr szError5, addr szBuff, MB_YESNO or MB_ICONWARNING
               pop     ecx
            .if eax == IDYES
                 push     ecx
               INVOKE     SendMessage, hWndComboD, CB_GETITEMDATA, ecx, 0

;---------- [Find dialog handle] ---------
DeleteHnd:
                  mov     edx, eax
                  and     Len, 0
                MOVmd     Cnt, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt
               .while (Cnt)
                     mov     eax, Len
                  .if hArray+[eax*8+4] == edx       ; Find handle
                        mov     hArray+[eax*8], 0   ; Clear cnt and ID
                        mov     hArray+[eax*8+4], 0 ; Clear handle
                     .if NoMsg
                           jmp     NoAdd
                     .else
                        .break
                     .endif
                  .endif
                     inc     Len
                     dec     Cnt
               .endw

;                  and     Len, 0
;                MOVmd     Cnt, TempACnt
;               .while (Cnt)
;                     mov     eax, Len
;                     mov     ecx, hTempA+[eax*8+4]
;                     mov     edx, hTempA+[eax*8]
;                     mov     ebx, ArrayCnt
;                     mov     hArray+[ebx*8+4], ecx    ; Save control handle
;                     mov     hArray+[ebx*8], edx      ; Save control type & cnt
;                     inc     ArrayCnt
;                     inc     Len
;                     dec     Cnt
;               .endw

                  pop     ecx
               INVOKE     SendMessage, hWndComboD, CB_DELETESTRING, ecx, 0
            .else
                  dec     DlgNum
                  mov     NoMsg, 1
                  mov     eax, hForm
                  jmp     DeleteHnd
            .endif
         .endif

;DSPValue hWnd, hForm, 1, 'm'
         INVOKE     SendMessage, hWndComboD, CB_ADDSTRING, 0, addr szBuff
           push     eax
         INVOKE     SendMessage, hWndComboD, CB_SETITEMDATA, eax, hForm
            pop     eax
         INVOKE     SendMessage, hWndComboD, CB_SETCURSEL, eax, 0
            add     Dlg.ID, 1000
            add     Dlg.StartID, 1000

NoAdd:
         INVOKE     ShowWindow, hREditP, SW_HIDE
         INVOKE     ShowWindow, hButtP, SW_HIDE
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, CtrlType, FALSE
            and     InputType, 0  ; Note reset the toolbar buttoms
            and     CtrlType, 0
            and     DlgOn, 0
            and     hUnder, 0
            and     CtrlOn, 0
            and     IDCnt, 0

         INVOKE     SetFocus, hMenuN
         INVOKE     ShowWindow, hForm, SW_HIDE
         INVOKE     SendMessage, hWndCombo, CB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hWndList, LB_RESETCONTENT, 0, 0
         INVOKE     RedrawWindow, hWndList, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_UPDATENOW or RDW_ALLCHILDREN
            jmp     DialogDone

      .elseif eax == 620     ; Grid On/Off
         .if !GridOn
               and     hPat, 0
         .endif
         .if hBRP
            INVOKE     DeleteObject, hBRP
         .endif
         INVOKE     CreatePatternBrush, hPat
            mov     hBRP, eax
         .if hPat && hBRP
            INVOKE     SetClassLong, hForm, GCL_HBRBACKGROUND, eax
         .else
            INVOKE     SetClassLong, hForm, GCL_HBRBACKGROUND, COLOR_BTNFACE+1 ;COLOR_WINDOW+1 ;COLOR_BTNFACE+1
         .endif
         .if hForm
            INVOKE     RedrawWindow, hForm, 0, 0,\
                       RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_UPDATENOW or RDW_ALLCHILDREN
         .endif
      .endif

         mov     eax, wparam
        cwde

;---------- [Control selection] ----------
      .if eax > 7500 && eax < 7530 ;7525   ; Controls Toolbar
           push     eax
            mov     Cnt, 7501
         .while (Cnt < 7531)
               mov     ecx, lparam
            .if ecx == hWndTool
               INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, Cnt, FALSE
            .endif
               inc     Cnt
         .endw
            pop     eax

         .if eax == 7513 && ToolOn || eax == 7514 && StatusOn
               and     InputType, 0
               jmp     DialogDone
         .endif

            mov     InputType, eax
            mov     ecx, lparam
         .if ecx == hWndTool
            INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, eax, TRUE
            INVOKE     SetFocus, hMenuN
         .endif
      .endif
      .if InputType == 7501 && DlgOn || InputType > 7501 && !DlgOn
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, InputType, FALSE
            and     InputType, 0
            jmp     DialogDone
      .endif

         mov     ecx, lparam
         mov     eax, wparam
        cwde
      .if eax == 7530 && ecx == hWndTool && ecx == 44448888

            mov     rect.left, 12
            mov     rect.top, 170 ;76 ;2 ;34
            mov     rect.right, 115
            mov     rect.bottom, 12
         INVOKE     MapDialogRect, hDlg2, addr rect

; Unit to pixel
;left   = (left   * baseunitX) / 4
;top    = (top    * baseunitY) / 8 
;right  = (right  * baseunitX) / 4
;bottom = (bottom * baseunitY) / 8

; Pixel to unit
;left   = (left   * 4) / baseunitX
;top    = (top    * 8) / baseunitY 
;right  = (right  * 4) / baseunitX
;bottom = (bottom * 8) / baseunitY

      .endif

         jmp     DialogDone

DialogDone:
         mov     eax, FALSE

DialogRet:
         ret
DialogDlg ENDP

;=====================================================
; ExtractID PROCEDURE
;=====================================================
ExtractID PROC  uses ebx esi edi TypeCtrl:DWORD
LOCAL    ft:FINDTEXT
LOCAL    cr:CHARRANGE
LOCAL    tr:TEXTRANGE
LOCAL    szBuff0[64]:BYTE, szBuff2[64]:BYTE

      .if TypeCtrl == 7501
            and     Dlg.ID, 0
      .else
            and     Ctrls.ID, 0
      .endif

;         and     TempACnt, 0

      .if SaveLimit
          MOVmd     ft.chrg.cpMax, SaveLimit
            jmp     Pass
      .endif

         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
      INVOKE     lstrcpyn, addr szBuff0, addr szDefine, 8
         lea     eax, szBuff0
         mov     ft.lpstrText, eax

LoopIt1:
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax != -1
            inc     eax
            mov     ft.chrg.cpMin, eax
            jmp     LoopIt1
      .else
            lea     eax, offset szCR
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax != -1
               add     eax, 4
               mov     ft.chrg.cpMax, eax
               mov     SaveLimit, eax
         .endif
      .endif

Pass:
         mov     ft.chrg.cpMin, 0
      INVOKE     lstrcpyn, addr szBuff0, addr szDefine, 8
         lea     eax, szBuff0
         mov     ft.lpstrText, eax
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax != -1
            mov     ft.chrg.cpMin, eax

         .if TypeCtrl == 7501
               lea     eax, offset Dlg.lpName

         .else
               lea     eax, offset Ctrls.lpName
         .endif
            mov     ft.lpstrText, eax

LoopIt2:
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN or\
                    FR_WHOLEWORD or FR_MATCHCASE, addr ft
         .if eax != -1
               mov     ft.chrg.cpMin, eax
               mov     tr.chrg.cpMin, eax
               mov     tr.chrg.cpMax, eax
            INVOKE     lstrlen, ft.lpstrText
               inc     eax
               add     tr.chrg.cpMax, eax
              push     eax
               dec     tr.chrg.cpMin
               lea     eax, szBuff0
               mov     tr.lpstrText, eax
            INVOKE     SendMessage, hREdit, EM_GETTEXTRANGE, 0, addr tr
               pop     eax

            .if byte ptr szBuff0 == ' ' && byte ptr szBuff0[eax] == ' ' ||\
                byte ptr szBuff0 == ' ' && byte ptr szBuff0[eax] == 9h ||\
                byte ptr szBuff0 == 9h && byte ptr szBuff0[eax] == 9h ||\
                byte ptr szBuff0 == 9h && byte ptr szBuff0[eax] == ' '
            .else
                MOVmd     ft.chrg.cpMin, tr.chrg.cpMax
                  inc     ft.chrg.cpMin
                  jmp     LoopIt2
            .endif

               lea     eax, offset szSpace
               mov     ft.lpstrText, eax
            INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
            .if eax != -1
                  mov     tr.chrg.cpMin, eax
                  mov     ft.chrg.cpMin, eax
                  lea     eax, offset szCR
                  mov     ft.lpstrText, eax
               INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
               .if eax != -1
                     mov     tr.chrg.cpMax, eax
                     lea     eax, szBuff0
                     mov     tr.lpstrText, eax
                  INVOKE     SendMessage, hREdit, EM_GETTEXTRANGE, 0, addr tr

                     mov     byte ptr szBuff2, 0
                     mov     ecx, tr.chrg.cpMax
                     sub     ecx, tr.chrg.cpMin
                     xor     esi, esi
                     xor     edi, edi
                  .while (ecx)
                        mov     al, byte ptr szBuff0[esi]
                     .if al > 2fh && al < 3ah
                           mov     byte ptr szBuff2[edi], al
                           mov     byte ptr szBuff2[edi+1], 0
                           inc     edi
                     .endif
                        inc     esi
                        dec     ecx
                  .endw
                  INVOKE     AsciiBase, addr szBuff2, 10
                  .if TypeCtrl == 7501
                        mov     Dlg.ID, eax
                  .else
                        mov     Ctrls.ID, eax
                  .endif
               .endif
            .endif
         .endif
      .endif

         ret
ExtractID ENDP

;=======================================
; Convert base units to pixels PROCEDURE
;=======================================
UnitToPixel PROC
LOCAL    Base:DWORD

comment^
         xor     eax, eax
         mov     ecx, 4
      .while (ecx)
          finit
           fild     rect.left[eax*4]
         .if ecx == 2 || ecx == 4
               fld     BaseUnitX
         .else
               fld     BaseUnitY
         .endif
           fmul     ST(0), ST(1)
          fistp     rect.left[eax*4]
            inc     eax
            dec     ecx
      .endw
ret
^
         xor     eax, eax
         mov     ecx, 4
      .while (ecx)
          finit
          fldcw     CWNoRound         ; No rounding mode.
           fild     rect.left[eax*4]
         .if ecx == 2 || ecx == 4
              push     Base4
               pop     Base
               fld     TestUnitX1
         .else
              push     Base8
               pop     Base
               fld     TestUnitY1
         .endif
           fmul     ST(0), ST(1)
           fild     Base              ; Load base
           fxch     ST(1)
          fdivr
            fld     Round
           fadd     ST(0), ST(1)
          fistp     rect.left[eax*4]
            inc     eax
            dec     ecx
      .endw

         ret
UnitToPixel ENDP

;=======================================
; Convert pixels to base units PROCEDURE
;=======================================
PixelToUnit PROC
LOCAL    Base:DWORD

         xor     eax, eax
         mov     ecx, 4
      .while (ecx)
          finit
          fldcw     CWNoRound         ; No rounding mode.
           fild     rect.left[eax*4]
         .if ecx == 2 || ecx == 4
              push     Base4
               pop     Base
         .else
              push     Base8
               pop     Base
         .endif
           fild     Base              ; Load base
           fmul     ST(0), ST(1)
         .if ecx == 2 || ecx == 4
               fld     TestUnitX1
         .else
               fld     TestUnitY1
         .endif
           fxch     ST(1)
          fdivr
            fld     Round
           fadd     ST(0), ST(1)
          fistp     rect.left[eax*4]
            inc     eax
            dec     ecx
      .endw

         ret
PixelToUnit ENDP

;=======================================
; GetString procedure
;=======================================
GetString PROC dlg:DWORD
LOCAL    Seax:DWORD, BlankOn, QuoteOn, Base, CntOn

      .if !HaveDlg && !dlg
            ret
      .endif

      pushad
         mov     Base, 2
         and     sPos, 0
         and     Seax, 0
         and     CntOn, 0
         and     TextLen, 0
         and     BlankOn, 0
         and     QuoteOn, 0
         mov     esi, pMemM
         mov     edi, hString
         xor     ebx, ebx
         mov     dl, byte ptr [esi+eax]
         mov     byte ptr [edi+ebx], dl
         inc     ebx
         inc     eax

         mov     ecx, BytesOut
      .while (ecx)
         .if byte ptr [esi+eax-1] == '_' || byte ptr [esi+eax-1] == '"'
               jmp     Doit
         .elseif dword ptr [esi+eax] == 'LAID' && word ptr [esi+eax+4] == 'GO' &&\
             byte ptr [esi+eax-1] == ' '
         .elseif dword ptr [esi+eax] == 'TPAC'
         .elseif dword ptr [esi+eax] == 'TNOF'
         .elseif dword ptr [esi+eax] == 'LYTS'
         .elseif dword ptr [esi+eax] == 'TSXE'
         .elseif dword ptr [esi+eax] == 'SALC' && byte ptr [esi+eax+4] == 'S'
         .elseif dword ptr [esi+eax] == 'IGEB'
         .elseif byte ptr [esi+eax] == 'E' && byte ptr [esi+eax+1] == 'N' &&\
                 byte ptr [esi+eax+2] == 'D'
         .elseif dword ptr [esi+eax] == 'TNOC'
         .elseif dword ptr [esi+eax] == 'XETL' || dword ptr [esi+eax] == 'XETR' ||\
                 dword ptr [esi+eax] == 'XETC'
         .elseif dword ptr [esi+eax] == 'UORG'
         .elseif dword ptr [esi+eax] == 'IDAR' && byte ptr [esi+eax-4] != 'A' ||\
                 dword ptr [esi+eax+1] == 'ROTU'
         .elseif dword ptr [esi+eax] == 'CEHC' && byte ptr [esi+eax-4] != 'A' ||\
                 dword ptr [esi+eax+1] == 'COTU'
         .elseif dword ptr [esi+eax] == 'PFED' ||\
                 dword ptr [esi+eax] == 'HSUP' && byte ptr [esi+eax-3] != 'D'
         .elseif dword ptr [esi+eax] == 'TIDE'
         .elseif dword ptr [esi+eax] == 'BMOC'
         .elseif dword ptr [esi+eax] == 'TSIL'
         .elseif dword ptr [esi+eax] == 'ORCS'
         .elseif dword ptr [esi+eax] == 'MTIB' || dword ptr [esi+eax] == 'NOCI'
         .else

Doit:
;LTEXT "If you select \"Web Site\", WinZip will launch your web browser to 
;connect to the WinZip web site.", -1, 6, 42, 181, 16

               mov     edi, hString
               mov     dl, byte ptr [esi+eax]
            .if dl == '"'
                  inc     QuoteOn
               .if !TextLen
                  mov     CntOn, 1
                  mov     sPos, eax
               .endif
            .endif

            .if dl == ' '
                  mov     BlankOn, 1
            .endif
            .if dl != ' ' && dl != '"' && dl != 0ah && dl != 0dh && BlankOn
               .if !TextLen
                  mov     CntOn, 1
                  mov     sPos, eax
                  dec     sPos
.if !FontOn
mov     TextLen, 2   ; Bitmap or Icon
.endif
               .endif
            .endif

            .if dl == ',' && QuoteOn
                 push     edx
                 push     eax
                  xor     edx, edx
                  mov     eax, QuoteOn
                  div     Base
                  pop     eax
               .if edx
                     pop     edx
;                     mov     byte ptr [esi+eax], '^'
                     mov     dl, '^'
               .else
                     pop     edx
               .endif
            .endif
 
            .if dl == ',' && QuoteOn > 1 ||  dl == ',' && BlankOn
                  and     QuoteOn, 0
and     CntOn, 0
            .endif
.if CntOn || FontOn && sPos && dl > 0dh
      inc     TextLen
.endif
;            .if dl != 0ah && dl != 0dh && dl != '\'
;                  mov     byte ptr [edi+ebx], dl
;                  inc     ebx
;            .if dl == '\' && QuoteOn
            .if dl == '\' && byte ptr [esi+eax+1] != 0dh && QuoteOn
                  mov     byte ptr [edi+ebx], dl
                  inc     ebx
            .elseif dl != 0ah && dl != 0dh && dl != '\'
                  mov     byte ptr [edi+ebx], dl
                  inc     ebx
            .else
               .if CntOn
                     mov     byte ptr [esi+eax], '^'
               .else
                     mov     byte ptr [esi+eax], ' '
               .endif
               .if dl == 0dh
                  mov     Seax, eax
               .endif
            .endif
               jmp     DoMore
         .endif

         .if byte ptr [esi+eax-1] != ' ' && byte ptr [esi+eax-1] != 0ah && byte ptr [esi+eax-1] != '^'
               jmp     Doit
         .endif

            mov     byte ptr [edi+ebx], 0dh
            mov     byte ptr [edi+ebx+1], 0
         .if Seax
               mov     eax, Seax
               mov     byte ptr [esi+eax], 0dh
               mov     byte ptr [esi+eax+1], 0ah
         .endif
;.if DlgNum == 1
;DSPValue hWnd, TextLen, 1, 't'
;INVOKE     MessageBox, NULL, edi, addr AppName, MB_OK
;.endif
         .break

DoMore:
            dec     ecx
            inc     eax
      .endw

       popad

         ret

GetString ENDP

;=====================================================
; Add missing BEGIN and/or END dialog statements PROCEDURE
;=====================================================
Fixit PROC  uses ebx esi edi
LOCAL    ft:FINDTEXT
LOCAL    tr:TEXTRANGE
LOCAL    szBuff0[64]:BYTE

         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
         lea     eax, offset szError
         mov     ft.lpstrText, eax

      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN or FR_MATCHCASE, addr ft
      .if eax != -1
            mov     ft.chrg.cpMin, eax
         INVOKE     lstrlen, addr szError
            add     ft.chrg.cpMin, eax
            lea     eax, offset szDIALOG
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN or FR_MATCHCASE, addr ft
         .if eax != -1
               mov     ft.chrg.cpMin, eax
               mov     tr.chrg.cpMin, eax
               mov     tr.chrg.cpMax, eax
               mov     ft.chrg.cpMax, eax
            .if eax > 32
                  sub     tr.chrg.cpMin, 32
            .else
                  jmp     GotIt
            .endif
               lea     eax, szBuff0
               mov     tr.lpstrText, eax
            INVOKE     SendMessage, hREdit, EM_GETTEXTRANGE, 0, addr tr
               mov     edx, tr.chrg.cpMax
               mov     eax, 32
               mov     ecx, 32
            .while (ecx)
               .if byte ptr szBuff0[eax] == 0dh
                  INVOKE     SendMessage, hREdit, EM_SETSEL, edx, edx
                  INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szFixit
                  INVOKE     RichEditProc, hREdit, WM_PAINT, 0, 0
                  .break
               .endif
                  dec     eax
                  dec     ecx
                  dec     edx
            .endw
         .else

GotIt:
            .if DlgNum == 1
                  mov     edx, BytesOut
                  dec     edx
               INVOKE     SendMessage, hREdit, EM_SETSEL, edx, edx
               INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szFixit
            .endif
         .endif
      .endif

         ret
Fixit ENDP

;=====================================================
; Validate PROCEDURE
;=====================================================
Validate PROC  uses ebx esi edi
LOCAL    Cnt1:DWORD, FoundB, FoundE
LOCAL    szBuff0[64]:BYTE

         mov     byte ptr szBuff0, 0
         mov     byte ptr szError, 0
      INVOKE     lstrcpy, hError, addr szNULL
         mov     esi, pMemM
         mov     edi, hError
         xor     eax, eax
         xor     ebx, ebx
         mov     ecx, BytesOut
      .while (ecx)
         .if byte ptr [esi+eax] == 9h   ; Tab stop
               mov     byte ptr [esi+eax], ' '
         .endif
         .if dword ptr [esi+eax] == 'LAID' && word ptr [esi+eax+4] == 'GO' &&\
             byte ptr [esi+eax-1] == ' '
            .if szBuff0
               .if !FoundB || !FoundE
                  pushad
                  INVOKE     lstrcat, addr szError, addr szBuff0
                    call     Fixit
                   popad
               .endif
            .endif
               mov     byte ptr szBuff0, 0
               and     FoundB, 0
               and     FoundE, 0
               jmp     DoDialog

         .elseif dword ptr [esi+eax] == 'IGEB' ;&& byte ptr [esi+eax-1] != ';'
               mov     FoundB, 1
               jmp     DoMore

         .elseif byte ptr [esi+eax] == 'E' && byte ptr [esi+eax+1] == 'N' &&\
                 byte ptr [esi+eax+2] == 'D' ;&& byte ptr [esi+eax-1] != ';'
               mov     FoundE, 1
               jmp     DoMore

DoDialog:
;---------- [Get the dialog name] ----------
              push     eax

Loop1:
            .if byte ptr [esi+eax] != 0ah && eax
                  dec     eax
                  jmp     Loop1
            .endif
            .if eax
                  inc     eax
            .endif

               mov     Cnt, 63
               xor     edx, edx
            .while (Cnt)
                  mov     bl, byte ptr [esi+eax]
               .if bl != 0dh
                     mov     byte ptr szBuff0[edx], bl
                     mov     byte ptr szBuff0[edx+1], 0
                     inc     edx
               .else
                  .break
               .endif
                  dec     Cnt
                  inc     eax
            .endw
            .if byte ptr szBuff0 == ';'
                  mov     byte ptr szBuff0, 0
            .endif
               pop     eax
               inc     DlgNum
               jmp     DoMore

         .endif

DoMore:
            dec     ecx
            inc     eax
      .endw
            .if szBuff0
               .if !FoundB || !FoundE
                  INVOKE     lstrcat, addr szError, addr szBuff0
                    call     Fixit
               .endif
            .endif

         ret
Validate ENDP

;=====================================================
; ErrorList PROCEDURE
;=====================================================
ErrorList PROC hdlg:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_CLOSE
         INVOKE     DestroyWindow, hdlg
            mov     eax, TRUE
            ret
      .endif

         mov     eax, FALSE
         ret
ErrorList ENDP

;=======================================
; ExtractDlg Dialog
;=======================================
ExtractDlg PROC  uses ebx esi edi  hdlg:DWORD, wmsg, wparam, lparam
LOCAL    EditS:EDITSTREAM
LOCAL    ft:FINDTEXT
LOCAL    tr:TEXTRANGE
LOCAL    tvi:TV_ITEM
LOCAL    Trect:RECT
LOCAL    Num:DWORD, CapOn, StaticOn, sw7, sw8, sw9, tAddr
LOCAL    Len1:DWORD, Len2, Cnt1, Cnt2, QuoteOn, SavRight, SavBottom
LOCAL    szBuff0[512]:BYTE, szBuff1[10]:BYTE, szCode[32]:BYTE, SaveCode[5]:BYTE, SaveName[32]:BYTE
LOCAL    szCodeT[32]:BYTE, szWork[64]:BYTE

      .if wmsg == WM_INITDIALOG
          MOVmd     hDlg3, hdlg
         INVOKE     GetDlgItem, hdlg, 402
            mov     hStatic402, eax
         INVOKE     GetDlgItem, hdlg, 403
            mov     hStatic403, eax
         INVOKE     GetDlgItem, hdlg, 703
            mov     hWndTree, eax
         INVOKE     GetDlgItem, hdlg, 404
            mov     hStatic404, eax
         INVOKE     GetDlgItem, hdlg, 704
            mov     hEdit704, eax
         INVOKE     ShowWindow, hStatic402, SW_HIDE
         INVOKE     ShowWindow, hStatic403, SW_HIDE
         INVOKE     ShowWindow, hWndTree, SW_HIDE
         INVOKE     GetDlgItem, hdlg, 602      ; Extract All Of The Dialogs
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 603      ; Extract A Selected Dialog
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 604      ; Save The Resource File
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 605      ; Clear All Dialogs From Memory
         .if !ArrayCnt
            INVOKE     EnableWindow, eax, 0
         .else
            INVOKE     EnableWindow, eax, 1
         .endif
         INVOKE     GetMenuItemCount, hFMenu   ; Get count of items in the sub menu
            inc     eax
            mov     MenuCnt, eax               ; Menu count for ProcessMRUFiles
         INVOKE     ProcessMRUFiles, hDlg3, 1, MenuCnt, 0, addr szRedit, hFMenu

      .elseif wmsg == WM_NOTIFY
         .if wparam == 703                     ; Treeview
               mov     eax, lparam
               mov     ebx, (NM_TREEVIEW ptr[eax]).hdr.code
               mov     ecx, (NM_TREEVIEW ptr[eax]).itemNew.hItem

            .if ebx == TVN_SELCHANGED
                 test     (NM_TREEVIEW ptr[eax]).action, TVIS_FOCUSED
                   jz     ExtractDone
                  mov     tvi.hItem, ecx
                  mov     tvi.imask, TVIF_TEXT or TVIF_PARAM or TVIF_CHILDREN
                  lea     eax, szWork
                  mov     tvi.pszText, eax
                  mov     tvi.cchTextMax, 64
               INVOKE     SendMessage, hWndTree, TVM_GETITEM, NULL, addr tvi
                  mov     eax, tvi.cChildren
               .if eax
                     jmp     ExtractDone
               .endif

;---------- [Close image if open] ----------
               .if hImage
                  INVOKE     SendMessage, hImage, WM_COMMAND, 405, 0
               .endif

;---------- [Release the picture if open] ----------
               .if ipPicture
                     mov     eax, ipPicture
                    push     eax
                     mov     edx, dword ptr[eax]
                    call     dword ptr[edx+8]             ; ipPicture->Release()
                  INVOKE     DeleteObject, hBitmap
                     and     ipPicture, 0
                  INVOKE     RedrawWindow, hREdit, 0, 0, RDW_INVALIDATE or RDW_ERASE
               .endif

                  mov     ecx, tvi.lParam
                  mov     esi, RsrcInfo                   ; Resource array
                  mov     OffPosID, ecx                   ; Save Resource array offset
                  mov     eax, dword ptr[esi+ecx+8]       ; Actual address of the resource
                  mov     SavAddr, eax
                  mov     eax, dword ptr[esi+ecx+12]      ; Size of resource
                  mov     RsrcSize, eax
                  mov     eax, dword ptr[esi+ecx]

;---------- [Check resource type] ----------
               .if eax == 0
                  INVOKE     RsrcMisc
               .elseif eax == 1
                  INVOKE     RsrcCursorIcon
               .elseif eax == 2
                  INVOKE     RsrcBitmap
               .elseif eax == 3
                  INVOKE     RsrcCursorIcon
               .elseif eax == 12
                  INVOKE     RsrcGrpImages                ; Grp Cursor
               .elseif eax == 14
                  INVOKE     RsrcGrpImages                ; Grp Icon
               .elseif eax == 21
                  INVOKE     RsrcAnimate
               .elseif eax == 22
                  INVOKE     RsrcAnimate
               .endif
            .endif
         .endif
            jmp     ExtractDone

      .elseif wmsg != WM_COMMAND
            jmp     ExtractDone
      .endif

         mov     eax, wparam
        cwde

        push     eax
      .if eax > 600 && eax < 606 || eax == 607
         .if hImage
            INVOKE     SendMessage, hImage, WM_COMMAND, 405, 0
         .endif
         .if ipPicture
               mov     eax, ipPicture
              push     eax
               mov     edx, dword ptr[eax]
              call     dword ptr[edx+8]          ; ipPicture->Release()
            INVOKE     DeleteObject, hBitmap
               and     ipPicture, 0
            INVOKE     RedrawWindow, hREdit, 0, 0, RDW_INVALIDATE or RDW_ERASE
         .endif
      .endif

      .if eax > 600 && eax < 606 ;|| eax == 607
         INVOKE     SetDlgItemInt, hdlg, 701, 0, 0
         INVOKE     SetDlgItemInt, hdlg, 702, 0, 0
      .endif
         pop     eax

      .if eax == 601   ; Select A Resource File
         .if hImage
            INVOKE     SendMessage, hImage, WM_COMMAND, 405, 0
         .endif
         INVOKE     ShowWindow, hStatic402, SW_HIDE
         INVOKE     ShowWindow, hStatic403, SW_HIDE
         INVOKE     ShowWindow, hWndTree, SW_HIDE

         INVOKE     GetWindowRect, hdlg, addr rect
            mov     ecx, lparam        ; x/y pos of window
            mov     edx, ecx
            and     edx, 0000ffffh     ; edx = LOWORD(lparam) = x pos
            shr     ecx, 16            ; ecx = HIWORD(lparam) = y pos
            mov     edx, rect.left
            mov     ecx, rect.top
            add     edx, 14
            add     ecx, 105
         INVOKE     TrackPopupMenu, hFMenu, TPM_LEFTALIGN or TPM_LEFTBUTTON,\
                    edx, ecx, 0, hdlg, addr rect

;            and     SaveLimit, 0
;            mov     sw3, 1
;            mov     IDStart, 1000
;         INVOKE     SetFocus, hMenuN
;           call     OpenFileA
;         INVOKE     SetFocus, hREdit
;         INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
;         .if eax
;            INVOKE     GetDlgItem, hdlg, 602
;            INVOKE     EnableWindow, eax, 1
;            INVOKE     GetDlgItem, hdlg, 604
;            INVOKE     EnableWindow, eax, 1
;         .endif

      .elseif eax == 3002    ; From open on popup menu
            mov     sw3, 1

DoOpen:
            and     SaveLimit, 0
            mov     IDStart, 1000
         INVOKE     SetFocus, hMenuN
           call     OpenFileA
         INVOKE     SetFocus, hREdit
         INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
         .if eax
            INVOKE     GetDlgItem, hdlg, 602
            INVOKE     EnableWindow, eax, 1
            INVOKE     GetDlgItem, hdlg, 604
            INVOKE     EnableWindow, eax, 1
         .endif

      .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     sw3, 4
            jmp     DoOpen

      .elseif eax == 602 || eax == 603
         .if eax == 602
               and     sw8, 0
         .else
               mov     sw8, 9
         .endif
         INVOKE     SetCurrentDirectory, addr PathName

         .if DlgOn
;---------- [Save the displayed dialog to memory and reset] ----------
            INVOKE     DialogDlg, hDlg2, WM_COMMAND, 616, 0
         .endif

            and     NameOn, 0
         INVOKE     IsDlgButtonChecked, hDlg3, 606
         .if eax
               mov     NameOn, 1
         .endif

; or WS_VISIBLE
         INVOKE     CreateWindowEx, 0, addr RichEdit, 0, WS_POPUP or ES_MULTILINE or\
                    WS_HSCROLL or WS_VSCROLL,\
                    100, 100, 300, 400, 0, 0, hInst, 0
            mov     hStyles, eax
         INVOKE     SendMessage, hStyles, EM_EXLIMITTEXT, 0, 50000
            mov     sw3, 3
           call     OpenFileA

;            add     IDStart, 1000
;            mov     eax, IDStart
;            mov     Dlg.ID, eax
;            inc     eax
;            mov     Dlg.StartID, eax

         .if wparam == 603   ; Selection
             MOVmd     tr.chrg.cpMin, sPos
             MOVmd     tr.chrg.cpMax, sPos
               add     tr.chrg.cpMax, 200
               lea     eax, szBuff0
               mov     tr.lpstrText, eax

            INVOKE     SendMessage, hREdit, EM_SETSEL, sPos, sPos
            INVOKE     GetDlgItem, hdlg, 603
            INVOKE     EnableWindow, eax, 0

            INVOKE     SendMessage, hREdit, EM_GETTEXTRANGE, 0, addr tr
               mov     byte ptr SaveName, 0
               mov     sw8, 9
               mov     ecx, eax
               xor     eax, eax
               xor     ebx, ebx
            .while (ecx)
                  mov     dl, byte ptr szBuff0[eax]
               .if dl != ' ' && sw8 == 9 ;!sw8
                     mov     byte ptr SaveName[ebx], dl
                     mov     byte ptr SaveName[ebx+1], 0
                     inc     ebx
               .else
                     mov     sw8, 1
               .endif
               .if dword ptr szBuff0[eax] == 'LAID' && word ptr szBuff0[eax+4] == 'GO' &&\
                   byte ptr szBuff0[eax-1] == ' '
                     inc     sw8
                  .break
               .endif
                  inc     eax
                  dec     ecx
            .endw
            .if sw8 != 2
;                  mov     NoMsg, 1
                  jmp     GetOut
            .endif
         .endif

            mov     BytesOut, 2000000
         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
            mov     BytesOut, eax   ; eax = bytes written
            and     Dlg.ExStyle, 0
            and     Dlg.Style, 0
            and     Dlg.Class, 0
;            and     SaveLimit, 0
            and     HexCode, 0
            and     HaveDlg, 0
            and     DlgNum, 0
            and     CtrlNum, 0
            and     StatCnt, 0
            and     ErrorOn, 0
            and     LinitReached, 0
            and     sw4, 0
         INVOKE     lstrcpy, hError, addr szNULL

         .if wparam == 602 || wparam == 603
              call     Validate
            .if szError
                  and     HoldM, 0
               INVOKE     SendMessage, hREdit, EM_STREAMOUT, SF_TEXT, addr EditS
                  mov     BytesOut, eax   ; eax = bytes written
            .endif
         .endif

            and     DlgNum, 0
            xor     eax, eax
            xor     edi, edi

         .while (BytesOut)
            .if LinitReached
                  jmp     AllDone ;GetOut
            .endif
               and     CapOn, 0
               mov     edx, pMemM
            .if dword ptr [edx+eax] == 'LAID' && word ptr [edx+eax+4] == 'GO' &&\
                byte ptr [edx+eax-1] == ' '
                  mov     HexCode, 1
mov     InputType, 7501
                  jmp     DoDialog
            .elseif dword ptr [edx+eax] == 'TPAC' && HexCode
                  mov     CapOn, 1
               INVOKE     GetString, 1
                  add     HexCode, 2
                  jmp     DoCaption
            .elseif dword ptr [edx+eax] == 'TNOF' && HexCode
                  mov     FontOn, 1
                  and     CapOn, 0
               INVOKE     GetString, 1
                  add     HexCode, 4
                  jmp     DoFont
            .elseif dword ptr [edx+eax] == 'LYTS' && HexCode
                  and     CapOn, 0
                  add     HexCode, 8
                  mov     sw4, 2
                  mov     sw5, 1
                  jmp     DoStyle
            .elseif dword ptr [edx+eax] == 'TSXE' && HexCode
                  and     CapOn, 0
                  add     HexCode, 16
                  mov     sw5, 2
                  jmp     DoEXStyle
            .elseif dword ptr [edx+eax] == 'SALC' && word ptr [edx+eax+4] == ' S'
                  jmp     DoClass
            .elseif dword ptr [edx+eax] == 'IGEB' && HexCode > 7
                  add     HexCode, 32
                  jmp     DoBegin
            .elseif byte ptr [edx+eax] == 'E' && byte ptr [edx+eax+1] == 'N' &&\
                    byte ptr [edx+eax+2] == 'D' && HexCode > 7
                  and     HexCode, 0
                  and     HaveDlg, 0
                  mov     StatCnt, 0 ;20
                  and     sw4, 0
               .if sw8 == 3
                     jmp     AllDone
               .endif
            .elseif dword ptr [edx+eax] == 'TNOC' && HexCode > 7
               INVOKE     GetString, 0
                  jmp     DoControl
            .elseif dword ptr [edx+eax] == 'XETL' || dword ptr [edx+eax] == 'XETR' ||\
                    dword ptr [edx+eax] == 'XETC'
                  mov     InputType, 7502
                  jmp     DoConvert
            .elseif dword ptr [edx+eax] == 'UORG' && byte ptr [edx+eax-1] != '_'
                  mov     InputType, 7503
                  jmp     DoConvert
            .elseif dword ptr [edx+eax] == 'IDAR' || dword ptr [edx+eax+1] == 'ROTU'
                  mov     InputType, 7504
                  jmp     DoConvert
            .elseif dword ptr [edx+eax] == 'CEHC' || dword ptr [edx+eax+1] == 'COTU'
                  mov     InputType, 7505
                  jmp     DoConvert
;            .elseif dword ptr [edx+eax] == 'TTUB'
            .elseif dword ptr [edx+eax] == 'PFED' ||\
                    dword ptr [edx+eax] == 'HSUP' && byte ptr [edx+eax-3] != 'D' ;||\
;                    dword ptr [edx+eax+1] == 'HSUP'
                  mov     InputType, 7506
                  jmp     DoConvert
            .elseif dword ptr [edx+eax] == 'TIDE'
                  mov     InputType, 7507
                  jmp     DoConvert
            .elseif dword ptr [edx+eax] == 'BMOC'
                  mov     InputType, 7509
                  jmp     DoConvert
            .elseif dword ptr [edx+eax] == 'TSIL'
                  mov     InputType, 7510
                  jmp     DoConvert
            .elseif dword ptr [edx+eax] == 'ORCS'
                  mov     InputType, 7515
                  jmp     DoConvert
            .elseif dword ptr [edx+eax] == 'MTIB' || dword ptr [edx+eax] == 'NOCI'
                  mov     InputType, 7502 ;7523
                  jmp     DoConvert

            .else

                  jmp     DoMore

DoDialog:
;---------- [Get the dialog name] ----------
                 push     eax
                  and     HaveDlg, 0

Loop1:
               .if byte ptr [edx+eax] != 0ah && eax

                  .if byte ptr [edx+eax] == ';'
                        and     HexCode, 0
                        pop     eax
                        mov     edx, pMemM
                        jmp     DoMore
                  .endif
   
                     dec     eax
                     jmp     Loop1
               .endif
   
               .if eax
                     inc     eax
               .endif
                  mov     ecx, 32
                  xor     edi, edi
               .while (ecx)
                     mov     bl, byte ptr [edx+eax]
   
                  .if bl != ' '
                        mov     byte ptr szBuff0[edi], bl
                        mov     byte ptr szBuff0[edi+1], 0
                        inc     edi
                  .else
                     .if sw8 == 2
                        INVOKE     lstrcmp, addr SaveName, addr szBuff0
                        .if eax != 0
                              pop     eax
                              mov     edx, pMemM
and     HexCode, 0

                              jmp     DoMore
                        .endif
                           mov     sw8, 3
                     .endif
                     INVOKE     lstrcpy, addr Dlg.lpName, addr szBuff0
                     INVOKE     ExtractID, 7501
                        pop     eax
                        mov     edx, pMemM
                     .break
                  .endif
                     dec     ecx
                     inc     eax
               .endw
   
DoPosSize:
;---------- [Get the position and size] ----------
               .while (BytesOut)
                  .if byte ptr [edx+eax] == ','
                    .break
                  .endif
                     inc     eax
                     dec     BytesOut
               .endw
   
Loop2:
               .if byte ptr [edx+eax-1] != ' ' && byte ptr [edx+eax-1] != ','
                     dec     eax
                     inc     BytesOut
                     jmp     Loop2
               .endif
                  mov     Len, eax
.if BytesOut > 63
                  mov     Cnt, 64 ;32
.else
    MOVmd     Cnt, BytesOut
.endif
                  xor     edi, edi
                  and     Num, 0
   
               .while (Cnt)
                     mov     eax, Len

Loop2A:
                  .if byte ptr [edx+eax] == ' '
                        inc     eax
                        inc     Len
                        dec     Cnt
                        dec     BytesOut
                        jmp     Loop2A
                  .endif
                     mov     bl, byte ptr [edx+eax]
                      
                  .if bl != ',' &&  bl != ' ' && bl != 0dh && bl != ';'
                        mov     byte ptr szBuff0[edi], bl
                        mov     byte ptr szBuff0[edi+1], 0
                        inc     edi
                  .else
                     INVOKE     AsciiBase, addr szBuff0, 10
                        mov     edx, Num
                        mov     rect.left[edx*4], eax
                        mov     edx, pMemM
                        xor     edi, edi
                        inc     Num
                     .if Num == 4
                        .break
                     .endif
                  .endif
                     inc     Len
                     dec     Cnt
                     dec     BytesOut
               .endw
                  mov     eax, Len
                  mov     edx, pMemM
               .if sw4 == 4
                     and     sw4, 0
                     jmp     RetPS
               .elseif sw4 == 8
                     and     sw4, 0
                     jmp     RetConvert3
               .else
                  and     sw4, 0
                  jmp     DoMore
               .endif

DoCaption:
;FONT 8, "MS Shell Dlg"

;---------- [Get the caption or font] ----------

               .if sw4 != 8 && !FontOn  ; sw4 = 8 is from DoConvert
                     sub     BytesOut, 8
                     add     eax, 8
               .elseif !FontOn
                     mov     ebx, Cnt
inc     ebx
                     sub     BytesOut, ebx
                     add     eax, ebx
                  .if InputType > 7506
                        mov     byte ptr szBuff0, 0
                        mov     Len, eax
                        jmp     WriteText ;NoCaption
                  .endif
               .endif

Commt:
                  mov     Len, eax
                  mov     ecx, 32
               .while (ecx)
                  .if byte ptr [edx+eax] == 0ah
                        mov     eax, Len
                        jmp     PressOn
                  .elseif byte ptr [edx+eax] == ';'
                        mov     eax, Len
                     .while (BytesOut)
                        .if byte ptr [edx+eax] == 0dh
                              mov     sw4, 2
                              jmp     DoMore
                        .endif
                           inc     eax
                           dec     BytesOut
                     .endw
   
                  .endif
                     dec     eax
                     dec     ecx
               .endw
                  mov     eax, Len

; CapOn = dlg caption
; FontOn = dlg font

PressOn:
;xor     ecx, ecx
;mov     cl, byte ptr [edx+eax]
;DSPValue hWnd, ecx, 1, 'm'
;mov     cl, byte ptr [edx+eax+1]
;DSPValue hWnd, ecx, 1, 'm'

;FONT 8, "MS Shell Dlg", 0, TRUE

               .if FontOn
                     mov     Len, eax
                     mov     ecx, sPos
                     sub     ecx, eax
                     add     Len, ecx
                     sub     BytesOut, ecx
                     and     TextLen, 0
                     and     sPos, 0
                     mov     ecx, 64
                     mov     eax, Len
                  .while (ecx)
                     .if byte ptr [edx+eax] != ' ' && byte ptr [edx+eax] > 0dh
                        .if !sPos
                              mov     sPos, eax
                        .endif
                     .elseif byte ptr [edx+eax] == 0dh
                        .break
                     .endif
                     .if !sPos
                           dec     BytesOut
                     .endif
                     .if sPos
                           inc     TextLen
                     .endif
                        inc     eax
                        dec     ecx
                  .endw
                     mov     eax, sPos
                     mov     Len, eax

;DSPValue hWnd, eax, 1, 'm'
;DSPValue hWnd, sPos, 1, 'm'
;DSPValue hWnd, TextLen, 1, 'm'
;xor     ecx, ecx
;mov     cl, byte ptr [edx+eax]
;DSPValue hWnd, ecx, 1, 'm'
;mov     cl, byte ptr [edx+eax+1]
;DSPValue hWnd, ecx, 1, 'm'
;mov     cl, byte ptr [edx+eax+2]
;DSPValue hWnd, ecx, 1, 'm'

               .endif

               .if byte ptr [edx+eax] == '"' && byte ptr [edx+eax+1] == '"' &&\
                   byte ptr [edx+eax+2] != '"' && byte ptr [edx+eax-1] != '"' ||\
                   byte ptr [edx+eax] == '"' && byte ptr [edx+eax+1] == ' ' && byte ptr [edx+eax+2] == '"'
                     mov     byte ptr szBuff0, 0
                     mov     Len, eax
                     jmp     WriteText
               .endif

               .if CapOn
                     and     sw4, 0
                     sub     TextLen, 4
                     dec     BytesOut
                     inc     eax
               .elseif FontOn
                     and     sw4, 0
;                     add     TextLen, 1 ;3
               .else
                     sub     TextLen, 2
                     dec     BytesOut
                     inc     eax
               .endif
                  mov     Len, eax
                  mov     ecx, TextLen
                  xor     edi, edi
.if ecx > 7fffh
xor     ecx, ecx
.endif

.if InputType != 7501
inc     sPos
mov     eax, sPos
sub     eax, Len
add     Len, eax
sub     BytesOut, eax
.endif

               .if !ecx
                     mov     byte ptr szBuff0, 0
               .endif
               .while (ecx)
                     mov     eax, Len
                     mov     bl, byte ptr [edx+eax]
                  .if bl != '^'
                        mov     byte ptr szBuff0[edi], bl
                        mov     byte ptr szBuff0[edi+1], 0
                        inc     edi
                  .endif
                     inc     Len
                     dec     ecx
                     dec     BytesOut
               .endw

                  mov     ecx, 8
               .while (ecx)
                     mov     eax, Len
                     mov     bl, byte ptr [edx+eax]
                  .if bl == ',' || bl == 0dh
                     .break
                  .endif
                     inc     Len
                     dec     ecx
                     dec     BytesOut
               .endw

WriteText:
                  INVOKE     lstrlen, addr szBuff0
                  .if eax > 510
                     INVOKE     lstrcpyn, addr szBuff0, addr szBuff0, 511
                  .endif
                  .if CapOn
                     INVOKE     lstrcpy, addr Dlg.lpCaption, addr szBuff0
                  .elseif FontOn
                     INVOKE     lstrcpy, addr Dlg.lpFont, addr szBuff0
                  .elseif sw4 == 3 || sw4 == 8
                     INVOKE     lstrcpy, addr Ctrls.lpCaption, addr szBuff0
                  .endif
;.if InputType == 7501 && DlgNum < 5
;INVOKE     MessageBox, NULL, addr szBuff0, addr AppName, MB_OK
;.endif

                     and     FontOn, 0
                  .if CapOn
                        mov     sw4, 2
                  .endif

                  mov     eax, Len
                  mov     edx, pMemM
               .if sw4 == 3
                     and     sw4, 0
                     jmp     RetCtrl
               .endif
               .if sw4 == 8
                     and     sw4, 0
                     jmp     RetConvert1
               .endif

                  and     sw4, 0
                  jmp     DoMore

DoFont:
                  mov     sw4, 2
;                  add     BytesOut, 3
;                  sub     eax, 3
                  jmp     DoCaption

DoStyle:
               INVOKE     GetString, 1

;---------- [Get the style or EXstyle] ----------
                  mov     Len, eax
                  mov     ecx, 32
               .while (ecx)
                  .if byte ptr [edx+eax] == 0ah
                        mov     eax, Len
                        sub     BytesOut, 5
                        add     eax, 5
                        jmp     Loop4
                  .elseif byte ptr [edx+eax] == ';'
                        mov     eax, Len
                        add     eax, 5
                        sub     BytesOut, 5
                        jmp     DoMore
                  .endif
                     dec     eax
                     dec     ecx
               .endw
                  mov     eax, Len

                  sub     BytesOut, 5
                  add     eax, 5

Loop4:
               .if byte ptr [edx+eax] == ' '
                     inc     eax
                     dec     BytesOut
                     jmp     Loop4
               .endif
   
                  mov     Len, eax

               .if word ptr [edx+eax] == 'x0'
               .elseif byte ptr [edx+eax+2] == '_'
                     xor     edi, edi
                     mov     ecx, 512 ;64
                  .while (ecx)
                        mov     bl, byte ptr [edx+eax]
                     .if bl != 0dh && bl != ';'
                           mov     byte ptr szBuffR[edi], bl
                           mov     byte ptr szBuffR[edi+1], 0
                           inc     edi
                     .else
                        .break
                     .endif
                        inc     eax
                        dec     ecx
                        dec     BytesOut
                  .endw
                     mov     Len, eax

                  .if ecx
;INVOKE     MessageBox, NULL, addr szBuffR, addr AppName, MB_OK
                       call     ParseStyle
                     .if eax
                           jmp     ExtractStyle
                     .endif
                  .endif
                     mov     eax, Len
                     jmp     DoMore
   
               .else
                     mov     eax, Len
                     jmp     DoMore
               .endif

                  add     eax, 2
                  mov     Len, eax
                  sub     BytesOut, 2
                  mov     Cnt, 32
                  xor     edi, edi
               .while (Cnt)
                     mov     eax, Len
                     mov     bl, byte ptr [edx+eax]
                  .if bl != 0dh && bl != ' ' && bl != ';' && bl != '^'
                        mov     byte ptr szBuff0[edi], bl
                        mov     byte ptr szBuff0[edi+1], 0
                        inc     edi
                  .else
                        mov     Len, eax
;INVOKE     MessageBox, NULL, addr szBuff0, addr AppName, MB_OK
                     INVOKE     AsciiBase, addr szBuff0, 16

ExtractStyle:
                     .if sw5 != 2
                           mov     Dlg.Style, eax
;                           mov     Dlg.ExStyle, 0
                     .else
                           mov     Dlg.ExStyle, eax
                     .endif
                     .break
                  .endif
                     inc     Len
                     dec     ecx
                     dec     BytesOut
               .endw
                  mov     eax, Len
                  mov     edx, pMemM
                  jmp     DoMore

DoEXStyle:
                  sub     BytesOut, 2
                  add     eax, 2
                  jmp     DoStyle

DoClass:
;---------- [Get the Class] ----------
                  mov     Len, eax
                  mov     ecx, 32
               .while (ecx)
                  .if byte ptr [edx+eax] == 0ah
                        mov     eax, Len
                        sub     BytesOut, 5
                        add     eax, 5
                        jmp     Loop6
                  .elseif byte ptr [edx+eax] == ';'
                        mov     eax, Len
                        add     eax, 5
                        sub     BytesOut, 5
                        jmp     DoMore
                  .endif
                     dec     eax
                     dec     ecx
               .endw
                  mov     eax, Len
                  mov     edx, pMemM
                  jmp     DoMore

Loop6:
               .if byte ptr [edx+eax] == ' ' || byte ptr [edx+eax] == '"'
                     inc     eax
                     dec     BytesOut
                     jmp     Loop6
               .endif
   
                  mov     Len, eax
                  mov     byte ptr Dlg.Class, 0
                  xor     edi, edi
                  mov     ecx, 32
               .while (ecx)
                     mov     bl, byte ptr [edx+eax]
                  .if bl != 0dh && bl != '"' && bl != ';'
                        mov     byte ptr Dlg.Class[edi], bl
                        mov     byte ptr Dlg.Class[edi+1], 0
                        inc     edi
                  .else
                     .break
                  .endif
                     inc     eax
                     dec     ecx
                     dec     BytesOut
               .endw
                  mov     Len, eax
                  mov     edx, pMemM
                  jmp     DoMore


DoBegin:
;---------- [C R E A T E  T H E  D I A L O G] ----------
                 push     eax
               .if sw8 == 0 || sw8 == 3
               .else
                     jmp     ByPass
               .endif
                  mov     HaveDlg, 1
;DSPValue hWnd, rect.bottom, 1, 'm'
                MOVmd     SavRight, rect.right
                MOVmd     SavBottom, rect.bottom
                  xor     ebx, ebx
                  mov     ecx, 4
               .while (ecx)
                   MOVmd     Dlg.LeftOrg[ebx*4], rect.left[ebx*4]
                     inc     ebx
                     dec     ecx
               .endw
                  mov     Dlg.Chg, 0
               .if !ConvertOn
                  INVOKE     MapDialogRect, hDlg2, addr rect
               .else
                    call     UnitToPixel
               .endif

;DSPValue hWnd, rect.bottom, 1, 'm'
               .if !rect.right
                     mov     rect.right, 200
               .endif
               .if !rect.bottom
                     mov     rect.bottom, 150
               .endif

                  mov     eax, ResB
                  add     rect.right, 6 ;eax
                  mov     eax, ResT
                  add     rect.bottom, 22 ;eax
                  mov     eax, Dlg.ExStyle
               .if !(eax & WS_EX_TOOLWINDOW)
                     add     rect.bottom, 3
               .endif
;DSPValue hWnd, rect.bottom, 1, 'm'
               INVOKE     GetWindowRect, hWork, addr Prect
                  mov     eax, Prect.left
                  add     rect.left, eax
                  mov     eax, Prect.top
                  add     rect.top, eax

                  mov     eax, rect.left
                  sub     eax, Prect.left
                  mov     FormX, eax
                  mov     eax, rect.top
                  sub     eax, Prect.top
                  mov     FormY, eax

                  mov     InputType, 7501
                  mov     sw44, 1
                  inc     DlgNum
;DSPValue hWnd, DlgNum, 1, 't'
               INVOKE     SetDlgItemInt, hdlg, 701, DlgNum, 0
               INVOKE     UpdateWindow, hdlg

               .if NameOn && !Dlg.ID
                  .if byte ptr Dlg.lpName > 2fh && byte ptr Dlg.lpName < 3ah
                     INVOKE     lstrcpy, addr szBuff1, addr Dlg.lpName
                     INVOKE     AsciiBase, addr szBuff1, 10
                        mov     Dlg.ID, eax
                        xor     eax, eax
                      MOVmd     tAddr, TextArray[eax*4]
                     INVOKE     BaseAscii, DlgNum, addr szBuff1, 2, 10, 1, 1, 0
                     INVOKE     lstrcpy, addr szBuff0, tAddr
                     INVOKE     lstrcat, addr szBuff0, addr szBuff1
                     INVOKE     lstrcpy, addr Dlg.lpName, addr szBuff0
                  .else
                        mov     eax, Dlg.StartID
                        dec     eax
                        mov     Dlg.ID, eax
                  .endif
               .endif

               INVOKE     CreateControls, hWork, 0

;---------- [Create the grabber controls] ----------
               INVOKE     LoadGrabbers, hForm
               INVOKE     GetSizes, hForm
               INVOKE     GetClientRect, hForm, addr Srect
               INVOKE     MoveGrabbers, 2, 0

                  mov     DlgOn, 1
                MOVmd     hUnder, hWork
                  and     StaticOn, 0
                  and     sw44, 0
                  and     sw5, 0
                  and     CapOn, 0
                  mov     byte ptr Dlg.lpCaption, 0
                  mov     Dlg.ExStyle, 0
               INVOKE     DialogDlg, hDlg2, WM_COMMAND, 616, 1234

ByPass:
                  pop     eax
                  mov     edx, pMemM

                  jmp     DoMore

DoControl:
.if !HaveDlg
      jmp     DoMore
.endif
                  mov     byte ptr SaveCode, 0
                  mov     sw4, 3
                  jmp     DoCaption

;    CONTROL "Find Next", IDC_BUTT01, "button", 0x54010000, 158, 2, 42, 11, 0x00000000

RetCtrl:
                  mov     ecx, 64 ;32
                  xor     edi, edi
               .while (ecx)
                     mov     bl, byte ptr [edx+eax]

;    CONTROL "Fi&nd what:", -1, "static", SS_LEFT, 4, 9, 48, 8

                  .if bl == 2dh   ; -1 static
                        inc     StatCnt
                       push     eax
                       push     ebx
                     INVOKE     BaseAscii, StatCnt, addr szBuff1, 2, 10, 1, 1, 0
                     .if InputType == 7502
                           mov     StaticOn, 1
                        INVOKE     lstrcpy, addr szBuff0, addr szSta
                           mov     byte ptr szCode, 's'
                     .elseif InputType == 7503
                        INVOKE     lstrcpy, addr szBuff0, addr szSta ;szGrp
                           mov     byte ptr szCode, 'b'
                     .elseif InputType == 7507
                        INVOKE     lstrcpy, addr szBuff0, addr szSta ;szEdit
                           mov     byte ptr szCode, 'e'
                     .else
.if SaveCode   ;N O T E !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
                           mov     StaticOn, 1
.endif
                        INVOKE     lstrcpy, addr szBuff0, addr szSta
                           mov     byte ptr szCode, 's'
                     .endif
                     INVOKE     lstrcat, addr szBuff0, addr szBuff1
                        mov     byte ptr szCode+1, 0
                        pop     ebx
                        pop     eax
                        mov     bl, ' '
                        mov     edi, 1
                  .endif

                  .if bl != '"' && bl != ',' && bl != ' ' && bl != ':'
                        mov     byte ptr szBuff0[edi], bl
                        mov     byte ptr szBuff0[edi+1], 0
                        inc     edi
                  .elseif edi
                       push     eax
                     INVOKE     lstrcpy, addr Ctrls.lpName, addr szBuff0
                     INVOKE     ExtractID, 0
                        pop     eax
                        mov     edx, pMemM
                     .break
                  .endif
                     dec     ecx
                     dec     BytesOut
                     inc     eax
               .endw
               .if sw4 == 8
                     jmp     RetConvert2
               .endif
                  and     sw4, 0
;    CONTROL "Find Next", IDC_BUTT01, "button", 0x54010000, 158, 2, 42, 11, 0x00000000
;    CONTROL "Fi&nd what:", -1, "static", SS_LEFT, 4, 9, 48, 8

Loop5:
               .if byte ptr [edx+eax] != '"'
                     inc     eax
                     dec     BytesOut
                     jmp     Loop5
               .endif
                  inc     eax
                  dec     BytesOut
                  mov     ecx, 32
                  xor     edi, edi
               .while (ecx)
                  .if byte ptr [edx+eax] != '"'
                        mov     bl, byte ptr [edx+eax]
                        mov     byte ptr szCode[edi], bl
                        mov     byte ptr szCode[edi+1], 0
                        inc     edi
                  .else
                     .break
                  .endif
                     dec     ecx
                     dec     BytesOut
                     inc     eax
               .endw
                  and     sw4, 0

;---------- [Get the control style] ----------
DoCtrlStyle:

;    CTEXT           "D",IDC_STATIC,24,29,8,8,NOT WS_GROUP
;    PUSHBUTTON      "Edx",29022,54,131,20,8,BS_CENTER | NOT WS_TABSTOP

                  mov     ecx, 32
               .while (ecx)
                  .if word ptr [edx+eax] == 'x0'
                        sub     BytesOut, 2
                        add     eax, 2
                        mov     ecx, 8
                        xor     edi, edi
                     .while (ecx)
                           mov     bl, byte ptr [edx+eax]
.if bl == ','
      mov     bl, '0'
   .while (ecx)
      mov     byte ptr szBuff0[edi], bl
      mov     byte ptr szBuff0[edi+1], 0
      inc     edi
      dec     ecx
   .endw
   .break
.endif
                           mov     byte ptr szBuff0[edi], bl
                           mov     byte ptr szBuff0[edi+1], 0
                           inc     edi
                           inc     eax
                           dec     ecx
                           dec     BytesOut
                     .endw
                     .break
   
         .elseif dword ptr [edx+eax] == ' TON'
            .while (ecx)
               .if byte ptr [edx+eax] == '_'
                  .break
               .endif
                  inc     eax
                  dec     ecx
                  dec     BytesOut
            .endw

                  .elseif byte ptr [edx+eax] == '_'
;---------- [Is not hex style] ----------
                        mov     Len, eax

GoBack:
                     .if byte ptr [edx+eax-1] != ' ' && byte ptr [edx+eax-1] != ','
                           dec     eax
                           dec     Len
                           inc     BytesOut
                           jmp     GoBack
                     .endif
                        xor     edi, edi
                        mov     ecx, 256 ;64
                     .while (ecx)
                           mov     bl, byte ptr [edx+eax]
                        .if bl != ',' && bl != 0dh
                              mov     byte ptr szBuffR[edi], bl
                              mov     byte ptr szBuffR[edi+1], 0
                              inc     edi
                        .else
                           .break
                        .endif
                           inc     eax
                           dec     ecx
                           dec     BytesOut
                     .endw
                        mov     Len, eax
   
                     .if ecx
                          call     ParseStyle
                        .if eax
                              jmp     MoveIt
                        .endif
                     .endif
                        mov     eax, Len
                        jmp     DoMore
   
                  .elseif StaticOn
                        mov     Len, eax
                        mov     eax, 50000100h
.if sw4 == 8
      xor     eax, eax
.endif
                        mov     Ctrls.ExStyle, 0
.if sw4 != 9 && sw4 != 8
                        and     sw4, 0
.endif
                        jmp     MoveIt

                  .elseif byte ptr [edx+eax] == 0dh
;---------- [No EXStyle] ----------
                        mov     Len, eax
                        xor     eax, eax
                        jmp     MoveIt
   
                  .endif
                     dec     ecx
                     dec     BytesOut
                     inc     eax
               .endw
                  mov     Len, eax
               INVOKE     AsciiBase, addr szBuff0, 16
   
MoveIt:
               .if sw4 != 3 && sw4 != 8
                  .if sw4 == 9 && InputType == 7502 ||\
                      sw4 == 0 && byte ptr szBuffR == 'S' && byte ptr szBuffR+1 == 'S'
                     .if !eax
                            or     eax, WS_CHILD or WS_VISIBLE or SS_NOTIFY
                     .else
                            or     eax, SS_NOTIFY
                     .endif
                  .endif
   
                  .if !eax
                         or     eax, WS_CHILD or WS_VISIBLE
                  .endif
   
                     mov     Ctrls.Style, eax
               .else
                     mov     Ctrls.ExStyle, eax
               .endif
                  mov     eax, Len
                  mov     edx, pMemM
               .if sw4 == 3 || sw4 == 8 || StaticOn && sw4 != 9
                     jmp     BuildCtrl
               .endif
               .if sw4 == 9
                     jmp     RetConvert4
               .endif

DoPosSizeC:
;---------- [Get the control position and size] ----------
                  mov     ecx, 48 ;12
               .while (ecx)
                  .if byte ptr [edx+eax] == ','
                        inc     eax
                        dec     ecx
                        dec     BytesOut
                     .while (ecx)
                        .if byte ptr [edx+eax] == ','
                           .break
                        .endif
                           inc     eax
                           dec     ecx
                           dec     BytesOut
                     .endw
                     .break
                  .endif
                     inc     eax
                     dec     ecx
                     dec     BytesOut
               .endw

               .if sw4 != 8
                     mov     sw4, 4
               .endif
                  jmp     DoPosSize

RetPS:
                  mov     ecx, 32
                  mov     sw4, 3
                  jmp     DoCtrlStyle

DoConvert:
               .if !HaveDlg || !HexCode
                     jmp     DoMore
               .endif

               INVOKE     GetString, 0

                 push     eax
   
                  mov     bl, byte ptr [edx+eax]
                  mov     byte ptr SaveCode, bl

                  mov     edx, pMemM
                  mov     ecx, 20 ;10
                  and     Cnt, 0
               .while (ecx)
                  .if byte ptr [edx+eax] == ' ' || byte ptr [edx+eax] == 0ah
                        mov     ebx, 20 ;10
                        sub     ebx, ecx
                        inc     eax
                        mov     ecx, 20
                     .while (ecx)
                        .if byte ptr [edx+eax] != ' ' && byte ptr [edx+eax] != '"'
                              inc     eax
                              dec     ecx
                              inc     Cnt
                        .else
                           .break
                        .endif
                     .endw
                     .break
                  .endif
                     dec     eax
                     dec     ecx
               .endw
                  pop     eax

               .if !Cnt
                     jmp     DoMore
               .endif
                  sub     Cnt, ebx
                  inc     Cnt
                  mov     sw4, 8
                  jmp     DoCaption

RetConvert1:
                  mov     sw4, 8
                  jmp     RetCtrl

RetConvert2:
                  mov     sw4, 8
                  jmp     DoPosSizeC

RetConvert3:
                  mov     sw4, 9
                  jmp     DoCtrlStyle

RetConvert4:
                  mov     sw4, 8
                  jmp     DoCtrlStyle

BuildCtrl:

;---------- [C R E A T E  T H E  C O N T R O L S] ----------

                 push     eax
   mov     byte ptr Ctrls.Class, 0
               .if sw4 == 8
                     jmp     FromConvert
               .endif

      INVOKE     lstrcpy, addr szCodeT, addr szCode

      .if byte ptr szCodeT > 64 && byte ptr szCodeT < 91
            add byte ptr szCodeT, 32
      .endif
      .if byte ptr szCodeT+1 > 64 && byte ptr szCodeT+1 < 91
            add byte ptr szCodeT+1, 32
      .endif
;INVOKE     MessageBox, NULL, addr szCode, addr AppName, MB_OK

   mov     eax, Ctrls.Style
   and     eax, 000000ffh

.if (eax == SS_ETCHEDFRAME) 
   .if byte ptr szCodeT == 's'
          or     Ctrls.ExStyle, WS_EX_TRANSPARENT
      INVOKE     lstrcpy, addr Ctrls.lpName, addr szSta
      INVOKE     lstrcat, addr Ctrls.lpName, addr Ctrls.lpCaption
   .endif
.elseif 
   INVOKE     lstrcmp, addr Ctrls.lpName, addr szSta
   .if !eax
         inc     StatCnt
      INVOKE     BaseAscii, StatCnt, addr szBuff1, 2, 10, 1, 1, 0
      INVOKE     lstrcat, addr Ctrls.lpName, addr szBuff1
   .endif
.endif

                  mov     ecx, Ctrls.Style
                  and     ecx, 0000000fh


               .if byte ptr szCodeT == 's' && byte ptr szCodeT+1 == 't'
                  .if ecx == SS_BITMAP
                        mov     InputType, 7523
                  .elseif ecx == SS_ICON
                        mov     InputType, 7524
                  .else
                        mov     InputType, 7502
                  .endif
               .elseif byte ptr szCodeT == 'b' && byte ptr szCodeT+1 == 'u'
                  .if ecx == BS_GROUPBOX
                        mov     InputType, 7503
                  .elseif ecx == BS_RADIOBUTTON || ecx == BS_AUTORADIOBUTTON
                        mov     InputType, 7504
                  .elseif ecx == BS_CHECKBOX || ecx == BS_AUTOCHECKBOX
                        mov     InputType, 7505
                  .else
                        mov     InputType, 7506
                  .endif
               .elseif byte ptr szCodeT == 'e' && byte ptr szCodeT+1 == 'd'
                        mov     InputType, 7507
               .elseif byte ptr szCodeT == 'r' && byte ptr szCodeT+1 == 'i'
                        mov     InputType, 7508
               .elseif byte ptr szCodeT == 'c' && byte ptr szCodeT+1 == 'o'
                        mov     InputType, 7509
               .elseif byte ptr szCodeT == 'l' && byte ptr szCodeT+1 == 'i'
                        mov     InputType, 7510
               .else
                     mov     Cnt, 31 ;30
                     mov     InputType, 7500
                  .while (Cnt)
                        inc     InputType
                        mov     eax, InputType
                        sub     eax, 7501
                        mov     ecx, ClassArray[eax*4]
                     INVOKE     lstrcmpi, ecx, addr szCode
                     .if !eax
                        .break
                     .endif
                        dec     Cnt
                  .endw
                  .if InputType == 7530
                        mov     InputType, 7508
                  .endif 
                  .if !Cnt
                        mov     InputType, 7506
                     INVOKE     lstrcpy, addr Ctrls.Class, addr szCode
                  .endif
               .endif

FromConvert:

   INVOKE     lstrcmp, addr Ctrls.lpName, addr szSta
   .if !eax
         inc     StatCnt
      INVOKE     BaseAscii, StatCnt, addr szBuff1, 2, 10, 1, 1, 0
      INVOKE     lstrcat, addr Ctrls.lpName, addr szBuff1
   .endif

               .if InputType == 7502 && byte ptr SaveCode == 'C'
                     mov     Ctrls.Style, 50000101h
               .elseif InputType == 7502 && byte ptr SaveCode == 'R'
                     mov     Ctrls.Style, 50000102h
               .elseif InputType == 7502 && byte ptr SaveCode == 'B'
                     mov     Ctrls.Style, 5000010Eh
                     mov     InputType, 7523
               .elseif InputType == 7502 && byte ptr SaveCode == 'I'
                     mov     Ctrls.Style, 50000103h
                     mov     InputType, 7524
            .elseif InputType == 7503 && byte ptr SaveCode == 'G'
                  mov     byte ptr Ctrls.Style, 7
            .elseif InputType == 7504 && byte ptr SaveCode == 'R'
                  mov     byte ptr Ctrls.Style, 4
            .elseif InputType == 7504 && byte ptr SaveCode == 'A'
                  mov     byte ptr Ctrls.Style, 9
            .elseif InputType == 7505 && byte ptr SaveCode == 'C'
                  mov     byte ptr Ctrls.Style, 2
            .elseif InputType == 7505 && byte ptr SaveCode == 'A'
                  mov     byte ptr Ctrls.Style, 3

               .endif

               .if InputType == 7506 && byte ptr SaveCode == 'D'
                      or     Ctrls.Style, BS_DEFPUSHBUTTON
               .endif

               .if !(Ctrls.Style & WS_VISIBLE)
                      or     Ctrls.Style, WS_VISIBLE
               .endif

                  mov     eax, rect.left
                  mov     ebx, rect.top
               .if rect.left > 2000 || rect.top > 2000 ||\
                   rect.right > 2000 || rect.bottom > 2000 ;||\
;                   eax > SavRight || ebx > SavBottom

                     and     sw9, 0
;                  .if eax > SavRight && rect.left < 2000
;                        mov     sw9, 1
;                        mov     rect.left, 0
;                  .endif
;                  .if ebx > SavBottom && rect.top < 2000
;                        mov     sw9, 1
;                        mov     rect.top, 0
;                  .endif


                  .if rect.left > 2000
                        mov     rect.left, 0
                  .endif
                  .if rect.top > 2000
                        mov     rect.top, 0
                  .endif
                  .if rect.right > 2000
                        mov     rect.right, 50
                  .endif
                  .if rect.bottom > 2000
                        mov     rect.bottom, 25
                  .endif

                  .if sw9
                        jmp     NoEMsg
                  .endif
                     inc     ErrorOn
                  INVOKE     lstrcat, hError, addr Dlg.lpName
                  INVOKE     lstrcpy, addr szWork, addr Dlg.lpName
                  INVOKE     lstrlen, addr szWork
                     mov     ecx, 18
                     sub     ecx, eax
                  INVOKE     lstrcpyn, addr szWork, addr szFill, ecx
                  INVOKE     lstrcat, hError, addr szWork
                  INVOKE     lstrcat, hError, addr Ctrls.lpName
                  INVOKE     lstrcat, hError, addr szCRLF
               .endif

NoEMsg:
                  mov     sw44, 1
                  xor     ebx, ebx
                  mov     ecx, 4
               .while (ecx)
                   MOVmd     Ctrls.LeftOrg[ebx*4], rect.left[ebx*4]
                     inc     ebx
                     dec     ecx
               .endw
                  mov     Ctrls.Chg, 0
               .if !ConvertOn
                  INVOKE     MapDialogRect, hDlg2, addr rect
               .else
                    call     UnitToPixel
               .endif
               .if !rect.right
                     mov     rect.right, 40
               .endif
               .if !rect.bottom
                     mov     rect.bottom, 20
               .endif

;                  mov     ecx, hForm
   
               .if !Ctrls.Style
                     mov     Ctrls.Style, WS_CHILD or WS_VISIBLE
               .endif
               .if InputType == 7507
                     mov     ebx, Ctrls.Style
                     and     ebx, 00f00000h
                  .if ebx == WS_BORDER
                        mov     Ctrls.ExStyle, 00000200h
                  .endif
               .endif
;.if InputType == 7503
;      dec     rect.top
;;      inc     rect.left
;      inc     rect.top
;      dec     rect.bottom
;.endif
;;.if InputType != 7503
;;      inc     rect.left
;;      inc     rect.top
;;.endif
;DSPValue hWnd, InputType, 1, 'm'
;DSPValue hWnd, Ctrls.ExStyle, 1, 'm'

                  inc     CtrlNum
               INVOKE     SetDlgItemInt, hdlg, 702, CtrlNum, 0
               INVOKE     UpdateWindow, hdlg

               .if NameOn && !Ctrls.ID && Ctrls.lpName
                     and     Len1, 0
                     mov     Cnt1, 10
                  .while (Cnt1)
                        mov     eax, Len1
                        mov     edx, ComIDArray[eax*4]
                     INVOKE     lstrcmp, edx, addr Ctrls.lpName
                     .if !eax
                         MOVmd     Ctrls.ID, Len1
                        .break
                     .endif
                        inc     Len1
                        dec     Cnt1
                  .endw
               .endif

               .if NameOn && !Ctrls.ID
                  .if byte ptr Ctrls.lpName+3 == '_' && byte ptr Ctrls.lpName+4 == 'S' &&\
                      byte ptr Ctrls.lpName+9 == 'C'
                        mov     eax, 1
                  .else
                     INVOKE     lstrcpy, addr szBuff1, addr Ctrls.lpName
                     INVOKE     AsciiBase, addr szBuff1, 10
                  .endif
                     mov     Ctrls.ID, eax

                  .if InputType == 7506 && eax >= 1 && eax <= 9
                        mov     edx, ComIDArray[eax*4]
                     INVOKE     lstrcpy, addr Ctrls.lpName, edx

                  .else

                     .if byte ptr Ctrls.lpName+3 == '_' && byte ptr Ctrls.lpName+4 == 'S' &&\
                         byte ptr Ctrls.lpName+9 == 'C'
                     .else
                           mov     eax, InputType
                           sub     eax, 7501
                         MOVmd     tAddr, TextArray[eax*4]
                           mov     eax, InputType
                           sub     eax, 7501
                           mov     ecx, CtrlCnt+[eax*4]
                           inc     ecx
                        INVOKE     BaseAscii, ecx, addr szBuff1, 2, 10, 1, 1, 0
                        INVOKE     lstrcpy, addr szBuff0, tAddr
                        INVOKE     lstrcat, addr szBuff0, addr szBuff1
                        INVOKE     lstrcpy, addr Ctrls.lpName, addr szBuff0
                        .if byte ptr Ctrls.lpName+3 == '_' && byte ptr Ctrls.lpName+4 == 'S' &&\
                            byte ptr Ctrls.lpName+9 == 'C'
                              inc     StatCnt
                        .endif
                     .endif
                  .endif
               .endif
.if InputType == 7502
       or     Ctrls.Style, SS_NOTIFY
.endif
                  sub     Dlg.StartID, 1000
               INVOKE     CreateControls, hForm, 0
                  add     Dlg.StartID, 1000

               .if CtrlType == 7503
                  INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234
                  .if CtrlType == 7503
                         inc     Srect.top
                  .endif
                  INVOKE     MoveGrabbers, 5, 0
                     and     hGrpOn, 0
               .endif

                  and     sw44, 0
                  and     BorderOn, 0
;            and     Ctrls.ID, 0
                  and     Ctrls.Style, 0
                  and     Ctrls.ExStyle, 0
                  and     Ctrls.Border, 0
                  and     StaticOn, 0
                  mov     sw4, 2
                  pop     eax
                  jmp     DoMore
            .endif

DoMore:
               dec     BytesOut
               inc     eax
;DSPValue hWnd, BytesOut, 1, 't'
;.if BytesOut < 80000
;DSPValue hWnd, 3333, 1, 'm'
;jmp     AllDone
;.endif
            .if sdword ptr BytesOut < 0
                  jmp     AllDone
            .endif
         .endw

AllDone:
;---------- [Check if any controls fall within a Groupbox boundaries] ----------
;DSPValue hWnd, 4444, 1, 'm'
;DSPValue hWnd, GrpCnt, 1, 'm'
;DSPValue hWnd, ArrayCnt, 1, 'm'
;jmp     GetOut
            and     hGrp, 0
            and     hParent, 0
            mov     sw44, 1
            and     Len1, 0
          MOVmd     Cnt1, GrpCnt
         .while (Cnt1)                            ; Find handle of Groupbox parent in the array
               mov     eax, Len1
            .if hGrpArray[eax]
                MOVmd     hCtrl, hGrpArray[eax+4] ; Handle of Groupbox
                  mov     ecx, hGrpArray[eax]
               INVOKE     GetParent, ecx
      mov     hForm, eax
               .if eax != hForm
                     jmp     DoAgain
               .endif
               INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234
                  mov     dis.itemID, 7 ;6^^^^^^^^^^^^

;---------- [Get offset in the structure array] ----------
               INVOKE     GetOffset, 0
                  mov     StrSize, eax
                 imul     ebx, StrSize
                  add     ecx, ebx
                 imul     edx, 4
                  add     ecx, edx
                MOVmd     Srect.left, dword ptr [ecx]      ; = Left
                MOVmd     Srect.top, dword ptr [ecx+4]     ; = Top
                MOVmd     Srect.right, dword ptr [ecx+8]   ; = Right
                MOVmd     Srect.bottom, dword ptr [ecx+12] ; = Bottom
                  mov     eax, Srect.left
                  add     Srect.right, eax
                  mov     eax, Srect.top
                  add     Srect.bottom, eax
                 call     ChkUnder
            .endif

DoAgain:
               add     Len1, 8
               dec     Cnt1
         .endw
            and     sw44, 0
            and     hGrpOn, 0

GetOut:
         INVOKE     HeapDestroy, hMemM
         INVOKE     DestroyWindow, hStyles
         INVOKE     SendMessage, hWndCombo, CB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hWndList, LB_RESETCONTENT, 0, 0

         .if !NoMsg
            INVOKE     BaseAscii, DlgNum, addr szDlgNum, 2, 10, 1, 0, 0
            INVOKE     BaseAscii, CtrlNum, addr szCtrlNum, 2, 10, 1, 0, 0
            INVOKE     MessageBox, NULL, addr szDlgNum, addr AppName, MB_OK
               mov     dword ptr szDlgNum, '    '
               mov     dword ptr szCtrlNum, '    '
         .endif
            and     DlgNum, 0
            and     NoMsg, 0
         .if ErrorOn
            INVOKE     CreateDialogParam, hInst, 5200, hREdit, offset ErrorList, 0
               mov     ecx, eax
            INVOKE     GetDlgItem, ecx, 5201
               mov     ecx, eax
              push     ecx
            INVOKE     SendMessage, ecx, WM_SETFONT, hFont, TRUE
               pop     ecx
            INVOKE     SendMessage, ecx, WM_SETTEXT, 0, hError
         .endif

      .elseif eax == 604
         INVOKE     SetFocus, hMenuN
           call     SaveFile
         INVOKE     SetFocus, hREdit

;---------- [Clear all dialogs from memory] ----------
      .elseif eax == 605
         INVOKE     ShowWindow, hForm, SW_HIDE

            and     Cnt, 0
         .while AniCnt
               mov     ecx, Cnt
            .if hAniArray+[ecx*4]
               INVOKE     DestroyWindow, hAniArray+[ecx*4]
            .endif
               inc     Cnt
               dec     AniCnt
         .endw

            and     Len, 0
         .while (ArrayCnt)
               mov     eax, Len
            .if hArray+[eax*8+4]                ; Check for valid handle
                  mov     edx, hArray+[eax*8+4] ; Extract handle
                  mov     ebx, hArray+[eax*8]   ; Extract array count type
                  and     ebx, 0ffffh
               .if ebx == 7501
                  INVOKE     DestroyWindow, edx
               .endif
            .endif
               inc     Len
               dec     ArrayCnt
         .endw

            and     Len1, 0
            mov     Cnt1, 30 ;24
         .while (Cnt1)
               mov     ecx, Len1
            .if dword ptr hDlgMem+[ecx*4] != 0
               INVOKE     HeapFree, hDefHeap, 0, dword ptr hDlgMem+[ecx*4]
            .endif
               inc     Len1
               dec     Cnt1
         .endw

         INVOKE     RtlZeroMemory, addr hDlgMem, 124 ;100
         INVOKE     RtlZeroMemory, addr hArray, 65544
         INVOKE     RtlZeroMemory, addr GrpCnt, 2576 ;1576
         INVOKE     RtlZeroMemory, addr hDlg, 6152

         INVOKE     SendMessage, hWndComboD, CB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hWndCombo, CB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hWndList, LB_RESETCONTENT, 0, 0
         INVOKE     SetDlgItemInt, hdlg, 701, 0, 0
         INVOKE     SetDlgItemInt, hdlg, 702, 0, 0

            and     InputType, 0
            and     hUnder, 0
            and     hForm, 0
            and     DlgOn, 0
            and     CtrlOn, 0
            and     CtrlNum, 0
            and     IDCnt, 0
            mov     Dlg.ID, 2000
            mov     Dlg.StartID, 2001

      .elseif eax == 606    ; Convert to a friendly name
         INVOKE     SetFocus, hMenuN

      .elseif eax == 607    ; Extract from a binary file
         INVOKE     ExtractRsrc, hWnd, hInst, hREdit, hDlg3
         INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
         .if eax
            INVOKE     GetDlgItem, hdlg, 602
            INVOKE     EnableWindow, eax, 1
            INVOKE     GetDlgItem, hdlg, 604
            INVOKE     EnableWindow, eax, 1
         .endif

      .endif
         jmp     ExtractDone

DoError:

ExtractDone:
      INVOKE     GetDlgItem, hdlg, 605
      .if !ArrayCnt
         INVOKE     EnableWindow, eax, 0
      .else
         INVOKE     EnableWindow, eax, 1
      .endif
         mov     eax, FALSE

ExtractRet:
         ret
ExtractDlg ENDP

;=======================================
; Parse the style or EXStyle PROCEDURE
;=======================================
ParseStyle PROC  uses ebx edi
LOCAL    ft:FINDTEXT
LOCAL    cr:CHARRANGE
LOCAL    tr:TEXTRANGE
LOCAL    Cnt1:DWORD, Len1, Styles
LOCAL    szBuff0[32]:BYTE, szBuff1[20]:BYTE

;INVOKE     MessageBox, NULL, addr szBuffR, addr AppName, MB_OK

         and     Styles, 0
      .if sw4 != 3 && sw4 != 8 && !sw5
            mov     Styles, WS_CHILD or WS_VISIBLE
      .elseif sw5 == 1
            mov     Styles, WS_VISIBLE
      .endif
      INVOKE     lstrlen, addr szBuffR
         inc     eax
         mov     Cnt1, eax
         and     Len1, 0
         xor     edi, edi
      .while (Cnt1)
            mov     eax, Len1
            mov     bl, byte ptr szBuffR[eax]

         .if dword ptr szBuffR[eax] == ' TON'
            .while (Cnt1)
                  mov     eax, Len1
               .if byte ptr szBuffR[eax] == '_'
                     inc     Len1
                     dec     Cnt1
                  .break
               .endif
               inc     Len1
               dec     Cnt1
            .endw

;         .if bl != ' ' && bl != '|' && bl != 0
         .elseif bl != ' ' && bl != '|' && bl != 0
               mov     byte ptr szBuff0[edi], bl
               mov     byte ptr szBuff0[edi+1], 0
               inc     edi
         .elseif edi
               mov     ft.chrg.cpMin, 0
               mov     ft.chrg.cpMax, -1
               lea     eax, szBuff0
               mov     ft.lpstrText, eax
            INVOKE     SendMessage, hStyles, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr ft
            .if eax != -1
                  add     eax, 32
                  mov     tr.chrg.cpMin, eax
                  add     eax, 8
                  mov     tr.chrg.cpMax, eax
                  lea     eax, szBuff1
                  mov     tr.lpstrText, eax
               INVOKE     SendMessage, hStyles, EM_GETTEXTRANGE, 0, addr tr
               INVOKE     AsciiBase, addr szBuff1, 16
                   or     Styles, eax
            .endif
               xor     edi, edi
         .endif
         .if !Cnt1
            .break
         .endif
            inc     Len1
            dec     Cnt1
      .endw
         mov     eax, Styles
         ret
ParseStyle ENDP

;=======================================
; BuildDlg Dialog
;=======================================
BuildDlg PROC    hdlg:DWORD, wmsg, wparam, lparam
LOCAL    szBuff0[256]:BYTE, szBuff1[256]:BYTE

      .if wmsg == WM_INITDIALOG
          MOVmd     hDlg4, hdlg
         INVOKE     GetDlgItem, hdlg, 602
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 603
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 604
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 605
         INVOKE     EnableWindow, eax, 0

      .elseif wmsg != WM_COMMAND
            jmp     BuildDone
      .endif

         mov     eax, wparam
        cwde

      .if eax == 601
         INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, offset szNULL
         INVOKE     SetFocus, hREdit
           call     BuildRes
         INVOKE     SetFocus, hREdit

         INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
         .if eax
            INVOKE     GetDlgItem, hdlg, 602
            INVOKE     EnableWindow, eax, 1
            INVOKE     GetDlgItem, hdlg, 603
            INVOKE     EnableWindow, eax, 1
            INVOKE     GetDlgItem, hdlg, 604
            INVOKE     EnableWindow, eax, 1
            INVOKE     GetDlgItem, hdlg, 605
            INVOKE     EnableWindow, eax, 1
         .endif

      .elseif eax == 602
         INVOKE     SetFocus, hMenuN
         INVOKE     GetWindowText, hWnd, addr szBuff0, lengthof szBuff0
         INVOKE     lstrlen, addr szBuff0
         .if eax
               mov     sw6, 1
         .endif
           call     SaveFile
         INVOKE     SetFocus, hREdit

      .elseif eax == 603
            and     sw6, 0
         INVOKE     SetFocus, hMenuN
           call     SaveFile
         INVOKE     SetFocus, hREdit

      .elseif eax == 604
         INVOKE     GetDlgItem, hDlg4, 601
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hDlg4, 602
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hDlg4, 603
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hDlg4, 605
         INVOKE     EnableWindow, eax, 0
         .if !hDlgS
            INVOKE     CreateDialogParam, hInst, 4816, hREdit, offset SampleDlgS, 4242
         .endif
         INVOKE     SetFocus, hDlgS
         INVOKE     GetDlgItem, hDlgS, 4002
            mov     hREditE, eax
         INVOKE     SendMessage, hREditE, WM_SETFONT, hFont, TRUE
         INVOKE     SendMessage, hREditE, WM_SETTEXT, FALSE, Equates

      .elseif eax == 605
         INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, offset szNULL
         INVOKE     SetFocus, hMenuN
      .elseif eax == 606
         INVOKE     SetFocus, hMenuN

      .endif

BuildDone:
         mov     eax, FALSE

BuildRet:
         ret
BuildDlg ENDP

;=======================================
; SampleDlgS Dialog
;=======================================
SampleDlgS PROC hdlg:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_INITDIALOG
         .if lparam == 4242
             MOVmd     hDlgS, hdlg
         .endif
         .if lparam == 2000
            INVOKE     LoadIcon, hInst, 8810
            INVOKE     SendMessage, hdlg, WM_SETICON, 1, eax
         .endif

      .elseif wmsg == WM_CLOSE
            jmp     CancleIt

      .elseif wmsg != WM_COMMAND
            jmp     SampleDone
      .endif

         mov     eax, wparam
        cwde

      .if eax == 3005 || eax == 4009
            jmp     CancleIt
      .endif
         jmp     SampleDone

CancleIt:
         mov     eax, hdlg
      .if eax == hDlgS
            and     hDlgS, 0
         INVOKE     GetDlgItem, hDlg4, 601
         INVOKE     EnableWindow, eax, 1
         INVOKE     GetDlgItem, hDlg4, 602
         INVOKE     EnableWindow, eax, 1
         INVOKE     GetDlgItem, hDlg4, 603
         INVOKE     EnableWindow, eax, 1
         INVOKE     GetDlgItem, hDlg4, 605
         INVOKE     EnableWindow, eax, 1
      .endif
      INVOKE     DestroyWindow, hdlg
      INVOKE     SetFocus, hREdit
         mov     eax, TRUE             ; Return
         jmp     SampleRet             ; with TRUE

SampleDone:
         mov     eax, FALSE           ; Return with FALSE

SampleRet:
         ret
SampleDlgS ENDP

;=======================================
; SampleDlg Dialog
;=======================================
SampleDlg PROC hdlg:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_INITDIALOG

      .elseif wmsg != WM_COMMAND
            jmp     SampleDone
      .endif

         mov     eax, wparam
        cwde

      .if eax == 602
            mov     sw3, 2
           call     OpenFileA
         INVOKE     SetFocus, hREdit

      .elseif eax == 603
         INVOKE     CreateDialogParam, hInst, 2000, hREdit, offset SampleDlgS, 2000
         INVOKE     SetFocus, eax

      .elseif eax == 604
         INVOKE     CreateDialogParam, hInst, 3000, hREdit, offset SampleDlgS, 3000
         INVOKE     SetFocus, eax

      .elseif eax == 605
         INVOKE     CreateDialogParam, hInst, 7000, hREdit, offset SampleDlgS, 7000
         INVOKE     SetFocus, eax

      .endif

SampleDone:
         mov     eax, FALSE

SampleRet:
         ret
SampleDlg ENDP

;===================================
; Load List/Combo Box Procedure
;===================================
LoadList PROC  uses esi  hList:DWORD, Input, TypeBox, CtrlSW
LOCAL    ft:FINDTEXT
LOCAL    tr:TEXTRANGE
LOCAL    TypeC:DWORD
LOCAL    szBuff1[64]:BYTE, szBuff2[20]:BYTE

            .if TypeBox == 2 || TypeBox == 3 || TypeBox == 4
                  mov     ft.chrg.cpMin, 0
                  mov     ft.chrg.cpMax, -1
               .if TypeBox != 4
                  .if TypeBox == 2
                     INVOKE     lstrcpy, addr szBuff1, addr szWS
                  .elseif TypeBox == 3
                     INVOKE     lstrcpy, addr szBuff1, addr szDS
                  .endif
                     lea     eax, szBuff1
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hDefaults, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr ft
                  .if eax == -1
                        jmp     AllDone
                  .endif
                     mov     ft.chrg.cpMin, 0

               .else
                  INVOKE     SendMessage, hDefaults, WM_GETTEXTLENGTH, 0, 0
                     mov     ft.chrg.cpMin, 1000
               .endif
                  mov     ft.chrg.cpMax, eax
               .if TypeBox == 2
                     mov     dword ptr szBuffQ, 'E_SW'
                     mov     byte ptr szBuffQ+4, 0
               .elseif TypeBox == 3

                  INVOKE     lstrcpy, addr szBuff1, addr szWS
                     lea     eax, szBuff1
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hDefaults, EM_FINDTEXT, FR_DOWN or FR_WHOLEWORD, addr ft
                  .if eax == -1
                        jmp     AllDone
                  .endif
                     mov     ft.chrg.cpMin, eax

                     mov     dword ptr szBuffQ, '_SW'
                     mov     byte ptr szBuffQ+3, 0
               .endif
                  lea     eax, szBuffQ
                  mov     ft.lpstrText, eax

Loop2:
               .if TypeBox != 4
                  INVOKE     SendMessage, hDefaults, EM_FINDTEXT, FR_DOWN or FR_MATCHCASE, addr ft
               .else
                  INVOKE     SendMessage, hDefaults, EM_FINDTEXT, FR_DOWN or FR_MATCHCASE or FR_WHOLEWORD, addr ft
               .endif
                  mov     ecx, ft.chrg.cpMax 
               .if eax != -1
                     mov     ft.chrg.cpMin, eax
                     inc     ft.chrg.cpMin
                     mov     tr.chrg.cpMin, eax
                     mov     tr.chrg.cpMax, eax
                  .if TypeBox == 3
                        add     tr.chrg.cpMax, 44
                  .elseif TypeBox == 4
                        add     tr.chrg.cpMax, 48
                  .else
                        add     tr.chrg.cpMax, 32
                  .endif
                     lea     eax, szBuff1
                     mov     tr.lpstrText, eax
                  INVOKE     SendMessage, hDefaults, EM_GETTEXTRANGE, 0, addr tr
                  .if TypeBox == 3
                     .if byte ptr szBuff1+42 != 'C' && CtrlSW
                           jmp     Pass
                     .endif
                        sub     tr.chrg.cpMax, 12
                  .endif

                  .if TypeBox == 4
                     .if byte ptr DefCode == 'B' && byte ptr szBuff1+42 != 'B' ||\
                         byte ptr DefCode == 'C' && byte ptr DefCode+1 == 'H' && byte ptr szBuff1+44 != 'C' ||\
                         byte ptr DefCode == 'R' && byte ptr DefCode+1 == 'A' && byte ptr szBuff1+46 != 'R' ||\
                         byte ptr DefCode == 'G' && byte ptr szBuff1+42 != 'G'
                           jmp     Pass
                     .endif
                        sub     tr.chrg.cpMax, 16
                  .endif

                     xor     eax, eax
                     mov     ecx, 32
                  .while (ecx)
                        .if byte ptr szBuff1[eax] == ' ' || byte ptr szBuff1[eax] == 0dh
                           .if byte ptr szBuff1[eax-1] == 'z'
                                 jmp     Pass
                           .endif
                              mov     byte ptr szBuff1[eax], 0
                           .break
                        .endif
                        inc     eax
                        dec     ecx
                  .endw
                     add     tr.chrg.cpMin, 32
                     add     tr.chrg.cpMax, 8
                     lea     eax, szBuff2
                     mov     tr.lpstrText, eax
                  INVOKE     SendMessage, hDefaults, EM_GETTEXTRANGE, 0, addr tr
                  INVOKE     AsciiBase, addr szBuff2, 16
                     mov     TypeC, eax
                  INVOKE     SendMessage, hList, LB_ADDSTRING, 0, addr szBuff1
                     mov     ecx, eax
                  INVOKE     SendMessage, hList, LB_SETITEMDATA, ecx, TypeC
                     jmp     Loop2

               .elseif eax == -1 ;&& ft.chrg.cpMin < ecx
                  .if TypeBox == 3
                     INVOKE     SendMessage, hList, LB_ADDSTRING, 0, addr szDivider
                  .endif
jmp     AllDone
Pass:
                     inc     ft.chrg.cpMin
                     jmp     Loop2
               .endif
;               .if TypeBox == 3
;                  INVOKE     SendMessage, hList, LB_ADDSTRING, 0, addr szDivider
;               .endif
            .endif

AllDone:
         ret
LoadList ENDP

;=======================================
; SetAllDefaults Procedure
;=======================================
SetAllDefaults PROC
LOCAL    hReg:DWORD, Cnt1, szData, Data

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

         xor     eax, eax
         mov     ecx, 120
      .while (ecx)
            mov     edx, dword ptr ddDlg[eax]
            mov     dword ptr ddDlgD[eax], edx
            add     eax, 4
            dec     ecx
      .endw

         lea     eax, offset szDlgD
         mov     szData, eax
         lea     eax, ddDlgD
         mov     Data, eax
         mov     Cnt1, 12
      .while (Cnt1)
         INVOKE     RegSetValueEx, hReg, szData, 0, REG_BINARY, Data, 40
            add     szData, 7
            add     Data, 40
            dec     Cnt1
      .endw

      INVOKE     RegCloseKey, hReg

         ret
SetAllDefaults ENDP

;=======================================
; GetDefaults Procedure
;=======================================
GetDefaults PROC hList:DWORD
LOCAL    hReg:DWORD, Cnt1, TypeC, Styles, Index, Incr, SavSel, szData, Data
LOCAL    szBuff0[256]:BYTE, szArray[256]:BYTE

      INVOKE     SendMessage, hList11, CB_GETCURSEL, 0, 0
      .if eax == CB_ERR
; Do Message
            jmp     AllDone
      .endif
         mov     SavSel, eax
        imul     eax, 40
         add     eax, offset ddDlgD
         mov     TypeC, eax

      .if hList == 1234
            mov     eax, SavSel
           imul     eax, 40
            mov     ecx, 10
         .while (ecx)
               mov     edx, dword ptr ddDlg[eax]
               mov     dword ptr ddDlgD[eax], edx
               add     eax, 4
               dec     ecx
         .endw
            jmp     DoRestore
      .endif

      INVOKE     SendMessage, hList, LB_GETSELCOUNT, 0, 0
      .if eax
            mov     ebx, eax
         INVOKE     SendMessage, hList, LB_GETSELITEMS, ebx, addr szArray
            and     Styles, 0
            and     Incr, 0
            and     Index, 0
            mov     Cnt1, eax
         .while (Cnt1)
               mov     ecx, Index
            INVOKE     SendMessage, hList, LB_GETTEXT, dword ptr szArray[ecx*4], addr szBuff0
            .if byte ptr szBuff0 != ' '
                  mov     ecx, Index
               INVOKE     SendMessage, hList, LB_GETITEMDATA, dword ptr szArray[ecx*4], 0
               .if byte ptr szBuff0 == 'W'
                      or     Styles, eax
               .else
                     mov     ecx, TypeC
                     mov     edx, Incr
                     mov     [ecx+edx*4], eax   ; Default styles
                     inc     Incr
               .endif
            .endif
               inc     Index
               dec     Cnt1
         .endw

            mov     eax, hList
         .if eax == hList13
               mov     eax, TypeC
               mov     ecx, Styles
               mov     dword ptr[eax+32], ecx

            .while (Incr < 8)
                  mov     ecx, TypeC
                  mov     edx, Incr
                  mov     dword ptr[ecx+edx*4], 0
                  inc     Incr
            .endw

         .else            ; Extended Styles
               mov     eax, TypeC
               mov     ecx, Styles
               mov     dword ptr[eax+36], ecx
         .endif

      .else
            mov     eax, hList
         .if eax == hList12
               mov     eax, TypeC
               mov     dword ptr[eax+36], 0
         .endif
      .endif

DoRestore:
         lea     eax, offset szDlgD
         mov     ecx, SavSel
        imul     ecx, 7
         add     eax, ecx
         mov     szData, eax

      .if hList != 1234
            lea     eax, ddDlgD
      .else
            lea     eax, ddDlg
      .endif

         mov     ecx, SavSel
        imul     ecx, 40
         add     eax, ecx
         mov     Data, eax

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hReg, addr lpdwDisp
      INVOKE     RegSetValueEx, hReg, szData, 0, REG_BINARY, Data, 40
      INVOKE     RegCloseKey, hReg


AllDone:
         ret
GetDefaults ENDP

;=======================================
; SetDefaults Dialog
;=======================================
SetDefaults PROC uses ebx edx hdlg:DWORD, wmsg, wparam, lparam
LOCAL    ft:FINDTEXT
LOCAL    cr:CHARRANGE
LOCAL    tr:TEXTRANGE
LOCAL    Cnt1:DWORD, Len1, TypeC, Styles, SetIt, Index, Incr, SavDef, Cnt2
LOCAL    szBuff0[256]:BYTE, szBuff1[64]:BYTE, szBuff2[20]:BYTE, szArray[256]:BYTE

      .if wmsg == WM_INITDIALOG
          MOVmd     hDef, hdlg
         INVOKE     GetDlgItem, hdlg, 411            ; Get the handle of the Combobox
            mov     hList11, eax                     ; Save it
         INVOKE     GetDlgItem, hdlg, 412            ; Get the handle of the Listbox
            mov     hList12, eax                     ; Save it
         INVOKE     GetDlgItem, hdlg, 413            ; Get the handle of the Listbox
            mov     hList13, eax                     ; Save it

         INVOKE     GetDlgItem, hdlg, 601
            mov     ecx, eax
         INVOKE     SendMessage, ecx, WM_SETFONT, hFontS, TRUE
         INVOKE     GetDlgItem, hdlg, 602
            mov     ecx, eax
         INVOKE     SendMessage, ecx, WM_SETFONT, hFontS, TRUE
         INVOKE     GetDlgItem, hdlg, 603
            mov     ecx, eax
         INVOKE     SendMessage, ecx, WM_SETFONT, hFontS, TRUE

         INVOKE     CreateWindowEx, 0, addr RichEdit, 0, WS_POPUP or ES_MULTILINE or\
                    WS_HSCROLL or WS_VSCROLL,\
                    100, 100, 300, 400, 0, 0, hInst, 0
            mov     hDefaults, eax
         INVOKE     SendMessage, hDefaults, EM_EXLIMITTEXT, 0, 50000
            mov     sw3, 6
           call     OpenFileA

            mov     Cnt1, 1
         .while (Cnt1 < 4)
            .if Cnt1 == 1
                  mov     ft.chrg.cpMin, 0
                  mov     ft.chrg.cpMax, 500
                  mov     byte ptr szBuffQ, 'Q'
                  mov     byte ptr szBuffQ+1, 0
                  lea     eax, szBuffQ
                  mov     ft.lpstrText, eax

Loop1:
               INVOKE     SendMessage, hDefaults, EM_FINDTEXT, FR_DOWN or FR_MATCHCASE, addr ft
               .if eax != -1
                     mov     ft.chrg.cpMin, eax
                     inc     ft.chrg.cpMin
                     mov     tr.chrg.cpMin, eax
                     add     eax, 32
                     mov     tr.chrg.cpMax, eax
                     lea     eax, szBuff1
                     mov     tr.lpstrText, eax
                  INVOKE     SendMessage, hDefaults, EM_GETTEXTRANGE, 0, addr tr
                  .if byte ptr szBuff1+3 == '_'
                     INVOKE     lstrcpyn, addr szBuff2, addr szBuff1+1, 3
                        mov     ax, word ptr szBuff2
                        mov     word ptr TypeC[0], ax
                        mov     byte ptr TypeC[2], 0
                     INVOKE     lstrcpy, addr szBuff1, addr szBuff1+4
                  .else
                     INVOKE     lstrcpyn, addr szBuff2, addr szBuff1+1, 4
                        mov     ax, word ptr szBuff2
                        mov     word ptr TypeC[0], ax
                        mov     al, byte ptr szBuff2+2
                        mov     byte ptr TypeC[2], al
                     INVOKE     lstrcpy, addr szBuff1, addr szBuff1+5
                  .endif
                     xor     eax, eax
                     mov     ecx, 32
                  .while (ecx)
                        .if byte ptr szBuff1[eax] == 0dh
                              mov     byte ptr szBuff1[eax], 0
                           .break
                        .endif
                        inc     eax
                        dec     ecx
                  .endw
                  INVOKE     SendMessage, hList11, CB_ADDSTRING, 0, addr szBuff1
                     mov     ecx, eax
                  INVOKE     SendMessage, hList11, CB_SETITEMDATA, ecx, TypeC
                     jmp     Loop1

               .elseif eax == -1 && ft.chrg.cpMin < 500
                     inc     ft.chrg.cpMin
                     jmp     Loop1
               .endif

            .elseif Cnt1 == 2
               INVOKE     LoadList, hList12, 0, Cnt1, 0

            .elseif Cnt1 == 3
               INVOKE     LoadList, hList13, 0, Cnt1, 0

                  mov     word ptr szBuffQ, 'SD'
                  mov     byte ptr szBuffQ+2, 0
               INVOKE     LoadList, hList13, 0, 4, 0
            .endif
               inc     Cnt1
         .endw

         INVOKE     SendMessage, hList11, CB_SETCURSEL, 0, 0

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

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

      .elseif wmsg == WM_CLOSE
            jmp     CancleIt

      .elseif wmsg != WM_COMMAND
            jmp     SetDefaultsDone
      .endif

         mov     eax, wparam
         and     eax, 0ffffh
         mov     ecx, wparam
         shr     ecx, 16

;---------- [Check the control combobox for control selection] ----------
      .if eax == 411 && ecx == CBN_SELCHANGE
         INVOKE     SendMessage, hList13, LB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hList11, CB_GETCURSEL, 0, 0
           push     eax
         INVOKE     LoadList, hList13, 0, 3, eax
            pop     eax
            mov     ecx, eax
           imul     ecx, 40
            add     ecx, offset ddDlgD
            mov     TypeC, ecx
            mov     ecx, eax
           push     ecx
         INVOKE     SendMessage, hList11, CB_GETLBTEXT, ecx, addr DefCode
            pop     ecx
         INVOKE     SendMessage, hList11, CB_GETITEMDATA, ecx, 0
            mov     ecx, eax
            shr     ecx, 16
            mov     byte ptr szBuffQ, al
            mov     byte ptr szBuffQ+1, ah
         .if !cl
               mov     byte ptr szBuffQ+2, 0
         .else
               mov     byte ptr szBuffQ+2, cl
               mov     byte ptr szBuffQ+3, 0
         .endif
         INVOKE     LoadList, hList13, 0, 4, 0
;INVOKE     MessageBox, NULL, addr szBuff1, addr AppName, MB_OK
;INVOKE     MessageBox, NULL, addr szBuffQ, addr AppName, MB_OK

;---------- [Set Extended Styles] ----------
         INVOKE     SendMessage, hList12, LB_SETSEL, 0, -1
         INVOKE     SendMessage, hList12, LB_GETCOUNT, 0, 0
            mov     Cnt1, eax
            and     Index, 0
            and     Incr, 0
            and     SetIt, 0

         .while (Cnt1)
            INVOKE     SendMessage, hList12, LB_GETITEMDATA, Index, 0
               mov     Styles, eax
;               mov     SavDef, eax
            INVOKE     SendMessage, hList12, LB_GETTEXT, Index, addr szBuff0
               mov     ecx, SavDef
            .if !SetIt
               mov     SetIt, 1
               mov     eax, TypeC
               mov     ecx, [eax+36]
               mov     SavDef, ecx
            .endif
            .if (ecx == Styles) && ecx
               INVOKE     SendMessage, hList12, LB_SETSEL, 1, Index
            .endif
               inc     Index
               dec     Cnt1
         .endw

;---------- [Set Window & Control Styles] ----------
         INVOKE     SendMessage, hList13, LB_GETCOUNT, 0, 0
            mov     Cnt1, eax
            and     Index, 0
            and     Incr, 0
            and     SetIt, 0

         .while (Cnt1)
            INVOKE     SendMessage, hList13, LB_GETITEMDATA, Index, 0
               mov     Styles, eax
            INVOKE     SendMessage, hList13, LB_GETTEXT, Index, addr szBuff0
               mov     ecx, SavDef
            .if byte ptr szBuff0 == ' '
                  and     SetIt, 0
                  jmp     NAS
            .elseif byte ptr szBuff0 == 'W'
               .if !SetIt
                  mov     SetIt, 1
                  mov     eax, TypeC
                  mov     ecx, [eax+32]
                  mov     SavDef, ecx
               .endif
               .if (ecx & Styles)
                     xor     ecx, Styles
                     mov     SavDef, ecx
                  INVOKE     SendMessage, hList13, LB_SETSEL, 1, Index
               .endif

            .else
                  and     Incr, 0
                  mov     Cnt2, 8
               .while (Cnt2)
                     mov     eax, Incr
                     mov     edx, TypeC
                     mov     ecx, [edx+eax*4]   ; Default styles
                  .if !ecx
                        jmp     NAS
                  .endif
                  .if ecx == Styles
                     INVOKE     SendMessage, hList13, LB_SETSEL, 1, Index
                     .break
                  .endif
                     inc     Incr
                     dec     Cnt2
               .endw
            .endif

NAS:
               inc     Index
               dec     Cnt1
         .endw
      .endif

         mov     eax, wparam
        cwde

      .if eax == 601             ; Restore all default styles
           call     SetAllDefaults
         INVOKE     SendMessage, hList11, CB_SETCURSEL, -1, 0
         INVOKE     SendMessage, hList12, LB_SETSEL, 0, -1
         INVOKE     SendMessage, hList13, LB_SETSEL, 0, -1

      .elseif eax == 602         ; Restore control default styles
         INVOKE     GetDefaults, 1234
            mov     ecx, CBN_SELCHANGE
            shl     ecx, 16
            mov     ax, 411
            mov     cx, ax
         INVOKE     SendMessage, hdlg, WM_COMMAND, ecx, 0

      .elseif eax == 603         ; Set control default styles
         INVOKE     GetDefaults, hList12
         INVOKE     GetDefaults, hList13

      .endif

         jmp     SetDefaultsDone

CancleIt:
      .if hBRD
         INVOKE     DeleteObject, hBRD
            and     hBRD, 0
      .endif
         and     hDef, 0
      INVOKE     DestroyWindow, hdlg
      INVOKE     SetFocus, hREdit
         mov     eax, TRUE
         jmp     SetDefaultsRet

SetDefaultsDone:
         mov     eax, FALSE

SetDefaultsRet:
         ret
SetDefaults ENDP

;=====================================================
; SubClass the Edit control PROCEDURE
;=====================================================
RichEditProc PROC uses ebx hwnd:DWORD, wmsg, wparam, lparam
LOCAL    ps:PAINTSTRUCT
LOCAL    hDCp:DWORD, TempDC, htbmp, hOldRgn, hRgn

      .if wmsg == WM_RBUTTONDOWN
            jmp     PopUp

      .elseif wmsg == WM_LBUTTONUP ;&& eax == hREdit
         .if TabSelect == 3
            INVOKE     SendMessage, hREdit, EM_GETSEL, addr sPos, addr ePos
               mov     eax, ePos
            .if eax > sPos
               INVOKE     GetDlgItem, hDlg3, 603
               INVOKE     EnableWindow, eax, 1
            .else
               INVOKE     GetDlgItem, hDlg3, 603
               INVOKE     EnableWindow, eax, 0
            .endif
         .endif
      .endif
         jmp     ThatsAll

PopUp:
      INVOKE     SetFocus, hREdit
      INVOKE     GetWindowRect, hREdit, addr rect
         mov     ecx, lparam        ; x/y pos of window
         mov     edx, ecx
         and     edx, 0000ffffh     ; edx = LOWORD(lparam) = x pos
         shr     ecx, 16            ; ecx = HIWORD(lparam) = y pos
         add     edx, rect.left
         add     ecx, rect.top
;         add     edx, 10 
;         add     ecx, 30
      .if hAsmEdit
            sub     edx, 6 
            sub     ecx, 22
      .endif
      INVOKE     TrackPopupMenu, hSMenu, TPM_LEFTALIGN or TPM_LEFTBUTTON,\
                 edx, ecx, 0, hWnd, addr rect

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

RichEditProc ENDP

;=====================================================
; Subclass PROCEDURE for the Static Controls
;=====================================================
SaticProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpStatic, hwnd, wmsg, wparam, lparam
         ret

SaticProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Button Controls
;=====================================================
ButtonProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpButton, hwnd, wmsg, wparam, lparam
         ret

ButtonProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Edit Controls
;=====================================================
EditProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpEdit, hwnd, wmsg, wparam, lparam
         ret

EditProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Rich Edit Controls
;=====================================================
REditProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpREdit, hwnd, wmsg, wparam, lparam
         ret

REditProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Combobox Controls
;=====================================================
ComboProc  PROC  hwnd:DWORD, wmsg, wparam, lparam
LOCAL     TPrect:RECT
LOCAL     hEDC:DWORD
LOCAL     szBuff[128]:BYTE

      .if wmsg == WM_PAINT
            push     hCtrl
           push     CtrlType
         INVOKE     CallWindowProc, lpCombo, hwnd, wmsg, wparam, lparam
          MOVmd     hCtrl, hwnd
            mov     CtrlType, 7509
            mov     dis.itemID, 3 ;2^^^^^^^^^^^^^
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
           imul     edx, 4
            add     ecx, edx
         INVOKE     lstrcpy, addr szBuff, ecx

         INVOKE     GetClientRect, hwnd, addr TPrect
         INVOKE     GetDC, hwnd
            mov     hEDC, eax
            add     TPrect.left, 3
         INVOKE     SelectObject, hEDC, hFontS
         INVOKE     SetTextColor, hEDC, 0
         INVOKE     DrawText, hEDC, addr szBuff, -1, addr TPrect, DT_SINGLELINE or DT_LEFT or DT_VCENTER
         INVOKE     ReleaseDC, hwnd, hEDC
            pop     CtrlType
            pop     hCtrl
            jmp     Ret0
      .endif

      .if wmsg == 32
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
            mov     eax, 1
            ret
      .endif

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpCombo, hwnd, wmsg, wparam, lparam
         ret

Ret0:
         mov     eax, FALSE
         ret
ComboProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Listbox Controls
;=====================================================
ListboxProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpListbox, hwnd, wmsg, wparam, lparam
         ret

ListboxProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Treeview Controls
;=====================================================
TreeviewProc  PROC  hwnd:DWORD, wmsg, wparam, lparam
LOCAL     TPrect:RECT
LOCAL     hEDC:DWORD

      .if wmsg == WM_PAINT
         INVOKE     CallWindowProc, lpTreeview, hwnd, wmsg, wparam, lparam
         INVOKE     GetClientRect, hwnd, addr TPrect
         INVOKE     GetDC, hwnd
            mov     hEDC, eax
            add     TPrect.left, 3
         INVOKE     SelectObject, hEDC, hFontS
         INVOKE     SetTextColor, hEDC, 0
         INVOKE     DrawText, hEDC, addr szTreeV, -1, addr TPrect, DT_SINGLELINE or DT_LEFT
         INVOKE     ReleaseDC, hwnd, hEDC
            jmp     Ret0
      .endif

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpTreeview, hwnd, wmsg, wparam, lparam
         ret

Ret0:
         mov     eax, FALSE
         ret
TreeviewProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Listview Controls
;=====================================================
ListviewProc  PROC  hwnd:DWORD, wmsg, wparam, lparam
LOCAL     TPrect:RECT
LOCAL     hEDC:DWORD

      .if wmsg == WM_PAINT
         INVOKE     CallWindowProc, lpListview, hwnd, wmsg, wparam, lparam
         INVOKE     GetClientRect, hwnd, addr TPrect
         INVOKE     GetDC, hwnd
            mov     hEDC, eax
            add     TPrect.left, 3
            add     TPrect.top, 15
         INVOKE     SelectObject, hEDC, hFontS
         INVOKE     SetTextColor, hEDC, 0
         INVOKE     DrawText, hEDC, addr szListV, -1, addr TPrect, DT_SINGLELINE or DT_LEFT
         INVOKE     ReleaseDC, hwnd, hEDC
            jmp     Ret0
      .endif

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpListview, hwnd, wmsg, wparam, lparam
         ret

Ret0:
         mov     eax, FALSE
         ret
ListviewProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Toolbar Controls
;=====================================================
ToolbarProc  PROC  hwnd:DWORD, wmsg, wparam, lparam
LOCAL    tbb:TBBUTTON
LOCAL     ID:DWORD

      .if wmsg == WM_PAINT
         INVOKE     SendMessage, hwnd, TB_BUTTONCOUNT, 0, 0
         .if eax
               jmp     ThatsAll
         .endif
         INVOKE     SendMessage, hwnd, 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, hwnd, TB_SETBITMAPSIZE, 0, ecx
            pop     ecx
         INVOKE     SendMessage, hwnd, TB_SETBUTTONSIZE, 0, ecx
   
            mov     tbab.hInst, 0
           push     hTBBmpS
            pop     tbab.nID
         INVOKE     SendMessage, hwnd, TB_ADDBITMAP, 1, addr tbab ;23
   
;---------- [Create the Quick Code Toolbar structures] ----------
            mov     Cnt, 0
            mov     ID, 8501
         .while (Cnt < 6)
               mov     ecx, Cnt
               mov     edx, ID
            .if Cnt == 3
                TBSep     hwnd
                  mov     ecx, Cnt
                  mov     edx, ID
            .endif
            TBButt     hwnd, ecx, edx, 0
               inc     Cnt
               inc     ID
         .endw
         INVOKE     GetClientRect, hwnd, addr Srect
            mov     Srect.left, 0
            mov     Srect.top, 0
            mov     Srect.bottom, 28 ;23
         INVOKE     MoveWindow, hwnd, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
            jmp     ThatsAll
      .endif

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

ThatsAll:
      INVOKE     CallWindowProc, lpToolbar, hwnd, wmsg, wparam, lparam
         ret

ToolbarProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Statusbar Controls
;=====================================================
StatusbarProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpStatusbar, hwnd, wmsg, wparam, lparam
         ret

StatusbarProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Scrollbar Controls
;=====================================================
ScrollProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpScroll, hwnd, wmsg, wparam, lparam
         ret

ScrollProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Progessbar Controls
;=====================================================
ProgessProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_PAINT
         INVOKE     SendMessage, hwnd, PBM_SETSTEP, 100, 0
         INVOKE     SendMessage, hwnd, PBM_SETPOS, 25, 0
            jmp     ThatsAll
      .endif

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

ThatsAll:
      INVOKE     CallWindowProc, lpProgess, hwnd, wmsg, wparam, lparam
         ret

ProgessProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Trackbar Controls
;=====================================================
TrackbarProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpTrackbar, hwnd, wmsg, wparam, lparam
         ret

TrackbarProc  ENDP

;=====================================================
; Subclass PROCEDURE for the UpDown Controls
;=====================================================
UpDownProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpUpDown, hwnd, wmsg, wparam, lparam
         ret

UpDownProc  ENDP

;=====================================================
; Subclass PROCEDURE for the TabCtrl Controls
;=====================================================
TabCtrlProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_NCHITTEST
            mov     wmsg, WM_MOUSEMOVE
      .endif
      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpTabCtrl, hwnd, wmsg, wparam, lparam
         ret

TabCtrlProc  ENDP

;=====================================================
; Subclass PROCEDURE for the SysMonth Controls
;=====================================================
SysMonthProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpSysMonth, hwnd, wmsg, wparam, lparam
         ret

SysMonthProc  ENDP

;=====================================================
; Subclass PROCEDURE for the SysDateTimePick Controls
;=====================================================
SysPickProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpSysPick, hwnd, wmsg, wparam, lparam
         ret

SysPickProc  ENDP

;=====================================================
; Subclass PROCEDURE for the Animate Controls
;=====================================================
AnimateProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpAnimate, hwnd, wmsg, wparam, lparam
         ret

AnimateProc  ENDP

;=====================================================
; Subclass PROCEDURE for the IPAdress Controls
;=====================================================
IPAdressProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

;      .if wmsg == 32
;            mov     wmsg, WM_MOUSEMOVE
;      .endif

;      .if wmsg == 273
;            mov     wmsg, WM_LBUTTONDOWN
;      .endif

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpIPAdress, hwnd, wmsg, wparam, lparam
         ret

IPAdressProc  ENDP

;=====================================================
; Subclass PROCEDURE for the HotKey Controls
;=====================================================
HotKeyProc  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_LBUTTONDOWN || wmsg == WM_LBUTTONUP || wmsg == WM_MOUSEMOVE ||\
          wmsg == WM_RBUTTONDOWN || wmsg == WM_COMMAND || wmsg == WM_LBUTTONDBLCLK
         INVOKE     LoadCursor, 0, IDC_ARROW
         INVOKE     SetCursor, eax
         INVOKE     MouseMUD, hwnd, wmsg, wparam, lparam
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpHotKey, hwnd, wmsg, wparam, lparam
         ret

HotKeyProc  ENDP

;=====================================================
; CreateControls PROCEDURE
;=====================================================
CreateControls PROC  uses ebx esi edi hwnd:DWORD, SwOn
LOCAL    Crect:RECT
LOCAL    Erect:RECT
LOCAL    StrAddr:DWORD, StrOff, StrSave, w1, w2, hTemp, MemSave, BlockSize
LOCAL    szBuff1[512]:BYTE, szBuff2[20]:BYTE

      .if SwOn
            jmp     NoCreate
      .endif
         mov     byte ptr Ctrls.Code+20, 0
         mov     byte ptr Ctrls.Code+21, 0

      .if !sw44
            mov     Dlg.Chg, 1
            and     Dlg.Border, 0
            and     Ctrls.ExStyle, 0
            and     Ctrls.Style, 0
            mov     Ctrls.Chg, 1
            and     Ctrls.Border, 0
      .endif

      .if InputType == 7501
         .if !sw44     ; sw44 is from extract dialogs
            INVOKE     lstrcpy, addr szBuff1, addr szDlg
               mov     byte ptr Dlg.Code+30, '0'
               mov     byte ptr Dlg.Code+31, '0'
               mov     Dlg.ExStyle, WS_EX_TOOLWINDOW
               mov     Dlg.Style, WS_OVERLAPPED or WS_VISIBLE or WS_SYSMENU or WS_CAPTION
               mov     w1, WS_EX_TOOLWINDOW
               mov     w2, WS_OVERLAPPED or WS_VISIBLE or WS_SYSMENU or WS_CAPTION ;or\
;                           WS_CLIPCHILDREN or WS_CLIPSIBLINGS

               mov     Dlg.ExStyle, 0
               mov     Dlg.Style, 0
               mov     eax, InputType
               xor     eax, eax
               mov     ecx, 9
            .while (ecx)
                  mov     edx, dword ptr ddDlgD[eax]
                   or     Dlg.Style, edx
                  add     eax, 4
                  dec     ecx
            .endw
               mov     edx, dword ptr ddDlgD[eax]
                or     Dlg.ExStyle, edx
             MOVmd     w1, Dlg.ExStyle
             MOVmd     w2, Dlg.Style

         .else
            INVOKE     lstrcpy, addr szBuff1, addr Dlg.lpCaption
;               mov     w1, WS_EX_TOOLWINDOW                          ;Dlg.ExStyle
;               mov     w2, WS_OVERLAPPED or WS_SYSMENU or WS_CAPTION ;or\
;;                           WS_CLIPCHILDREN or WS_CLIPSIBLINGS        ;Dlg.Style

               mov     byte ptr Dlg.Code+30, '0'
               mov     eax, Dlg.ExStyle

            .if (eax & WS_EX_TOPMOST)
                  xor     eax, WS_EX_TOPMOST
                  mov     byte ptr Dlg.Code+30, '1'
            .endif
               mov     w1, eax

               mov     eax, Dlg.Style
            .if (eax & WS_VISIBLE)
                  xor     eax, WS_VISIBLE
            .endif
            .if (eax & WS_POPUP)
                  xor     eax, WS_POPUP
                  mov     byte ptr Dlg.Code+31, '1'
            .endif
            .if (eax & WS_CHILD)
               mov     eax, WS_OVERLAPPED or WS_SYSMENU or WS_CAPTION
            .endif
               mov     w2, eax
         .endif

         INVOKE     lstrcpy, addr szBuffT, addr szBuff1
         INVOKE     CreateWindowEx, w1,\
                    addr FormClass, addr szBuff1, w2,\
                    rect.left, rect.top, rect.right, rect.bottom, hwnd, 0, hInst, 0
            mov     hForm, eax

         .if hAsmEdit       ; From AsmEdit
               mov     ecx, hRetForm
               mov     eax, hForm
               mov     [ecx], eax
         .endif
            mov     IndexCnt, 0

         INVOKE     DialogDlg, hDlg2, WM_COMMAND, 620, 0
            mov     eax, hForm

      .elseif InputType == 7502
         .if (Ctrls.ExStyle & WS_EX_TRANSPARENT)
               xor     Ctrls.Style, SS_NOTIFY
         .endif
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or SS_NOTIFY

      .elseif InputType == 7503
         INVOKE     CreateWindowEx, 0, addr GroupClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS,\
                    rect.left, rect.top, rect.right, rect.bottom, hwnd, 0, hInst, 0
            mov     hTemp, eax
            mov     hGrp, eax

           push     rect.left
           push     rect.top
            mov     rect.left, 0
            mov     rect.top, 0
         INVOKE     CreateWin, hTemp, 0, WS_CHILD or WS_VISIBLE or BS_GROUPBOX
            pop     rect.top
            pop     rect.left

;---------- [Save the Groupbox and its parent handle] ----------
      .if GrpCnt >= 256 ;128
            mov     LinitReached, 1
         INVOKE     MessageBox, NULL, addr szError3, addr AppName, MB_OK
            jmp     Ret0
      .endif
            mov     edx, hTemp
            mov     ecx, GrpCnt
            mov     hGrpArray+[ecx*8], edx      ; Save parent handle
            mov     hGrpArray+[ecx*8+4], eax    ; Save control handle
            inc     GrpCnt
            and     xGrp, 0
            and     yGrp, 0
           push     eax
         INVOKE     BringWindowToTop, hGrp
            pop     eax

      .elseif InputType == 7504
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or BS_AUTORADIOBUTTON or WS_TABSTOP

      .elseif InputType == 7505
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or BS_AUTOCHECKBOX or WS_TABSTOP

      .elseif InputType == 7506
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or WS_TABSTOP

      .elseif InputType == 7507
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or WS_TABSTOP

      .elseif InputType == 7508
         INVOKE     CreateWin, hwnd, WS_EX_CLIENTEDGE, WS_CHILD or WS_VISIBLE or\
                    ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or WS_TABSTOP

;CBS_DROPDOWNLIST
      .elseif InputType == 7509
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or WS_VSCROLL or\
                    CBS_HASSTRINGS or CBS_DROPDOWNLIST or CBS_SORT or\
                    CBS_NOINTEGRALHEIGHT
            mov     ecx, Ctrls.Style
         .if (ecx & WS_VSCROLL)
               mov     byte ptr Ctrls.Code+20, '1' ; Set VSCROLL code
         .endif
         .if (ecx & WS_VSCROLL)
               mov     byte ptr Ctrls.Code+21, '1' ; Set HSCROLL code
         .endif

      .elseif InputType == 7510
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or WS_VSCROLL or\
                    LBS_HASSTRINGS or LBS_NOTIFY or LBS_NOINTEGRALHEIGHT
            mov     ecx, Ctrls.Style
         .if (ecx & WS_VSCROLL)
               mov     byte ptr Ctrls.Code+20, '1' ; Set VSCROLL code
         .endif
         .if (ecx & WS_VSCROLL)
               mov     byte ptr Ctrls.Code+21, '1' ; Set HSCROLL code
         .endif

      .elseif InputType == 7511
         INVOKE     CreateWin, hwnd, WS_EX_CLIENTEDGE, WS_CHILD or WS_VISIBLE or TVS_HASBUTTONS or\
                    TVS_LINESATROOT or TVS_SHOWSELALWAYS

      .elseif InputType == 7512
         INVOKE     CreateWin, hwnd, WS_EX_CLIENTEDGE, WS_CHILD or WS_VISIBLE or LVS_REPORT or\
                    LVS_SORTASCENDING or LVS_SHOWSELALWAYS

      .elseif InputType == 7513
            mov     ToolOn, 1
            mov     rect.left, 0
            mov     rect.top, 0
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS or\
                    WS_BORDER

      .elseif InputType == 7514
            mov     StatusOn, 1
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or SBARS_SIZEGRIP

      .elseif InputType == 7515
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7516
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or SBS_VERT

      .elseif InputType == 7517
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7518
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7519
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7520
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7521
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7522
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7523
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or SS_NOTIFY or\
                    SS_BITMAP or SS_REALSIZEIMAGE

      .elseif InputType == 7524
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or SS_NOTIFY or\
                    SS_ICON or SS_REALSIZEIMAGE

      .elseif InputType == 7525
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE or SS_NOTIFY or\
                    SS_ICON or SS_REALSIZEIMAGE

      .elseif InputType == 7526
;---------- [Create a static Control Window] ----------
         INVOKE     CreateWindowEx, 0, addr StaticClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_CLIPSIBLINGS or SS_NOTIFY,\
                    rect.left, rect.top, 33, 33, hwnd, 2001, hInst, NULL
            mov     hTemp, eax
;ACS_CENTER or WS_BORDER or or SS_NOTIFY
           push     rect.left
           push     rect.top
            mov     rect.left, 0
            mov     rect.top, 0
         INVOKE     CreateWin, hTemp, 0, WS_CHILD or WS_VISIBLE or\
                    ACS_TIMER or ACS_TRANSPARENT or ACS_CENTER
            pop     rect.top
            pop     rect.left
            mov     ecx, AniCnt
            mov     hAniArray+[ecx*4], eax      ; Save parent handle
            inc     AniCnt

      .elseif InputType == 7527
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7528
         INVOKE     CreateWin, hwnd, 0, WS_CHILD or WS_VISIBLE

      .elseif InputType == 7529
         INVOKE     CreateWin, hwnd, WS_EX_STATICEDGE or WS_EX_CLIENTEDGE or WS_EX_DLGMODALFRAME,\
                                     WS_CHILD or WS_VISIBLE or WS_BORDER

      .elseif InputType == 7530

      .else
            mov     eax, -1
            ret
      .endif

         mov     hCtrl, eax
       MOVmd     CtrlType, InputType
      .if CtrlType != 7501
          MOVmd     hSMove, hCtrl
          MOVmd     CtrlHnd, hCtrl
          MOVmd     SavCtrl, InputType
      .endif
and     xGrp, 0
and     yGrp, 0

      .if !KeepOn
         .if InputType != 7501
            INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, CtrlType, FALSE
               and     InputType, 0
         .endif
      .endif

      .if CtrlType == 7520
           call     DoTabs
      .endif

      .if CtrlType == 7523
         INVOKE     SendMessage, hCtrl, STM_SETIMAGE, IMAGE_BITMAP, hBmpR
         INVOKE     MoveWindow, hCtrl, rect.left, rect.top, rect.right, rect.bottom, TRUE
      .endif

      .if CtrlType == 7524
         INVOKE     SendMessage, hCtrl, STM_SETIMAGE, IMAGE_ICON, hIcoR
         INVOKE     MoveWindow, hCtrl, rect.left, rect.top, rect.right, rect.bottom, TRUE
      .endif

      .if CtrlType == 7525
            mov     rect.right, 32
            mov     rect.bottom, 32
         INVOKE     SendMessage, hCtrl, STM_SETIMAGE, IMAGE_ICON, hIcon
         INVOKE     MoveWindow, hCtrl, rect.left, rect.top, rect.right, rect.bottom, TRUE
      .endif

      .if CtrlType == 7526
         INVOKE     lstrcpy, addr szBuff1, addr RootPath
         INVOKE     lstrcat, addr szBuff1, addr szBackS
         INVOKE     lstrcat, addr szBuff1, addr szAnimateAvi
            mov     rect.right, 33
            mov     rect.bottom, 33
         INVOKE     MoveWindow, hCtrl, 0, 0, rect.right, rect.bottom, TRUE
         INVOKE     SendMessage, hCtrl, ACM_OPEN, 0, addr szBuff1
         INVOKE     ShowWindow, hCtrl, SW_SHOW
            mov     ecx, -1
            shl     ecx, 16
            mov     ax, -1
            mov     cx, ax
         INVOKE     SendMessage, hCtrl, ACM_PLAY, 20, ecx
mov     eax, hTemp
mov     hCtrl, eax
      .endif

      .if CtrlType != 7527
         INVOKE     SendMessage, hCtrl, WM_SETFONT, hFontS, TRUE
      .else
;         INVOKE     SendMessage, hCtrl, WM_SETFONT, hFontIP, TRUE
      .endif

;---------- [Get the control count] ----------
         mov     eax, CtrlType
         sub     eax, 7501
         mov     ecx, CtrlCnt+[eax*4]
         mov     Cnt, ecx

      .if CtrlType == 7501
            mov     edx, CtrlCnt
            inc     edx
          MOVmd     StartID+[edx*4], Dlg.StartID
      .endif

      .if !IDCnt && CtrlType != 7501
          MOVmd     IDCnt, Dlg.StartID
            dec     IDCnt
      .endif

      .if CtrlType != 7501
            inc     TabIDCnt
            inc     IDCnt
           push     hCtrl
           push     CtrlType
          MOVmd     hCtrl, hForm
            mov     CtrlType, 7501
            mov     dis.itemID, 0
;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
          MOVmd     StartID+[ebx*4+4], IDCnt
            pop     CtrlType
            pop     hCtrl
      .endif

;      .if !sw44
;---------- [Save the handle - type - cnt] ----------
      .if ArrayCnt >= 8192 ;2048 ;1024 ;512
            mov     LinitReached, 1
         INVOKE     MessageBox, NULL, addr szError3, addr AppName, MB_OK
            jmp     Ret0
      .endif
         mov     ecx, hCtrl
         mov     eax, ArrayCnt
         mov     hArray+[eax*8+4], ecx    ; Save control handle
         mov     edx, Cnt
         shl     edx, 16
         mov     dx, word ptr CtrlType
         mov     hArray+[eax*8], edx      ; Save control type & cnt
         inc     ArrayCnt
         and     CtrlOn, 0
         mov     StrSave, edx
;DSPValue hWndStat, ArrayCnt, 1, 's'

;      .else
;         mov     ecx, hCtrl
;         mov     eax, TempACnt
;         mov     hTempA+[eax*8+4], ecx    ; Save control handle
;         mov     edx, Cnt
;         shl     edx, 16
;         mov     dx, word ptr CtrlType
;         mov     hTempA+[eax*8], edx      ; Save control type & cnt
;         inc     TempACnt
;         and     CtrlOn, 0
;         mov     StrSave, edx
;      .endif

      .if CtrlType == 7501
            lea     ecx, offset Dlg
            mov     eax, sizeof Dlg
      .else
            lea     ecx, offset Ctrls
            mov     eax, sizeof Ctrls
          MOVmd     Ctrls.TabIndex, TabIDCnt
      .endif

         mov     StrSize, eax
         mov     StrAddr, ecx

;---------- [Set the ID - name - caption] ----------
      .if CtrlType != 7501
            mov     eax, IDCnt
         .if !sw44 || PasteOn
               mov     dword ptr[ecx], eax
         .else
            .if !dword ptr[ecx]
                  mov     dword ptr[ecx], eax
            .endif
         .endif
      .else
            mov     eax, Dlg.StartID
            dec     eax
         .if !sw44
               mov     dword ptr[ecx], eax
         .else
            .if !dword ptr[ecx]
                  mov     dword ptr[ecx], eax
            .endif
         .endif
mov     IDCnt, eax
and     TabIDCnt, 0
      .endif

         inc     Cnt
      INVOKE     BaseAscii, Cnt, addr szBuff2, 2, 10, 1, 1, 0
         dec     Cnt

      .if CtrlType == 7501
;            mov     StrOff, 104   ;++++++
            lea     eax, Dlg.lpName
            sub     eax, DlgStart
            mov     StrOff, eax
      .else
         .if PasteOn
               mov     Ctrls.Chg, 1
         .endif
;            mov     StrOff, 4     ;++++++
            lea     eax, Ctrls.lpName
            sub     eax, CtrlsStart
            mov     StrOff, eax
      .endif

      .if !UseIDOn
            mov     ecx, StrAddr
            add     ecx, StrOff
.if !sw44 || PasteOn
         INVOKE     lstrcpy, ecx, addr szBuffT
.endif
            mov     ecx, StrAddr
            add     ecx, StrOff
           push     ecx
.if !sw44 || PasteOn
         INVOKE     lstrcat, ecx, addr szBuff2
.endif

      .else
            mov     ecx, IDCnt
         .if CtrlType == 7501
               mov     ecx, Dlg.StartID
               dec     ecx
         .endif
         INVOKE     BaseAscii, ecx, addr szBuff2, 2, 10, 1, 1, 0
            mov     ecx, StrAddr
            add     ecx, StrOff
           push     ecx
         INVOKE     lstrcpy, ecx, addr szBuff2
      .endif

         pop     ecx
      INVOKE     SendMessage, hWndCombo, CB_ADDSTRING, 0, ecx
        push     eax
      INVOKE     SendMessage, hWndCombo, CB_SETITEMDATA, eax, StrSave  ; = CntType
         pop     eax
      INVOKE     SendMessage, hWndCombo, CB_SETCURSEL, eax, 0

      .if CtrlType == 7501
;            mov     StrOff, 168 ;+++++++
            lea     eax, Dlg.lpCaption
            sub     eax, DlgStart
            mov     StrOff, eax

      .else
;            mov     StrOff, 36  ;+++++++
            lea     eax, Ctrls.lpCaption
            sub     eax, CtrlsStart
            mov     StrOff, eax
      .endif
         mov     ecx, StrAddr
         add     ecx, StrOff
      INVOKE     lstrcpy, ecx, addr szBuffT

      .if CtrlType != 7501 ;&& !sw44 ; Removed 08-17-2003
            mov     eax, CtrlType
            sub     eax, 7501
            mov     ecx, ClassArray[eax*4]
         INVOKE     lstrcpy, addr Ctrls.Class, ecx
         .if CtrlType == 7529
            INVOKE     lstrcpy, addr Ctrls.Class, addr CustClass
         .endif
      .endif

;---------- [Update the structure with the parent handle - type - cnt - border] ----------
         mov     ecx, StrAddr
         add     ecx, StrSize
         sub     ecx, 4
       MOVmd     [ecx], hForm
         sub     ecx, 4
       MOVmd     [ecx], StrSave
         sub     ecx, 4
      .if CtrlType != 7501
            mov     edx, Ctrls.Style
      .else
            mov     edx, Dlg.Style
      .endif
         and     edx, 00f00000h
      .if edx == WS_BORDER
            mov     edx, 1
            mov     [ecx], edx
      .endif

         lea     eax, Ctrls.Code
         sub     eax, CtrlsStart
         add     eax, 20
         mov     StrOff, eax
         mov     ecx, StrAddr
         add     ecx, StrOff
         mov     byte ptr [ecx], '0'         ; Clear VSCROLL code
         mov     byte ptr [ecx+1], '0'       ; Clear HSCROLL code
      .if CtrlType > 7506 && CtrlType < 7513
            mov     eax, Ctrls.Style
         .if (eax & WS_VSCROLL)
               mov     byte ptr [ecx], '1'   ; Set VSCROLL code
         .endif
         .if (eax & WS_HSCROLL)
               mov     byte ptr [ecx+1], '1' ; Set VSCROLL code
         .endif
      .endif

;---------- [Allocate or reallocate memory] ----------
         mov     ecx, CtrlType
         sub     ecx, 7501
         mov     MemSave, ecx
      .if dword ptr hDlgMem+[ecx*4] == 0
         INVOKE     HeapAlloc, hDefHeap, HEAP_ZERO_MEMORY, 5000
            mov     ecx, MemSave
            mov     offset dword ptr hDlgMem+[ecx*4], eax

      .else
            mov     ebx, dword ptr hDlgMem+[ecx*4] ; Structure memory address
           push     ebx
            mov     eax, Cnt
           imul     eax, StrSize                   ; Size of the structure
            add     ebx, eax                       ; Offset the number of structures
           push     ebx
         INVOKE     HeapSize, hDefHeap, 0, dword ptr hDlgMem+[ecx*4]
            mov     BlockSize, eax
            pop     ebx
            pop     edx
            add     edx, eax
            sub     edx, StrSize
         .if ebx > edx
               add     BlockSize, 5000
               mov     ecx, MemSave
            INVOKE     HeapReAlloc, hDefHeap, HEAP_GENERATE_EXCEPTIONS or HEAP_ZERO_MEMORY,\
                       offset dword ptr hDlgMem+[ecx*4], BlockSize
            .if eax == STATUS_NO_MEMORY || eax == STATUS_ACCESS_VIOLATION || eax == 0
                  mov     LinitReached, 1
               INVOKE     MessageBox, NULL, addr szError3, addr AppName, MB_OK
                  jmp     Ret0
            .endif
               mov     ecx, MemSave
               mov     offset dword ptr hDlgMem+[ecx*4], eax  ; Dies  !!!!!!!!!!!!!!!!
         .endif
      .endif

;   mov     ecx, MemSave
;INVOKE     HeapSize, hDefHeap, 0, dword ptr hDlgMem+[ecx*4]
;DSPValue hWndStat, eax, 1, 's'

;---------- [Load the control structure into memory] ----------
         mov     esi, StrAddr                      ; Address of the structure
         mov     ecx, StrSize                      ; Size of the structure
         mov     eax, CtrlType
         sub     eax, 7501
         mov     edi, dword ptr hDlgMem+[eax*4]    ; Structure memory address
         mov     eax, Cnt
        imul     eax, ecx
         add     edi, eax                          ; Offset the number of structures
         rep     movsb                             ; Load the structure

         mov     eax, CtrlType
         sub     eax, 7501
         add     CtrlCnt+[eax*4], 1

NoCreate:
      .if CtrlType == 7502
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, SaticProc
            mov     lpStatic, eax

      .elseif CtrlType == 7503
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ButtonProc
            mov     lpButton, eax

      .elseif CtrlType > 7503 && CtrlType < 7507
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ButtonProc
            mov     lpButton, eax

      .elseif CtrlType == 7507
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, EditProc
            mov     lpEdit, eax

      .elseif CtrlType == 7508
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, REditProc
            mov     lpREdit, eax

      .elseif CtrlType == 7509
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ComboProc
            mov     lpCombo, eax
         INVOKE     GetParent, hCtrl
            mov     hParent, eax
         INVOKE     RedrawWindow, hParent, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_UPDATENOW or RDW_ALLCHILDREN

      .elseif CtrlType == 7510
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ListboxProc
            mov     lpListbox, eax
;         INVOKE     SendMessage, hCtrl, LB_ADDSTRING, 0, addr szListB

      .elseif CtrlType == 7511
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, TreeviewProc
            mov     lpTreeview, eax

      .elseif CtrlType == 7512
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ListviewProc
            mov     lpListview, eax

      .elseif CtrlType == 7513
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ToolbarProc
            mov     lpToolbar, eax

      .elseif CtrlType == 7514
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, StatusbarProc
            mov     lpStatusbar, eax

      .elseif CtrlType == 7515
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ScrollProc
            mov     lpScroll, eax

      .elseif CtrlType == 7516
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ScrollProc
            mov     lpScroll, eax

      .elseif CtrlType == 7517
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ProgessProc
            mov     lpProgess, eax

      .elseif CtrlType == 7518
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, TrackbarProc
            mov     lpTrackbar, eax

      .elseif CtrlType == 7519
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, UpDownProc
            mov     lpUpDown, eax

      .elseif CtrlType == 7520
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, TabCtrlProc
            mov     lpTabCtrl, eax

      .elseif CtrlType == 7521
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, SysMonthProc
            mov     lpSysMonth, eax

      .elseif CtrlType == 7522
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, SysPickProc
            mov     lpSysPick, eax

      .elseif CtrlType == 7523
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, SaticProc
            mov     lpStatic, eax

      .elseif CtrlType == 7524
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, SaticProc
            mov     lpStatic, eax

      .elseif CtrlType == 7525
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, SaticProc
            mov     lpStatic, eax

      .elseif CtrlType == 7526
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, SaticProc
            mov     lpStatic, eax

      .elseif CtrlType == 7527
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, IPAdressProc
            mov     lpIPAdress, eax

      .elseif CtrlType == 7528
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, HotKeyProc
            mov     lpHotKey, eax

      .elseif CtrlType == 7529
         INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, ButtonProc
            mov     lpButton, eax

      .elseif CtrlType == 7530

      .else
            mov     eax, -1
            ret
      .endif

      .if SwOn
            jmp     Ret0
      .endif

      INVOKE     BringWindowToTop, hCtrl
      INVOKE     CopyRect, addr Srect, addr rect

      .if hGrpOn
         INVOKE     GetWindowRect, hForm, addr Crect
         INVOKE     GetWindowRect, hGrp, addr Erect
               mov     eax, Erect.left
               sub     eax, Crect.left
               sub     eax, SizeB
               add     Srect.left, eax
               mov     eax, Erect.top
               sub     eax, Crect.top
               sub     eax, SizeT
               add     Srect.top, eax
      .endif

      .if CtrlType == 7513 || CtrlType == 7514
         INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234
         .if CtrlType == 7513
               mov     Srect.left, 0
               mov     Srect.top, 0
               mov     Srect.bottom, 28 ;33
         .endif
      .endif

      INVOKE     MoveGrabbers, 5, 0

      .if CtrlType == 7503 && !sw44 || CtrlType == 7503 && PasteOn
            mov     eax, Srect.left
            add     Srect.right, eax
            mov     eax, Srect.top
            add     Srect.bottom, eax
           call     ChkUnder
      .endif

Ret0:
         xor     eax, eax
         ret
CreateControls ENDP

;=====================================================
; Create windows PROCEDURE
;=====================================================
CreateWin  PROC hwnd:DWORD, dwEXStyle, dwStyle
LOCAL    cAddr:DWORD, tAddr

         mov     eax, InputType
         sub     eax, 7501
       MOVmd     cAddr, ClassArray[eax*4]
      .if !sw44
          MOVmd     tAddr, TextArray[eax*4]
         INVOKE     lstrcpy, addr szBuffT, tAddr
          MOVmd     Ctrls.ExStyle, dwEXStyle
          MOVmd     Ctrls.Style, dwStyle

         .if InputType < 7513
               mov     Ctrls.ExStyle, 0
               mov     Ctrls.Style, 0
               mov     eax, InputType
               sub     eax, 7501
              imul     eax, 40
               mov     ecx, 9
            .while (ecx)
                  mov     edx, dword ptr ddDlgD[eax]
                   or     Ctrls.Style, edx
                  add     eax, 4
                  dec     ecx
            .endw
               mov     edx, dword ptr ddDlgD[eax]
                or     Ctrls.ExStyle, edx
             MOVmd     dwEXStyle, Ctrls.ExStyle
             MOVmd     dwStyle, Ctrls.Style
         .endif

      .else
          MOVmd     dwEXStyle, Ctrls.ExStyle
          MOVmd     dwStyle, Ctrls.Style
            lea     eax, Ctrls.lpCaption
            mov     tAddr, eax
         .if PasteOn
               mov     eax, InputType
               sub     eax, 7501
             MOVmd     tAddr, TextArray[eax*4]
         .endif
         INVOKE     lstrcpy, addr szBuffT, tAddr
      .endif

         mov     eax, hwnd
;      .if eax == hForm
             or     dwStyle, WS_CLIPSIBLINGS
;      .endif

      INVOKE     CreateWindowEx, dwEXStyle, cAddr, tAddr, dwStyle,\
                 rect.left, rect.top, rect.right, rect.bottom, hwnd, InputType, hInst, 0

      .if InputType == 7510
            mov     ecx, eax
           push     eax
         INVOKE     SendMessage, ecx, LB_ADDSTRING, 0, tAddr
            pop     eax
      .endif

      .if InputType == 7519
            mov     ecx, eax
           push     eax
         INVOKE     MoveWindow, ecx, rect.left, rect.top, rect.right, rect.bottom, TRUE
            pop     eax
      .endif

         ret
CreateWin  ENDP

;=====================================================
; Insert Tab item PROCEDURE
;=====================================================
DoTabs PROC
LOCAL     pt:POINT

;---------- [Fill the Tab Control Item structure and insert the item] ----------
         mov     tci.imask, TCIF_TEXT             ; Text
         mov     tci.lpReserved1, 0               ; Reserved
         mov     tci.lpReserved2, 0               ; Reserved
         mov     tci.pszText, offset TabTitle1    ; pointer to string containing tab text 
         mov     tci.cchTextMax, sizeof TabTitle1 ; Size of TabTitle1
         mov     tci.iImage, -1                   ; Index to tab control's image 
         mov     tci.lParam, 0                    ; Extra info
      INVOKE     SendMessage, hCtrl, TCM_INSERTITEM, 0, offset tci

         mov     tci.pszText, offset TabTitle2
         mov     tci.cchTextMax, sizeof TabTitle2
      INVOKE     SendMessage, hCtrl, TCM_INSERTITEM, 1, addr tci

         ret
DoTabs ENDP

;=====================================================
; ChkMatch PROCEDURE
;=====================================================
ChkMatch PROC
LOCAL    ft:FINDTEXT
LOCAL    CntB:DWORD, CntE

            and     CntB, 0
            and     CntE, 0
            mov     ft.chrg.cpMin, 0
            mov     ft.chrg.cpMax, -1
            lea     eax, offset szFindB
            mov     ft.lpstrText, eax

FindNextB:
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax != -1
               inc     CntB
               inc     eax
               mov     ft.chrg.cpMin, eax
               jmp     FindNextB
         .endif
            mov     ft.chrg.cpMin, 0
            mov     ft.chrg.cpMax, -1
            lea     eax, offset szFindE
            mov     ft.lpstrText, eax

FindNextE:
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax != -1
               inc     CntE
               inc     eax
               mov     ft.chrg.cpMin, eax
               jmp     FindNextE
         .endif
            mov     eax, CntB
         .if eax != CntE
            INVOKE     MessageBox, NULL, addr szError2, addr AppName, MB_OK
               mov     eax, -1
         .else
               xor     eax, eax
         .endif
         ret
ChkMatch ENDP

;=====================================================
; Fills a buffer with a character.
;=====================================================
FillBuffer PROC  uses esi edi  Input:DWORD, SizeBuf:DWORD, Fill:BYTE, TermA:DWORD
         mov     esi, Input
         mov     edi, esi           ; Dest = Source
         mov     ecx, SizeBuf       ; 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

;=====================================================
; Subclass PROCEDURE for the Static rect Control
;=====================================================
SaticProcR  PROC  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_ERASEBKGND
            mov     eax, 1
            ret
      .endif

      INVOKE     CallWindowProc, lpStaticR, hwnd, wmsg, wparam, lparam
         ret

SaticProcR  ENDP

;=====================================================
; Move grappers PROCEDURE
;=====================================================
MoveGrabbers  PROC  uses ebx esi edi  Var:DWORD, NoLoad
LOCAL    Frect:RECT
LOCAL    StrCnt:DWORD
LOCAL    szBuff[256]:BYTE

      .if NoLoad == 4
            jmp     LoadStruct
      .endif
         mov     eax, Srect.bottom
         shr     eax, 1
         mov     edx, Srect.top
         add     edx, eax
         sub     edx, 2
         mov     ecx, Srect.left
         sub     ecx, Var
        push     edx
      .if Var == 2
            add     ecx, 2
      .endif
      INVOKE     MoveWindow, hSizeL, ecx, edx, 5, 5, TRUE
         pop     edx
         mov     ecx, Srect.left
         add     ecx, Srect.right
      .if Var == 2
            sub     ecx, 5
      .endif
      INVOKE     MoveWindow, hSizeR, ecx, edx, 5, 5, TRUE

         mov     eax, Srect.right
         shr     eax, 1
         mov     edx, Srect.left
         add     edx, eax
         sub     edx, 2
         mov     ecx, Srect.top
         sub     ecx, Var
        push     edx
      .if Var == 2
            add     ecx, 2
      .endif
      INVOKE     MoveWindow, hSizeT, edx, ecx, 5, 5, TRUE
         pop     edx
         mov     ecx, Srect.top
         add     ecx, Srect.bottom
      .if Var == 2
            sub     ecx, 5
      .endif
      INVOKE     MoveWindow, hSizeB, edx, ecx, 5, 5, TRUE

      INVOKE     RedrawWindow, hSizeL, 0, 0,\
                 RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_NOCHILDREN
      INVOKE     RedrawWindow, hSizeT, 0, 0,\
                 RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_NOCHILDREN
      INVOKE     RedrawWindow, hSizeR, 0, 0,\
                 RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_NOCHILDREN
      INVOKE     RedrawWindow, hSizeB, 0, 0,\
                 RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_NOCHILDREN
      INVOKE     SetWindowPos, hSizeL, HWND_TOP,\
                 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
      INVOKE     SetWindowPos, hSizeT, HWND_TOP,\
                 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
      INVOKE     SetWindowPos, hSizeR, HWND_TOP,\
                 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
      INVOKE     SetWindowPos, hSizeB, HWND_TOP,\
                 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE

LoadStruct:
      .if NoLoad == 1
            jmp     Ret0
      .endif
      INVOKE     SendMessage, hWndList, LB_RESETCONTENT, 0, 0
      .if CtrlType == 7501
            lea     ecx, offset szDialog
      .else
            lea     ecx, offset szCtrl
      .endif
         xor     eax, eax

Getlen:
      .if byte ptr[ecx+eax] == 2ch
            mov     Len, eax
            inc     Len
           push     ecx
         INVOKE     lstrcpyn, addr szBuff, ecx, Len
         INVOKE     SendMessage, hWndList, LB_ADDSTRING, 0, addr szBuff
            pop     ecx
            add     ecx, Len
            xor     eax, eax
            jmp     Getlen
      .elseif byte ptr[ecx+eax] == 0h
            jmp     DoUpdate
      .endif
         inc     eax
         jmp     Getlen

DoUpdate:
.if CtrlType == 7503
         xor     eax, eax
         mov     edx, hGrp
         mov     ecx, GrpCnt ;32
      .while (ecx)                       ; Find handle of Groupbox in the array
         .if hGrpArray[eax] == edx
             MOVmd     hCtrl, hGrpArray[eax+4]
            .break  
         .endif
            add     eax, 8
            dec     ecx
      .endw
.endif
         mov     eax, CtrlType
         sub     eax, 7501
         mov     ecx, CtrlCnt+[eax*4]
         mov     StrCnt, ecx

      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szName
         mov     dis.itemID, eax
;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
        imul     edx, 4
         add     ecx, edx
      INVOKE     lstrcpy, addr szBuff, ecx
      INVOKE     SendMessage, hWndCombo, CB_FINDSTRINGEXACT, 0, addr szBuff
      INVOKE     SendMessage, hWndCombo, CB_SETCURSEL, eax, 0

;      INVOKE     GetWindowLong, hCtrl, GWL_EXSTYLE
;        push     eax
      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szExStyle
         mov     dis.itemID, eax

;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
mov     eax, dword ptr [ecx+edx*4] ;!
;         pop     eax

.if dword ptr [ecx+edx*4] == 0
      mov     eax, 0
.endif
        push     ecx
         add     ecx, DlgCode
;      .if CtrlType == 7501 && byte ptr [ecx+738] == '1'
      .if CtrlType == 7501 && byte ptr [ecx+30] == '1'
             or     eax, WS_EX_TOPMOST
      .endif
         pop     ecx ;eax   ; This caused two days of work!!!!!!!!!!!!!
         mov     dword ptr [ecx+edx*4], eax

      INVOKE     GetWindowLong, hCtrl, GWL_STYLE
        push     eax
      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szStyle
         mov     dis.itemID, eax

;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
         mov     SavOff, ecx

;---------- [Update the border and handle in the structure] ----------
        push     dis.itemID
        push     edx
         mov     dis.itemID, 0
      INVOKE     GetOffset, 0
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
        push     ecx
      .if CtrlType == 7501
            add     ecx, DlgBorder
            mov     ebx, dword ptr[ecx]
      .else
            add     ecx, CtrlsBorder
            mov     ebx, dword ptr[ecx]
      .endif
      .if ebx
            mov     ebx, WS_BORDER
      .endif
         pop     ecx
         pop     edx
         pop     dis.itemID

         pop     eax
          or     eax, ebx
;      .if CtrlType == 7503
;            and     eax, 0fffffff7h
;      .endif
         mov     ebx, ecx ;SavOff
         add     ebx, DlgCode
;      .if CtrlType == 7501 && byte ptr [ebx+739] == '1'
      .if CtrlType == 7501 && byte ptr [ebx+31] == '1'
             or     eax, WS_POPUP
      .endif

      .if CtrlType > 7506 && CtrlType < 7513
            mov     ebx, ecx ;SavOff
            add     ebx, CtrlsCode

;         .if byte ptr [ebx+628] == '1' ; Set VSCROLL code
         .if byte ptr [ebx+20] == '1' ; Set VSCROLL code
                or     eax, WS_VSCROLL
         .endif
;         .if byte ptr [ebx+629] == '1' ; Set HSCROLL code
         .if byte ptr [ebx+21] == '1' ; Set HSCROLL code
                or     eax, WS_HSCROLL
         .endif
      .endif
         mov     ecx, SavOff
         mov     dword ptr [ecx+edx*4], eax

;---------- [Update the position & size] ----------
      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szLeft
         mov     dis.itemID, eax
;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     StrSize, eax
         mov     eax, Srect.left
      .if CtrlType == 7501
            mov     eax, xOff ;FormX
      .endif
        imul     ebx, StrSize
         add     ecx, ebx
         mov     dword ptr [ecx+edx*4], eax

      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szTop
         mov     dis.itemID, eax
;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     eax, Srect.top
      .if CtrlType == 7501
            mov     eax, yOff ;FormY
      .endif
        imul     ebx, StrSize
         add     ecx, ebx
         mov     dword ptr [ecx+edx*4], eax

      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szWidth
         mov     dis.itemID, eax
;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     eax, Srect.right
      .if CtrlType == 7501
;            add     eax, 6
            add     eax, SizeB
            add     eax, SizeB
      .endif
        imul     ebx, StrSize
         add     ecx, ebx
         mov     dword ptr [ecx+edx*4], eax

      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szHeight
         mov     dis.itemID, eax
;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     eax, Srect.bottom
      .if CtrlType == 7501
;            add     eax, 22
            add     eax, SizeT
            add     eax, SizeB
      .endif
        imul     ebx, StrSize
         add     ecx, ebx
         mov     dword ptr [ecx+edx*4], eax

;      INVOKE     SendMessage, hWndList, LB_SETCURSEL, dis.itemID, 0
;      INVOKE     SendMessage, hWndList, LB_SETCURSEL, -1, 0
      INVOKE     SendMessage, hWndList, LB_GETTOPINDEX, 0, 0
      INVOKE     SendMessage, hWndList, LB_SETTOPINDEX, eax, 0
      INVOKE     SendMessage, hWndList, LB_SETCURSEL, -1, 0

Ret0:
         mov     eax, FALSE
         ret
MoveGrabbers ENDP

;=====================================================
; x - y position PROCEDURE
;=====================================================
PosProc  PROC  hwnd:DWORD, xPosB, yPosB, PosType
LOCAL    pt:POINT
LOCAL    Crect:RECT

      INVOKE     GetCursorPos, addr pt
      INVOKE     ScreenToClient, hwnd, addr pt
      INVOKE     GetWindowRect, hwnd, addr Crect
         mov     eax, Crect.left
         mov     ecx, eax
         add     eax, PosType
         add     pt.x, eax
         mov     eax, Crect.top
         mov     edx, eax
         add     eax, PosType
         add     pt.y, eax
         sub     Crect.right, ecx
         sub     Crect.bottom, edx
         mov     eax, hwnd
      .if PosType == 12 || PosType == 15 || PosType == 8 || PosType == 11 || PosType == 13
         INVOKE     BaseAscii, xPosB, addr XNum, 1, 10, 1, 1, 0
         INVOKE     BaseAscii, yPosB, addr YNum, 1, 10, 1, 1, 0
         .if PosType == 8 || PosType == 15
              add     pt.y, 15
            .if PosType == 8
                  sub     pt.x, 2
                  dec     pt.y
            .endif
         .endif
         .if PosType == 12 && hParent
            sub     pt.x, 6
            sub     pt.y, 6
         .endif
         .if PosType == 13
            sub     pt.x, 10
            sub     pt.y, 10
         .endif

      .else
            mov     ecx, rect.right
            sub     ecx, rect.left
            mov     edx, rect.bottom
            sub     edx, rect.top
         .if InputType == 7501 || PosType == 7
               sub     pt.x, 4
               sub     pt.y, 4
         .else
               add     pt.y, 16
         .endif
         INVOKE     BaseAscii, ecx, addr XNum, 1, 10, 1, 1, 0
         INVOKE     BaseAscii, edx, addr YNum, 1, 10, 1, 1, 0
      .endif
      INVOKE     lstrcpy, addr szBuffP, addr XNum
      INVOKE     lstrcat, addr szBuffP, addr szX
      INVOKE     lstrcat, addr szBuffP, addr YNum

      INVOKE     MoveWindow, hSizeData, pt.x, pt.y, 55, 15, 1
      INVOKE     SendMessage, hSizeData, WM_MOUSEMOVE, 0, 0

         mov     eax, FALSE
         ret
PosProc  ENDP

;=====================================================
; Update the control values if enter was not pressed
;=====================================================
UpdateCtrl  PROC

        push     hCtrl
        push     CtrlType
        push     dis.itemID
       MOVmd     hCtrl, UpCtrl
       MOVmd     CtrlType, UpType
       MOVmd     dis.itemID, UpID
      INVOKE     REditP, hREditP, WM_KEYUP, 0dh, 0
      INVOKE     SendMessage, hREditP, EM_SETMODIFY, FALSE, 0
         and     UpID, 0
         pop     dis.itemID
         pop     CtrlType
         pop     hCtrl

         ret
UpdateCtrl  ENDP

;=====================================================
; Subclass PROCEDURE for the Listbox Edit
;=====================================================
REditP  PROC  uses ebx  hwnd:DWORD, wmsg, wparam, lparam
LOCAL    Crect:RECT
LOCAL    Wrect:RECT
LOCAL    StrSave:DWORD, StrAddr, Sedx, TypeID, hEDC
LOCAL    szBuff[512]:BYTE, szBuff1[64]:BYTE, szBuff2[64]:BYTE

      .if wparam == 9
            jmp     Ret0
      .endif
      .if wmsg == WM_KEYUP && wparam == 0dh  ; Enter key
            and     UpID, 0
            and     TypeID, 0
         INVOKE     SendMessage, hWndList, LB_GETTEXT, dis.itemID, addr szBuff
         INVOKE     lstrcmpi, addr szBuff, addr szID
         .if !eax
               mov     TypeID, 1
               jmp     GetIt
         .endif
         INVOKE     lstrcmpi, addr szBuff, addr szName
         .if !eax
               mov     TypeID, 3
               jmp     GetIt
         .endif
         INVOKE     lstrcmpi, addr szBuff, addr szCaption
         .if !eax
               mov     TypeID, 6
               jmp     GetIt
         .endif
         INVOKE     lstrcmpi, addr szBuff, addr szExStyle
         .if !eax
               mov     TypeID, 7
               jmp     GetIt
         .endif
         INVOKE     lstrcmpi, addr szBuff, addr szStyle
         .if !eax
               mov     TypeID, 8
               jmp     GetIt
         .endif
         INVOKE     lstrcmpi, addr szBuff, addr szLeft
         .if !eax
               mov     TypeID, 11
               jmp     GetIt
         .endif
         INVOKE     lstrcmpi, addr szBuff, addr szTop
         .if !eax
               mov     TypeID, 12
               jmp     GetIt
         .endif
         INVOKE     lstrcmpi, addr szBuff, addr szWidth
         .if !eax
               mov     TypeID, 13
               jmp     GetIt
         .endif
         INVOKE     lstrcmpi, addr szBuff, addr szHeight
         .if !eax
               mov     TypeID, 14
               jmp     GetIt
         .endif

GetIt:
         .if !TypeID
               jmp     ThatsAll
         .endif
         INVOKE     SendMessage, hREditP, EM_SETMODIFY, FALSE, 0
         .if TypeID == 1   ; 1 = (ID)
            INVOKE     SendMessage, hREditP, WM_GETTEXT, lengthof szBuff, addr szBuff
            INVOKE     lstrcpy, addr szBuff2, addr szBuff
;---------- [Get offset in the structure array] ----------
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
               mov     StrAddr, ecx
               mov     Sedx, edx
            INVOKE     BaseAscii, [ecx+edx*4], addr szBuff1, 1, 10, 1, 1, 0
            INVOKE     AsciiBase, addr szBuff2, 10
               mov     ecx, StrAddr
               mov     edx, Sedx
.if eax
               mov     [ecx+edx*4], eax
.endif
            .if UseIDOn
                  mov     dis.itemID, 1
               .if CtrlType == 7501
                     mov     dis.itemID, 4
               .endif
;---------- [Get offset in the structure array] ----------
               INVOKE     GetOffset, 0
                  mov     StrSize, eax
                 imul     ebx, StrSize
                  add     ecx, ebx
                  mov     StrAddr, ecx
                  mov     Sedx, edx
                  jmp     DoName
            .endif
         .endif

         .if TypeID == 3   ; 3 = (Name)
            INVOKE     SendMessage, hREditP, WM_GETTEXT, lengthof szBuff, addr szBuff
              push     eax

;---------- [Get offset in the structure array] ----------
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
               mov     StrAddr, ecx
               mov     Sedx, edx
            INVOKE     lstrcpy, addr szBuff1, addr [ecx+edx*4]
               pop     eax
.if !eax
   INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr szBuff1
      jmp     ThatsAll
.endif

DoName:
            INVOKE     SendMessage, hWndCombo, CB_GETCURSEL, 0, 0
               .if eax == CB_ERR
                     and     eax, 0
               .endif
              push     eax
            INVOKE     SendMessage, hWndCombo, CB_GETITEMDATA, eax, 0
               mov     StrSave, eax
            INVOKE     SendMessage, hWndCombo, CB_FINDSTRINGEXACT, -1, addr szBuff1
               pop     ecx
            .if eax == CB_ERR
               INVOKE     SendMessage, hWndCombo, CB_GETLBTEXT, ecx, addr szBuff1
               .if eax == CB_ERR
                     jmp     ThatsAll
               .endif
            .endif
            INVOKE     SendMessage, hWndCombo, CB_DELETESTRING, eax, 0
            INVOKE     SendMessage, hWndCombo, CB_ADDSTRING, 0, addr szBuff
              push     eax
            INVOKE     SendMessage, hWndCombo, CB_SETITEMDATA, eax, StrSave  ; = CntType
               pop     eax
            INVOKE     SendMessage, hWndCombo, CB_SETCURSEL, eax, 0

               mov     ecx, StrAddr
               mov     edx, Sedx
            INVOKE     lstrcpy, addr [ecx+edx*4], addr szBuff

            .if CtrlType != 7501
                  jmp     ThatsAll
            .endif
            INVOKE     SendMessage, hWndComboD, CB_FINDSTRINGEXACT, -1, addr szBuff1
            .if eax == CB_ERR
                  jmp     ThatsAll
            .endif
            INVOKE     SendMessage, hWndComboD, CB_DELETESTRING, eax, 0
            INVOKE     SendMessage, hWndComboD, CB_ADDSTRING, 0, addr szBuff
              push     eax
            INVOKE     SendMessage, hWndComboD, CB_SETITEMDATA, eax, hForm
               pop     eax
            INVOKE     SendMessage, hWndComboD, CB_SETCURSEL, eax, 0
               jmp     Ret0

         .elseif TypeID == 6   ; 6 = Caption
            INVOKE     SendMessage, hREditP, WM_GETTEXT, lengthof szBuff, addr szBuff
            .if CtrlType == 7501
               INVOKE     SendMessage, hForm, WM_SETTEXT, 0, addr szBuff

            .elseif CtrlType == 7502 || CtrlType == 7509 || CtrlType == 7510
                 push     dis.itemID
               INVOKE     GetParent, hCtrl
               .if eax != hForm
                  .if !xGrp || !yGrp
                     INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234 ;5678
                  .else
                     mov     eax, xGrp
                     add     eax, SizeB
                     sub     Srect.left, eax
                     mov     eax, yGrp
                     add     eax, SizeT
                     sub     Srect.top, eax
                  .endif
               .endif
               INVOKE     ReloadCtrl, addr szBuff
                  pop     dis.itemID

            .elseif CtrlType > 7502 && CtrlType < 7531 ;7525
               INVOKE     SendMessage, hCtrl, WM_SETTEXT, 0, addr szBuff
            .endif
               jmp     Ret0

         .elseif TypeID == 7 || TypeID == 8  ; 7 = EXStyle - 8 = Style
            INVOKE     SendMessage, hREditP, WM_GETTEXT, lengthof szBuff1, addr szBuff1
            INVOKE     AsciiBase, addr szBuff1, 16
              push     eax
;---------- [Get offset in the structure array] ----------
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
               mov     SavOff, ecx
               pop     eax
               mov     [ecx+edx*4], eax

            .if TypeID == 7
                  mov     sEXStyle, eax
                  mov     eax, [ecx+edx*4+4]
                  mov     sStyle, eax
               INVOKE     SetWindowLong, hCtrl, GWL_EXSTYLE, sEXStyle
               INVOKE     StyleProc, hCtrl, WM_COMMAND, 5044, 0

            .elseif TypeID == 8
                  mov     sStyle, eax
                  mov     eax, [ecx+edx*4-4]
                  mov     sEXStyle, eax
               INVOKE     SetWindowLong, hCtrl, GWL_STYLE, sStyle
               INVOKE     StyleProc, hCtrl, WM_COMMAND, 5044, 0
            .endif
               jmp     Ret0
         .endif

            INVOKE     GetClientRect, hWork, addr Wrect
         .if CtrlType == 7501
;            INVOKE     GetClientRect, hWork, addr Wrect
            INVOKE     GetWindowRect, hWnd, addr Crect
            INVOKE     GetWindowRect, hForm, addr Srect
               mov     eax, Srect.left
               sub     Srect.right, eax
               mov     eax, Srect.top
               sub     Srect.bottom, eax
               mov     eax, ResB
               add     Crect.left, eax ;6
               mov     eax, ResT
               add     Crect.top, eax ;22
         .else

            .if CtrlType == 7503
                  xor     eax, eax
                  mov     edx, hCtrl
                  mov     ecx, GrpCnt ;32
               .while (ecx) ; Find handle of Groupbox parent in the array
                  .if hGrpArray[eax+4] == edx
                        mov     ecx, hGrpArray[eax]
                        mov     hGrp, ecx
                        mov     hCtrl, edx
                     .break  
                  .endif
                     add     eax, 8
                     dec     ecx
               .endw
            .endif

            INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234
         .endif

;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            mov     eax, dword ptr [ecx+edx*4]
         .if TypeID == 13
            .if eax > Wrect.right
                  mov     eax, Wrect.right
                  mov     dword ptr [ecx+edx*4], eax
            .endif
         .elseif TypeID == 14
            .if eax > Wrect.bottom
                  mov     eax, Wrect.bottom
                  mov     dword ptr [ecx+edx*4], eax
            .endif
         .endif
         .if TypeID == 11
            .if CtrlType == 7501
                  add     eax, Crect.left
            .endif
               mov     Srect.left, eax
         .elseif TypeID == 12
            .if CtrlType == 7501
                  add     eax, Crect.top
            .endif
               mov     Srect.top, eax
         .elseif TypeID == 13
               mov     Srect.right, eax
         .elseif TypeID == 14
               mov     Srect.bottom, eax
         .endif

         .if CtrlType != 7501
            INVOKE     GetParent, hCtrl
               mov     eax, hParent     ; Check hParent and hGrp in MouseMUD
;            .if eax == hGrp || CtrlType == 7503
            .if eax == hGrp && CtrlType != 7503 ;== 7503
               .if TypeID == 11
                     mov     eax, xGrp
                     add     eax, SizeB
                     sub     Srect.left, eax
               .endif
               .if TypeID == 12
                     mov     eax, yGrp
                     add     eax, SizeT
                     sub     Srect.top, eax
               .endif
            .endif
         .endif

         .if ComboOn
               sub     Srect.bottom, 6
         .endif

         .if CtrlType == 7503
            INVOKE     GetParent, hCtrl
               mov     ecx, eax
            INVOKE     MoveWindow, ecx, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
            INVOKE     MoveWindow, hCtrl, 0, 0, Srect.right, Srect.bottom, TRUE

              push     hGrpOn
              call     ChkChildren
               pop     hGrpOn

         .else
            INVOKE     GetParent, hCtrl
            .if eax != hForm
                  mov     ecx, eax
               INVOKE     GetWindowLong, ecx, GWL_STYLE
               .if (eax & WS_BORDER)
                     dec     Srect.left
                     dec     Srect.top
               .endif
            .endif
            INVOKE     MoveWindow, hCtrl, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
         .endif

         .if hGrpOn
               and     hGrpOn, 0
            INVOKE     RedrawWindow, hGrp, 0, 0,\
                       RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN
         .endif

;         .if CtrlType != 7501 && CtrlType != 7503
            mov     eax, hParent     ; Check hParent and hGrp in MouseMUD
         .if eax == hGrp && CtrlType != 7503
               mov     eax, xGrp
               add     eax, SizeB
               add     Srect.left, eax
               mov     eax, yGrp
               add     eax, SizeT
               add     Srect.top, eax
         .endif

         .if CtrlType == 7501
            INVOKE     GetClientRect, hCtrl, addr Srect
            INVOKE     MoveGrabbers, 2, 1
         .else
            .if CtrlType == 7509       ;Combobox
                  mov     eax, CBrect.bottom
;                  add     eax, 6
                  mov     ecx, Srect.top
                  mov     Srect.bottom, ecx
                  add     Srect.bottom, eax
                  sub     Srect.bottom, ecx
            .endif

            INVOKE     MoveGrabbers, 5, 1
         .endif
      .else
;            mov     eax, 1
;            ret
      .endif

ThatsAll:
      INVOKE     CallWindowProc, SubREditP, hwnd, wmsg, wparam, lparam
         ret

Ret0:
         xor     eax, eax
         ret
REditP  ENDP

;=====================================================
; Subclass PROCEDURE for the Listbox Button
;=====================================================
ControlButtP  PROC hwnd:DWORD, wmsg, wparam, lparam
LOCAL    hMemDC:DWORD

      INVOKE     CallWindowProc, SubBmpP, hwnd, wmsg, wparam, lparam
      .if wmsg == WM_PAINT
            mov     eax, hwnd
         .if eax == hButtP
            INVOKE     GetDC, hButtP               ; Get the dc of the button
               mov     hDC, eax
            INVOKE     CreateCompatibleDC, hDC     ; Create a compatible dc in memory
               mov     hMemDC, eax
            INVOKE     SelectObject, hMemDC, hBmpB ; Select the opened bitmap into the dc
            INVOKE     BitBlt, hDC, 0, 0, 14, 14, hMemDC, 0, 0, SRCCOPY ;Copy the bitmap
            INVOKE     DeleteDC, hMemDC            ; Delete the memory dc
            INVOKE     ReleaseDC, hButtP, hDC      ; Release the control dc
         .endif
            jmp     Ret0
      .endif

Ret1:
         mov     eax, TRUE
         ret

Ret0:
         mov     eax, FALSE
         ret
ControlButtP  ENDP

;=====================================================
; Style and EXStyle PROCEDURE
;=====================================================
StyleProc PROC  uses ebx esi edi  hdlg:DWORD, wmsg, wparam, lparam
LOCAL    hTemp:DWORD, hTempB, Border, cAddr, tAddr
LOCAL    szBuff[260]:BYTE, szBuffS[1024]:BYTE, szTemp[1024]:BYTE

;      .if wmsg == WM_COMMAND && wparam == 5044                  ; From REditP proc
;DSPValue hWnd, wparam, 1, 'm'
;      .endif

         cmp     wmsg, WM_INITDIALOG
         jne     NotInit
         mov     sPos, 0
         mov     ePos, 1
      INVOKE     GetDlgItem, hdlg, 5001
         mov     hEdit, eax
      INVOKE     GetDlgItem, hdlg, 5002
         mov     hTemp, eax
      INVOKE     LoadBitmap, 0, OBM_LFARROW  ;left
         mov     hTempB, eax
      INVOKE     SendMessage, hTemp, BM_SETIMAGE, IMAGE_BITMAP, hTempB
      INVOKE     GetDlgItem, hdlg, 5003
         mov     hTemp, eax
      INVOKE     LoadBitmap, 0, OBM_RGARROW  ;right
         mov     hTempB, eax
      INVOKE     SendMessage, hTemp, BM_SETIMAGE, IMAGE_BITMAP, hTempB
      INVOKE     GetDlgItem, hdlg, 5004
         mov     hTemp, eax
      INVOKE     LoadBitmap, 0, OBM_UPARROW  ;up
         mov     hTempB, eax
      INVOKE     SendMessage, hTemp, BM_SETIMAGE, IMAGE_BITMAP, hTempB
      INVOKE     GetDlgItem, hdlg, 5008
         mov     hText, eax
      INVOKE     SendMessage, hText, WM_SETFONT, hFontT, TRUE
         mov     eax, dis.itemID
      .if CtrlType == 7502 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szSS
      .elseif CtrlType == 7503 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szBSG
      .elseif CtrlType == 7504 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szBSR
      .elseif CtrlType == 7505 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szBSC
      .elseif CtrlType == 7506 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szBSB
      .elseif CtrlType == 7509 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szCBS
      .elseif CtrlType == 7512 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szLVS
      .elseif CtrlType == 7513 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szTBSTYLE
      .elseif CtrlType == 7514 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szSBS
      .elseif CtrlType == 7518 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szTBS
      .elseif CtrlType == 7520 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szTCS
      .elseif CtrlType == 7522 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szDTS
      .elseif CtrlType == 7523 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szSS
      .elseif CtrlType == 7524 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szSS
      .elseif CtrlType == 7525 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szSS
      .elseif CtrlType == 7530 && byte ptr Code[eax] == 's'
         INVOKE     SendMessage, hText, WM_SETTEXT, 0, addr szBSG
      .endif
         mov     eax, dis.itemID
      .if byte ptr Code[eax] == 'x' || byte ptr Code[eax] == 's'
         .if byte ptr Code[eax] == 'x'
               mov     sPos, 13
               mov     ePos, 14
            INVOKE     SendMessage, hdlg, WM_SETTEXT, 0, addr szExStyle
         .endif
;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
         INVOKE     BaseAscii, [ecx+edx*4], addr szBuffR, 32, 2, 1, 1, 1  ; ??????
         INVOKE     SendMessage, hEdit, WM_SETTEXT, 0, addr szBuffR
         INVOKE     SetFocus, hEdit
         INVOKE     SendMessage, hEdit, EM_SETSEL, sPos, ePos
      .endif
         mov     wparam, 5005
         jmp     Setit

NotInit:
         cmp     wmsg, WM_CLOSE
          je     CancleIt
         cmp     wmsg, WM_COMMAND      ; Is message a WM_COMMAND?
         jne     DlgDone
         mov     eax, wparam           ; Otherwise, see if it's OK or CANCEL
        cwde
         cmp     eax, 5006             ; that was pressed
          je     CancleIt              ; and if not either of these

      .if eax == 5044                  ; From REditP proc
            jmp     FREditP
      .endif

      .if eax == 5002                  ; Left
         INVOKE     SendMessage, hEdit, EM_GETSEL, addr sPos, addr ePos
         .if sPos
            dec     sPos
            dec     ePos
         .else
            mov     sPos, 31
            mov     ePos, 32
         .endif
         INVOKE     SetFocus, hEdit
         INVOKE     SendMessage, hEdit, EM_SETSEL, sPos, ePos

      .elseif eax == 5003              ; Right
         INVOKE     SendMessage, hEdit, EM_GETSEL, addr sPos, addr ePos
         .if sPos < 31
            inc     sPos
            inc     ePos
         .else
            mov     sPos, 0
            mov     ePos, 1
         .endif
         INVOKE     SetFocus, hEdit
         INVOKE     SendMessage, hEdit, EM_SETSEL, sPos, ePos

      .elseif eax == 5004              ; Change
         INVOKE     SendMessage, hEdit, EM_SETSEL, sPos, ePos
         INVOKE     SendMessage, hEdit, WM_GETTEXT, 33, addr szBuffR
            mov     eax, sPos
            xor     byte ptr szBuffR[eax], 1
         INVOKE     SetFocus, hEdit
         INVOKE     SendMessage, hEdit, WM_SETTEXT, 0, addr szBuffR
         INVOKE     SendMessage, hEdit, EM_SETSEL, sPos, ePos

;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            mov     SavOff, ecx
         INVOKE     AsciiBase, addr szBuffR, 2
            mov     [ecx+edx*4], eax
         INVOKE     BaseAscii, [ecx+edx*4], addr szBuffR, 8, 16, 1, 1, 1  ; ??????
            mov     eax, dis.itemID
         .if byte ptr Code[eax] == 'x'
               mov     eax, [ecx+edx*4]
               mov     sEXStyle, eax
            INVOKE     SetWindowLong, hCtrl, GWL_EXSTYLE, [ecx+edx*4]
            INVOKE     GetWindowLong, hCtrl, GWL_STYLE

               mov     ecx, SavOff
               add     ecx, DlgCode
            .if CtrlType == 7501
;               .if byte ptr [ecx+739] ==  '1'           ; Popup code
               .if byte ptr [ecx+31] ==  '1'            ; Popup code
                      or     eax, WS_POPUP              ; Set popup style
               .endif
            .endif
            .if CtrlType > 7506 && CtrlType < 7513
                  mov     ecx, SavOff
                  add     ecx, CtrlsCode
;               .if byte ptr [ecx+628] ==  '1'           ; VSCROLL code
               .if byte ptr [ecx+20] ==  '1'           ; VSCROLL code
                      or     eax, WS_VSCROLL            ; Set VSCROLL style
               .endif
;               .if byte ptr [ecx+629] ==  '1'           ; HSCROLL code
               .if byte ptr [ecx+21] ==  '1'           ; HSCROLL code
                      or     eax, WS_HSCROLL            ; Set HSCROLL style
               .endif
            .endif
               mov     sStyle, eax

         .else
               mov     eax, [ecx+edx*4]
               mov     sStyle, eax

mov     eax, [ecx+edx*4-4] ;!!
mov     sEXStyle, eax
   
            .if CtrlType > 7506 && CtrlType < 7513
                 push     ecx
                  mov     ecx, SavOff
                  add     ecx, CtrlsCode
;                  mov     byte ptr [ecx+628], '0'    ; Clear VSCROLL code
;                  mov     byte ptr [ecx+629], '0'    ; Clear HSCROLL code
                  mov     byte ptr [ecx+20], '0'     ; Clear VSCROLL code
                  mov     byte ptr [ecx+21], '0'     ; Clear HSCROLL code
               .if (sStyle & WS_VSCROLL)
;                     mov     byte ptr [ecx+628], '1' ; Set VSCROLL code
                     mov     byte ptr [ecx+20], '1'  ; Set VSCROLL code
               .endif
               .if (sStyle & WS_HSCROLL)
;                     mov     byte ptr [ecx+629], '1' ; Set HSCROLL code
                     mov     byte ptr [ecx+21], '1'  ; Set HSCROLL code
               .endif
                  pop     ecx
            .endif

            INVOKE     SetWindowLong, hCtrl, GWL_STYLE, [ecx+edx*4]
;            INVOKE     GetWindowLong, hCtrl, GWL_EXSTYLE
mov     eax, sEXStyle ;!!
               mov     ecx, SavOff
               add     ecx, DlgCode
            .if CtrlType == 7501
;               .if byte ptr [ecx+738] == '1'         ; Topmost code
               .if byte ptr [ecx+30] == '1'          ; Topmost code
                      or     eax, WS_EX_TOPMOST      ; Set topmost style
               .endif
            .endif
               mov     sEXStyle, eax
         .endif
         INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr szBuffR


FREditP:
            mov     eax, CtrlType
            sub     eax, 7501
          MOVmd     cAddr, ClassArray[eax*4]
          MOVmd     tAddr, TextArray[eax*4]

         .if !eax && CtrlType == 7501
               mov     sw1, 1
            INVOKE     GetWindowRect, hForm, addr Srect
               mov     eax, Srect.left
               sub     Srect.right, eax
               mov     eax, Srect.top
               sub     Srect.bottom, eax
            INVOKE     GetWindowRect, hWnd, addr rect

               mov     eax, xOff
               add     rect.left, eax
               mov     eax, yOff
               add     rect.top, eax

               mov     ecx, SavOff
               add     ecx, DlgCode
;               mov     byte ptr [ecx+738], '0'    ; Clear topmost code
               mov     byte ptr [ecx+30], '0'     ; Clear topmost code
               mov     eax, sEXStyle
            .if (eax & WS_EX_TOPMOST)
                  xor     sEXStyle, WS_EX_TOPMOST ; Remove topmost style
;                  mov     byte ptr [ecx+738], '1' ; Set topmost code
                  mov     byte ptr [ecx+30], '1'  ; Set topmost code
            .endif

               mov     ecx, SavOff
               add     ecx, DlgCode
;               mov     byte ptr [ecx+739], '0'    ; Clear popup code
               mov     byte ptr [ecx+31], '0'     ; Clear popup code
               mov     eax, sStyle
            .if (eax & WS_POPUP)
                  xor     sStyle, WS_POPUP        ; Remove popup style
;                  mov     ecx, SavOff
;                  mov     byte ptr [ecx+739], '1' ; Set popup code
                  mov     byte ptr [ecx+31], '1'  ; Set popup code
            .endif

            INVOKE     SetWindowLong, hCtrl, GWL_EXSTYLE, sEXStyle
            INVOKE     SetWindowLong, hCtrl, GWL_STYLE, sStyle

               inc     Srect.bottom
            INVOKE     MoveWindow, hCtrl, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
               dec     Srect.bottom
            INVOKE     MoveWindow, hCtrl, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
            INVOKE     GetSizes, hCtrl
            INVOKE     GetClientRect, hCtrl, addr Srect
            INVOKE     MoveGrabbers, 2, 1
               and     sw1, 0
               jmp     DlgDone
         .endif

         .if CtrlType == 7503
            INVOKE     GetParent, hCtrl
               mov     ecx, eax
            INVOKE     GetWindowRect, ecx, addr Srect
            INVOKE     GetWindowRect, hForm, addr rect
               mov     eax, Srect.left
               sub     Srect.right, eax
               mov     eax, Srect.top
               sub     Srect.bottom, eax
               mov     eax, rect.left
               add     eax, SizeB
               sub     Srect.left, eax
               mov     eax, rect.top
               add     eax, SizeT
               sub     Srect.top, eax
            INVOKE     SetWindowLong, hCtrl, GWL_EXSTYLE, sEXStyle
            INVOKE     SetWindowLong, hCtrl, GWL_STYLE, sStyle
            INVOKE     GetParent, hCtrl
               mov     ecx, eax
            INVOKE     MoveWindow, ecx, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
               inc     Srect.bottom
            INVOKE     MoveWindow, hCtrl, 0, 0, Srect.right, Srect.bottom, TRUE
               dec     Srect.bottom
            INVOKE     MoveWindow, hCtrl, 0, 0, Srect.right, Srect.bottom, TRUE
               jmp     DlgDone
         .endif

         INVOKE     GetParent, hCtrl
         .if eax != hForm
;NOTE !! Need to back off after create
            .if !xGrp || !yGrp
               INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234
            .else
               mov     eax, xGrp
               add     eax, SizeB
               sub     Srect.left, eax
               mov     eax, yGrp
               add     eax, SizeT
               sub     Srect.top, eax
            .endif
         .endif

;---------- [Get caption] ----------
           push     dis.itemID
         .if CtrlType == 7501
               mov     dis.itemID, 6
         .else
               mov     dis.itemID, 3 ;2^^^^^^^^^^
         .endif
;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
         INVOKE     lstrcpy, addr szBuff, addr [ecx+edx*4]
         INVOKE     CopyRect, addr rect, addr Srect
         INVOKE     ReloadCtrl, addr szBuff

         .if CtrlType == 7523 || CtrlType == 7524 || CtrlType == 7525
            .if CtrlType == 7523
               INVOKE     SendMessage, hCtrl, STM_SETIMAGE, IMAGE_BITMAP, hBmpR
            .elseif CtrlType == 7524
               INVOKE     SendMessage, hCtrl, STM_SETIMAGE, IMAGE_ICON, hIcoR
            .else
               INVOKE     SendMessage, hCtrl, STM_SETIMAGE, IMAGE_ICON, hIcon
            .endif
            INVOKE     MoveWindow, hCtrl, rect.left, rect.top, rect.right, rect.bottom, TRUE
            INVOKE     MoveGrabbers, 5, 1
         .endif

            pop     dis.itemID

;---------- [Update the border and handle in the structure] ----------
UpdateBH:
           push     dis.itemID
;         INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szHeight
;            mov     dis.itemID, eax
;---------- [Get offset in the structure array] ----------
;         INVOKE     GetOffset, 0
;            pop     dis.itemID
;           imul     ebx, StrSize
;            add     ecx, ebx
;            add     edx, 9

            mov     dis.itemID, 0
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
         .if CtrlType == 7501
            add     ecx, DlgBorder
         .else
            add     ecx, CtrlsBorder
         .endif

            mov     eax, dis.itemID

         .if byte ptr Code[eax] == 's'
               xor     eax, eax
               mov     ebx, sStyle
               and     ebx, 00f00000h
            .if ebx == WS_BORDER
                  mov     eax, 1
            .endif
;               mov     dword ptr [ecx+edx*4], eax
               mov     dword ptr [ecx], eax
         .endif

            jmp     DlgDone

      .elseif eax == 5005
            mov     eax, dis.itemID
         .if byte ptr Code[eax] == 'x'
               mov     sPos, 13
               mov     ePos, 14
         .else
               mov     sPos, 16
               mov     ePos, 17
         .endif
         .if CtrlType == 7501 && byte ptr Code[eax] == 's'
               mov     sPos, 0
               mov     ePos, 1
         .endif
         INVOKE     SetFocus, hEdit
         INVOKE     SendMessage, hEdit, EM_SETSEL, sPos, ePos

      .endif

Setit:
      .if wparam == 5002 || wparam == 5003 || wparam == 5005
            mov     eax, dis.itemID
         .if byte ptr Code[eax] == 'x'
            INVOKE     lstrcpy, addr szBuffS, addr szExS
               jmp     Gotit
         .endif
         .if CtrlType == 7501
            INVOKE     lstrcpy, addr szBuffS, addr szSWin
         .elseif CtrlType > 7506 && CtrlType < 7511
            INVOKE     lstrcpy, addr szBuffS, addr szSWinCtrlS
         .else
            INVOKE     lstrcpy, addr szBuffS, addr szSWinCtrl
         .endif
         .if CtrlType >= 7501 && CtrlType <= 7530 ;7524
               mov     eax, CtrlType
               sub     eax, 7501
            INVOKE     lstrcat, addr szBuffS, StyleArray[eax*4]
         .endif

Gotit:
            mov     ecx, sPos
            lea     esi, szBuffS
         .while (ecx)
            .if byte ptr[esi] == ','
                 dec     ecx
            .endif
               inc     esi
         .endw
            lea     edi, szBuff
            mov     ecx, 1
         .while (ecx)
               mov     al, byte ptr[esi]
               mov     byte ptr[edi], al
            .if al == ','
                  mov     byte ptr[edi], 0
               INVOKE     GetDlgItem, hdlg, 5007
                  mov     ecx, eax
               INVOKE     SendMessage, ecx, WM_SETTEXT, 0, addr szBuff
                  jmp     DlgDone
            .endif
            inc     esi
            inc     edi
         .endw
      .endif

         jmp     DlgDone

CancleIt:
         and     hStyle, 0
      INVOKE     DestroyWindow, hdlg
         mov     eax, TRUE             ; Return
         jmp     DlgRet                ; with TRUE

DlgDone:
.if wparam == 5044
      ret
.endif
         mov     eax, FALSE            ; Return with FALSE

DlgRet:
         ret                           ; Return
StyleProc ENDP

;=====================================================
; Reload control PROCEDURE
;=====================================================
ReloadCtrl PROC szText:DWORD
LOCAL    cAddr:DWORD, tAddr
LOCAL    szBuff[512]:BYTE

;      INVOKE     GetWindowLong, hCtrl, GWL_EXSTYLE
;         mov     sEXStyle, eax

      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szExStyle
         mov     dis.itemID, eax
;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
         mov     eax, dword ptr [ecx+edx*4] ;!
         mov     sEXStyle, eax

      INVOKE     GetWindowLong, hCtrl, GWL_STYLE
         mov     sStyle, eax
         mov     eax, CtrlType
         sub     eax, 7501
       MOVmd     cAddr, ClassArray[eax*4]
       MOVmd     tAddr, TextArray[eax*4]

      INVOKE     GetParent, hCtrl
        push     eax
      INVOKE     DestroyWindow, hCtrl
         pop     ecx

      .if ecx == hGrp
            mov     eax, xGrp
            sub     Srect.left, eax
            mov     eax, yGrp
            sub     Srect.top, eax
      .endif

        push     ecx
      .if szText
         INVOKE     lstrcpy, addr szBuff, szText
      .else
         INVOKE     lstrcpy, addr szBuff, tAddr
      .endif



         pop     ecx
      INVOKE     CreateWindowEx, sEXStyle, cAddr, addr szBuff, sStyle,\
                 Srect.left, Srect.top, Srect.right, Srect.bottom, ecx, CtrlType, hInst, 0
         mov     ebx, eax

         xor     eax, eax
         mov     ecx, ArrayCnt ;2048 ;1024 ;512 ;64
inc     ecx
      .while (ecx)          ; Find handle of active control in the array
            mov     edx, hCtrl
         .if hArray[eax+4] == edx
               mov     hArray[eax+4], ebx
               mov     hCtrl, ebx
            .break  
         .endif
            add     eax, 8
            dec     ecx
      .endw
         and     sw1, 0
      .if CtrlType != 7527
         INVOKE     SendMessage, hCtrl, WM_SETFONT, hFontS, TRUE
      .else
;         INVOKE     SendMessage, hCtrl, WM_SETFONT, hFontIP, TRUE
      .endif

      .if CtrlType == 7510  ; Listbox
         INVOKE     SendMessage, hCtrl, LB_ADDSTRING, 0, addr szBuff
      .endif

      .if CtrlType == 7519  ; UpDown
         INVOKE     MoveWindow, hCtrl, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
      .endif

      .if CtrlType == 7520  ; Tab
           call     DoTabs
      .endif

      INVOKE     GetParent, hCtrl
      .if eax
         .if eax != hForm && CtrlType != 7503
               mov     ecx, xGrp
               add     ecx, SizeB
               add     Srect.left, ecx
               mov     ecx, yGrp
               add     ecx, SizeT
               add     Srect.top, ecx
         .endif

         INVOKE     CreateControls, eax, 1

      .endif
         ret                           ; Return
ReloadCtrl ENDP

;=====================================================
; Options PROCEDURE
;=====================================================
OptionsProc PROC  uses ebx  hdlg:DWORD, wmsg, wparam, lparam
LOCAL    hChild:DWORD, Cnt1, Len1, Secx, sWth, sHgt
LOCAL    sL:DWORD, sU, sR, sD, vS, hS

         cmp     wmsg, WM_INITDIALOG
         jne     NotInit

      .if lparam != 42
          MOVmd     hOpt, hdlg
      .else
          MOVmd     hSizePos, hdlg
         .if vSpace
            INVOKE     SetDlgItemInt, hdlg, 3018, vSpace, 0
         .else
            INVOKE     SetDlgItemInt, hdlg, 3018, 2, 0
         .endif
         .if hSpace
            INVOKE     SetDlgItemInt, hdlg, 3019, hSpace, 0
         .else
            INVOKE     SetDlgItemInt, hdlg, 3019, 2, 0
         .endif
      .endif

      INVOKE     GetDlgItem, hdlg, 601
      .if GridOn
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
      .else
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_UNCHECKED, 0
      .endif
      INVOKE     GetDlgItem, hdlg, 607
      .if SnapOn
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
      .else
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_UNCHECKED, 0
      .endif
      INVOKE     GetDlgItem, hdlg, 608
      .if ConvertOn
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
      .else
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_UNCHECKED, 0
      .endif
      INVOKE     GetDlgItem, hdlg, 602
      .if Grid == 2
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
      .endif
      INVOKE     GetDlgItem, hdlg, 603
      .if Grid == 3
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
      .endif
      INVOKE     GetDlgItem, hdlg, 604
      .if Grid == 4
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
      .endif
      INVOKE     GetDlgItem, hdlg, 606
      .if Grid == 6
         INVOKE     SendMessage, eax, BM_SETCHECK, BST_CHECKED, 0
      .endif

      INVOKE     GetDlgItem, hdlg, 605
      .if !ArrayCnt
         INVOKE     EnableWindow, eax, 0
      .else
         INVOKE     EnableWindow, eax, 1
      .endif

      INVOKE     SetFocus, hWndList

         jmp     DlgDone

NotInit:
         cmp     wmsg, WM_CLOSE
          je     CancleIt
         cmp     wmsg, WM_COMMAND      ; Is message a WM_COMMAND?
         jne     DlgDone
         mov     eax, wparam           ; Otherwise, see if it's OK or CANCEL
        cwde

      .if eax > 600 && eax < 610
           push     eax
         .if eax == 601
               and     GridOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, 601
            .if eax
                  mov     GridOn, 1
            .else
               INVOKE     GetDlgItem, hdlg, 601
               INVOKE     SendMessage, eax, BM_SETCHECK, BST_UNCHECKED, 0
                  mov     hPat, 0
            .endif
         .endif
            pop     eax

         .if eax == 605  ; Clear memory
            INVOKE     SendMessage, hDlg3, WM_COMMAND, 605, 0
               jmp     CancleIt

         .elseif eax == 607
               and     SnapOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, 607
            .if eax
                  mov     SnapOn, 1
            .endif

         .elseif eax == 608
               and     ConvertOn, 0
            INVOKE     IsDlgButtonChecked, hdlg, 608
            .if eax
                  mov     ConvertOn, 1
            .endif

         .elseif eax == 609
            INVOKE     CreateDialogParam, hInst, 5100, hREdit, offset SetDefaults, 0
            INVOKE     SendMessage, hOpt, WM_CLOSE, 0, 0
               jmp     DlgDone

         .endif

         INVOKE     IsDlgButtonChecked, hdlg, 602
         .if eax
             MOVmd     hPat, hPat2
               mov     Grid, 2
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 603
         .if eax
             MOVmd     hPat, hPat3
               mov     Grid, 3
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 604
         .if eax
             MOVmd     hPat, hPat4
               mov     Grid, 4
         .endif
         INVOKE     IsDlgButtonChecked, hdlg, 606
         .if eax
             MOVmd     hPat, hPat6
               mov     Grid, 6
         .endif
         INVOKE     DialogDlg, hDlg2, WM_COMMAND, 620, 0
         INVOKE     SetFocus, hForm

;---------- [Position or size the multiple selections] ----------
      .elseif eax > 2000 && eax < 2017
         INVOKE     GetDlgItemInt, hdlg, 3012, 0, 0
            mov     sL, eax
         INVOKE     GetDlgItemInt, hdlg, 3013, 0, 0
            mov     sU, eax
         INVOKE     GetDlgItemInt, hdlg, 3014, 0, 0
            mov     sR, eax
         INVOKE     GetDlgItemInt, hdlg, 3015, 0, 0
            mov     sD, eax
         INVOKE     GetDlgItemInt, hdlg, 3016, 0, 0
            mov     sWth, eax
         INVOKE     GetDlgItemInt, hdlg, 3017, 0, 0
            mov     sHgt, eax
         INVOKE     GetDlgItemInt, hdlg, 3018, 0, 0
            mov     vS, eax
            mov     vSpace, eax
         INVOKE     GetDlgItemInt, hdlg, 3019, 0, 0
            mov     hS, eax
            mov     hSpace, eax
         INVOKE     ASMC, wparam, lparam, sL, sU, sR, sD, sWth, sHgt, vS, hS
         INVOKE     SetFocus, hForm
            jmp     DlgDone
      .endif

         jmp     DlgDone

CancleIt:
            mov     eax, hdlg
      .if eax != hOpt
         INVOKE     GetDlgItemInt, hdlg, 3018, 0, 0
            mov     vSpace, eax
         INVOKE     GetDlgItemInt, hdlg, 3019, 0, 0
            mov     hSpace, eax
      .endif
         and     hOpt, 0
         and     hSizePos, 0
      INVOKE     DestroyWindow, hdlg
         mov     eax, TRUE             ; Return
         jmp     DlgRet                ; with TRUE

DlgDone:
         mov     eax, FALSE            ; Return with FALSE

DlgRet:
         ret                           ; Return
OptionsProc ENDP

;=====================================================
; SizeDataProc Size & pos box data PROCEDURE
;=====================================================
SizeDataProc PROC  hdlg:DWORD, wmsg, wparam, lparam
LOCAL    lb:LOGBRUSH
LOCAL    Drect:RECT
LOCAL    hSDC:DWORD
LOCAL    Clear[20]:BYTE

         cmp     wmsg, WM_INITDIALOG
         jne     NotInit
        push     hdlg
         pop     hSizeData
         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?
         jne     DlgDone
         mov     eax, wparam           ; Otherwise, see if it's OK or CANCEL
        cwde
         cmp     eax, IDCANCEL         ; that was pressed
          je     CancleIt              ; and if not either of these
         jmp     DlgDone

ColorDlg:
      .if hBRS
         INVOKE     DeleteObject, hBRS
      .endif
      INVOKE     GetSysColor, COLOR_INFOBK
      INVOKE     CreateSolidBrush, eax
         mov     hBRS, eax
         ret
 
OutPut:
      INVOKE     GetClientRect, hdlg, addr Drect
      INVOKE     GetDC, hdlg
         mov     hSDC, eax
      INVOKE     SelectObject, hSDC, hFontS
      INVOKE     SelectObject, hSDC, hBRS
      INVOKE     FillRect, hSDC, addr Drect, hBRS ; Background color
         mov     Drect.left, 2
         mov     Drect.top, 1
         mov     Drect.bottom, 16
      INVOKE     FillBuffer, addr Clear, sizeof Clear, ' ', 1
      INVOKE     GetSysColor, COLOR_INFOBK
      INVOKE     SetBkColor, hSDC, eax
      INVOKE     SetTextColor, hSDC, 0
      INVOKE     DrawText, hSDC, addr Clear, 20, addr Drect, DT_LEFT or DT_SINGLELINE
      INVOKE     DrawText, hSDC, addr szBuffP, -1, addr Drect, DT_LEFT or DT_SINGLELINE
      INVOKE     ReleaseDC, hdlg, hSDC
         jmp     DlgDone

CancleIt:
      .if hBRS
         INVOKE     DeleteObject, hBRS
           and      hBRS, 0
      .endif
         and     hSizeData, 0
      INVOKE     DestroyWindow, hdlg
         mov     eax, TRUE             ; Return
         jmp     DlgRet                ; with TRUE

DlgDone:
         mov     eax, FALSE            ; Return with FALSE

DlgRet:
         ret                           ; Return
SizeDataProc ENDP

;=====================================================
; SubClass the ListBox control PROCEDURE
;=====================================================
ListBoxProc PROC  uses ebx  hwnd:DWORD, wmsg, wparam, lparam
LOCAL    cf:CHOOSEFONT
LOCAL    Vrect:RECT
LOCAL    Val:DWORD, OldCnt, NumChars
LOCAL    szBuff[512]:BYTE

      .if wmsg == WM_LBUTTONDOWN
            mov     ecx, UpID
         .if UpID ;&& ecx != dis.itemID     ; Enter key was not pressed after change
              call     UpdateCtrl
         .endif
            jmp     ThatsAll
      .endif

      INVOKE     SendMessage, hREditP, EM_GETMODIFY, 0, 0
      .if eax
          MOVmd     UpID, dis.itemID
          MOVmd     UpCtrl, hCtrl
          MOVmd     UpType, CtrlType
         INVOKE     SendMessage, hREditP, WM_GETTEXT, lengthof szBuff, addr szBuff
            mov     NumChars, eax

CopyFont:
;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            mov     eax, 0
         .if CtrlType > 7501 && CtrlType < 7531 ;7525
               mov     eax, 3456
         .endif
         .if CtrlType == 7501 && dis.itemID > 1 && CtrlType == 7501 && dis.itemID < 7 ||\
             eax == 3456 && dis.itemID > 0 && eax == 3456 && dis.itemID < 4 ;3^^^^^^^^^

            .if dis.itemID == 1 || dis.itemID == 4  ; = lpName
                   jmp     ThatsAll
            .endif
            .if CtrlType == 7501 && dis.itemID == 6 || eax == 3456 && dis.itemID == 3 ; = lpCaption
               .if NumChars > 510 ;255
                    push     ecx
                    push     edx
                  INVOKE     lstrcpyn, addr szBuff, addr szBuff, 511 ;256
                  INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr szBuff
                  INVOKE     SendMessage, hREditP, EM_SETSEL, 510, 510
                     pop     edx
                     pop     ecx
               .endif
            .endif
            .if CtrlType == 7501 && dis.itemID == 5 || CtrlType != 7529 && dis.itemID == 2
               INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr [ecx+edx*4]
               INVOKE     SendMessage, hREditP, EM_SETSEL, 510, 510
            .else
               INVOKE     lstrcpy, addr [ecx+edx*4], addr szBuff
            .endif

         .else
            .if dis.itemID == 0 && UseIDOn
                   jmp     ThatsAll
            .endif

            INVOKE     AsciiBase, addr szBuff, 10

.if dis.itemID == 0 && !eax
      jmp     ThatsAll
.endif

            .if CtrlType != 7501 && dis.itemID == 6 ;5^^^^^^   ; Tab index
               mov     IndexCnt, eax
               mov     eax, [ecx+edx*4]
               mov     OldCnt, eax
               .if eax >= IndexCnt     ; eax = 3 & IndexCnt = 1
                     mov     Val, 0
               .else
                     mov     Val, 1
               .endif
              push     ecx
              push     edx
               and     Len, 0
             MOVmd     Cnt, ArrayCnt
inc     Cnt

GetMore:
            .while (Cnt)                         ; Find handle of active control in the array
                  mov     eax, Len
               .if hArray+[eax*8+4]              ; Check for valid handle
                   MOVmd     hCtrl, hArray+[eax*8+4]
                     mov     ebx, hArray+[eax*8] ; Extract array count
                     mov     eax, ebx
                     and     eax, 0ffffh
                     mov     CtrlType, eax
                     shr     ebx, 16
                  .if eax == 7501
                        inc     Len
                        dec     Cnt
                        jmp     GetMore
                  .endif

;---------- [Get offset in the structure array] ----------
                    push     ebx
                     mov     dis.itemID, 6 ;5^^^^^^^^^^^^^^^
                  INVOKE     GetOffset, 1
                     pop     ebx
                     mov     StrSize, eax
                    imul     ebx, StrSize
                     add     ecx, ebx
                     mov     ebx, IndexCnt
                     mov     eax, dword ptr[ecx+edx*4]
                  .if ebx <= dword ptr[ecx+edx*4] && Val == 0
                     .if Cnt > 1
.if eax < OldCnt
                           inc     eax
.endif
                     .endif
                  .elseif ebx >= dword ptr[ecx+edx*4] && Val == 1
                     .if eax > 1
                           dec     eax
                     .endif
                  .endif
                     mov     dword ptr[ecx+edx*4], eax
               .endif
                  inc     Len
                  dec     Cnt
            .endw

               pop     edx
               pop     ecx
               mov     eax, IndexCnt
            .endif
               mov     [ecx+edx*4], eax

            .if CtrlType == 7501 && dis.itemID == 1
                  mov     edx, CtrlCnt
                  mov     StartID+[edx*4], eax
                  dec     eax
                  mov     IDCnt, eax
            .endif
         .endif

         INVOKE     SendMessage, hREditP, EM_SETMODIFY, FALSE, 0
      .endif

      .if wmsg == WM_COMMAND
            mov     eax, wparam
           cwde

         .if eax == 82
               mov     eax, dis.itemID
            .if byte ptr Code[eax] == 'f'
                  mov     sw1, 1
               INVOKE     RtlZeroMemory, addr cf, sizeof cf
               INVOKE     lstrcpy, addr lf.lfFaceName, addr FontMS
                  mov     lf.lfHeight, -10
                  mov     cf.lStructSize, sizeof cf
                  mov     eax, hWnd
                  mov     cf.hwndOwner, eax
                  mov     eax, hInst
                  mov     cf.hInstance, eax
                  lea     eax, lf
                  mov     cf.lpLogFont, eax
                  mov     cf.iPointSize, 80
                  mov     cf.Flags, CF_SCREENFONTS or CF_INITTOLOGFONTSTRUCT or\
                          CF_FORCEFONTEXIST ;or CF_EFFECTS
               INVOKE     ChooseFont, addr cf   ; Invoke common ChooseFont dialog
               .if !eax
                     and     sw1, 0
                     jmp     Ret0
               .endif
                  mov     eax, cf.iPointSize
                  xor     edx, edx
                  mov     ecx, 10
                  div     ecx
                  mov     ecx, eax
               INVOKE     BaseAscii, ecx, addr szBuff, 1, 10, 1, 1, 0
               INVOKE     lstrcat, addr szBuff, addr szComma
               INVOKE     lstrcat, addr szBuff, addr szSpace
               INVOKE     lstrcat, addr szBuff, addr szQuote
               INVOKE     lstrcat, addr szBuff, addr lf.lfFaceName
               INVOKE     lstrcat, addr szBuff, addr szQuote
               INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr szBuff
                  and     sw1, 0
                  mov     wparam, 0
                  jmp     CopyFont

            .elseif byte ptr Code[eax] == 'x' || byte ptr Code[eax] == 's'
               INVOKE     IsWindowVisible, hStyle
               .if eax
                  INVOKE     StyleProc, hStyle, WM_COMMAND, 5006, 0
                     and     hStyle, 0
                  INVOKE     SendMessage, hWndList, LB_SETCURSEL, dis.itemID, 0
                     jmp     Ret0
               .endif
                  INVOKE     CreateDialogParam, hInst, 5000, hWnd, offset StyleProc, 0
                     mov     hStyle, eax
                  INVOKE     GetWindowRect, hWndList, addr rect ; Rectangle of LisBox
;                     dec     rect.left
                     sub     rect.left, 15
                     mov     ecx, dis.rcItem.top
                     add     ecx, 15
                     add     rect.top, ecx
                  INVOKE     MoveWindow, hStyle, rect.left, rect.top, 213, 161, TRUE
                     jmp     Ret0
            .endif

            INVOKE     IsWindowVisible, hListP
            .if eax
               INVOKE     ShowWindow, hListP, SW_HIDE
               INVOKE     SendMessage, hWndList, LB_SETCURSEL, dis.itemID, 0
                  jmp     Ret0
            .endif

            INVOKE     GetWindowRect, hWndList, addr rect ; Rectangle of LisBox
               add     rect.left, 70
               mov     ecx, dis.rcItem.top
               add     ecx, 15
               add     rect.top, ecx
               mov     edx, dis.rcItem.right
               sub     edx, 71
               inc     edx
              push     edx
            INVOKE     SendMessage, hListP, LB_RESETCONTENT, 0, 0

               mov     eax, dis.itemID
            .if byte ptr Code[eax] == 'a'
               INVOKE     SendMessage, hListP, LB_ADDSTRING, 0, addr szFalse
               INVOKE     SendMessage, hListP, LB_ADDSTRING, 0, addr szTrue
;            .elseif byte ptr Code[eax] == 'n'
;               INVOKE     SendMessage, hListP, LB_ADDSTRING, 0, addr szH
;               INVOKE     SendMessage, hListP, LB_ADDSTRING, 0, addr szA
;               INVOKE     SendMessage, hListP, LB_ADDSTRING, 0, addr szN
;               INVOKE     SendMessage, hListP, LB_ADDSTRING, 0, addr szD
            .endif

            INVOKE     SendMessage, hListP, LB_GETCOUNT, 0, 0
              imul     eax, 15
               add     eax, 2
               pop     edx
            INVOKE     MoveWindow, hListP, rect.left, rect.top, edx, eax, TRUE
            INVOKE     ShowWindow, hListP, SW_SHOWDEFAULT
;---------- [Get offset in the structure array] ----------
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
               mov     eax, [ecx+edx*4]
              push     eax
            INVOKE     SendMessage, hListP, LB_SETCURSEL, 0, 0
               pop     eax
            INVOKE     SendMessage, hListP, LB_SETCURSEL, eax, 0
            INVOKE     SetFocus, hWndList
               jmp     Ret0
         .endif
      .endif
         jmp     ThatsAll

ThatsAll:
      INVOKE     CallWindowProc, lpListBox, hwnd, wmsg, wparam, lparam
         ret

Ret0:
         mov     eax, 0
         ret
ListBoxProc ENDP

;=====================================================
; SubClass the ListPop control PROCEDURE
;=====================================================
ListPopProc PROC hwnd:DWORD, wmsg, wparam, lparam
LOCAL    szBuff[512]:BYTE

      .if wmsg == WM_LBUTTONUP
         INVOKE     SendMessage, hListP, LB_GETCURSEL, 0, 0
            mov     edx, eax
            mov     ecx, lparam
         .if eax == LB_ERR
               jmp     ThatsAll
         .endif
           push     edx
         INVOKE     SendMessage, hListP, LB_GETTEXT, edx, addr szBuff
         INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr szBuff
;---------- [Get offset in the structure array] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            pop     eax
            mov     [ecx+edx*4], eax
         INVOKE     ShowWindow, hListP, SW_HIDE
INVOKE     SendMessage, hWndList, LB_SETCURSEL, dis.itemID, 0
      .endif

ThatsAll:
      INVOKE     CallWindowProc, lpListPop, hwnd, wmsg, wparam, lparam
         ret

Ret0:
         mov     eax, 0
         ret
ListPopProc ENDP

;=====================================================
; Convert the code to text
;=====================================================
GetCode PROC

;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
         mov     eax, dis.itemID
      .if byte ptr Code[eax] == 't' || byte ptr Code[eax] == 'f'
         INVOKE     lstrcpy, addr szBuffR, addr [ecx+edx*4]
         INVOKE     lstrlen, addr szBuffR

      .else

         .if byte ptr Code[eax] == 'a'
            .if byte ptr [ecx+edx*4] == 0
               INVOKE     lstrcpy, addr szBuffR, addr szFalse
            .else
               INVOKE     lstrcpy, addr szBuffR, addr szTrue
            .endif
            INVOKE     lstrlen, addr szBuffR

;         .elseif byte ptr Code[eax] == 'n'
;            .if byte ptr [ecx+edx*4] == 0
;               INVOKE     lstrcpy, addr szBuffR, addr szH
;            .elseif byte ptr [ecx+edx*4] == 1
;               INVOKE     lstrcpy, addr szBuffR, addr szA
;            .elseif byte ptr [ecx+edx*4] == 2
;               INVOKE     lstrcpy, addr szBuffR, addr szN
;            .elseif byte ptr [ecx+edx*4] == 3
;               INVOKE     lstrcpy, addr szBuffR, addr szD
;            .else
;               INVOKE     lstrcpy, addr szBuffR, addr szH
;            .endif
;            INVOKE     lstrlen, addr szBuffR

         .else
            .if CtrlType == 7501 && dis.itemID > 6 && CtrlType == 7501 && dis.itemID < 9 ||\
                CtrlType != 7501 && dis.itemID > 3 && CtrlType != 7501 && dis.itemID < 6 ;^^^^^^^^^^
               INVOKE     BaseAscii, [ecx+edx*4], addr szBuffR, 8, 16, 1, 1, 1  ; ??????
            .else
               INVOKE     BaseAscii, [ecx+edx*4], addr szBuffR, 1, 10, 1, 1, 0
            .endif
            INVOKE     lstrlen, addr szBuffR
         .endif
      .endif
         ret
GetCode ENDP

;=====================================================
; Get the offset into the array
;=====================================================
GetOffset PROC swOn:DWORD

         and     ebx, 0
      .if swOn
            jmp     NoSearch
      .endif

;---------- [Get structure array count and CtrlType] ----------
         xor     eax, eax
         mov     edx, hCtrl
         mov     ecx, ArrayCnt ;2048 ;1024 ;512 ;64
inc     ecx
      .while (ecx)                         ; Find handle of active control in the array
         .if hArray+[eax*8+4] == edx       ; Check for control handle
               mov     ebx, hArray+[eax*8] ; Extract array count
               shr     ebx, 16
               mov     eax, hArray+[eax*8] ; Extract CtrlType
               and     eax, 0ffffh
               mov     CtrlType, eax
            .break
         .endif
            inc     eax
            dec     ecx
      .endw

NoSearch:
        push     ebx

;---------- [Get structure size and structure code] ----------
      .if CtrlType != 7501
         INVOKE     lstrcpyn, addr Code, addr Ctrls.Code, 33
            mov     eax, sizeof Ctrls
      .endif
      .if CtrlType == 7501
         INVOKE     lstrcpyn, addr Code, addr Dlg.Code, 33
            mov     eax, sizeof Dlg
      .endif

;---------- [Get array memory address for structure type] ---------
         mov     edx, CtrlType
         sub     edx, 7501
         mov     ecx, hDlgMem[edx*4]

;---------- [Get offest into the structure] ----------
         mov     edx, dis.itemID
       .if CtrlType == 7501 && dis.itemID > 2
            add     edx, 15
      .endif
      .if CtrlType == 7501 && dis.itemID > 3
            add     edx, 7
      .endif
      .if CtrlType == 7501 && dis.itemID > 4
            add     edx, 7
      .endif
      .if CtrlType == 7501 && dis.itemID > 5
            add     edx, 7
      .endif
      .if CtrlType == 7501 && dis.itemID > 6
;            add     edx, 7
            add     edx, 127 ;63
      .endif
      .if CtrlType > 7501 && CtrlType < 7531 && dis.itemID > 1
            add     edx, 7
      .endif
      .if CtrlType > 7501 && CtrlType < 7531 && dis.itemID > 2 ;^^^^^^^^
            add     edx, 7
      .endif
      .if CtrlType > 7501 && CtrlType < 7531 && dis.itemID > 3 ;^^^^^^^^
;            add     edx, 7
            add     edx, 127 ;63
      .endif

         pop     ebx
         ret
GetOffset ENDP

;======================================================
; Check for under laying Groupbox controls
;======================================================
ChkUnder PROC uses ebx esi
LOCAL    Trect:RECT
LOCAL    hChild:DWORD, Cnt2, Len2

;---------- [Build the output] ----------
         and     sw2, 0
         and     Len2, 0
       MOVmd     Cnt2, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt2

GetMore:
      .while (Cnt2)                          ; Find valid control handles in the array
            mov     eax, Len2
         .if hArray+[eax*8+4]                ; Check for valid handle
               mov     ebx, hArray+[eax*8]   ; Extract array count
               mov     edx, hArray+[eax*8+4] ; Extract handle
               mov     hChild, edx
               mov     eax, ebx
               and     eax, 0ffffh
               mov     CtrlType, eax
               shr     ebx, 16
               inc     Len2
               dec     Cnt2
            .if eax == 7501 || eax == 7503
                  jmp     GetMore
            .endif
            .break
         .endif
            inc     Len2
            dec     Cnt2
      .endw

;---------- [Run out] ----------
      .if !Cnt2
            jmp     Ret0
      .endif

;---------- [Get offset in the structure array] ----------
        push     ebx
      INVOKE     GetOffset, 1
         pop     ebx
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
         mov     sPos, ecx
         mov     esi, ecx
         add     esi, CtrlsLeft
         add     ecx, StrSize
         mov     eax, dword ptr [ecx-4]       ; Matching parent handle

      .if eax == hForm
         .if byte ptr [ecx-16] == '1'
               jmp     GetMore
         .endif
;            mov     eax, dword ptr [ecx-60]   ; = Left
;            mov     ebx, dword ptr [ecx-56]   ; = Top
            mov     eax, dword ptr [esi]      ; = Left
            mov     ebx, dword ptr [esi+4]    ; = Top

         .if eax > Srect.left && eax < Srect.right &&\
             ebx > Srect.top && ebx < Srect.bottom

.if sw44
   .if ConvertOn
;         add     dword ptr [ecx-56], 1
         add     dword ptr [esi+4], 1
   .else
;         add     dword ptr [ecx-56], 2
         add     dword ptr [esi+4], 2
   .endif
;;      add     dword ptr [ecx-60], 1
;;      add     dword ptr [esi], 1
.endif

               mov     eax, Srect.left
;               sub     dword ptr [ecx-60], eax
               sub     dword ptr [esi], eax
               mov     eax, Srect.top
;               sub     dword ptr [ecx-56], eax
               sub     dword ptr [esi+4], eax
               mov     byte ptr [ecx-16], '1' ; Set done flag

;             MOVmd     rect.left, dword ptr [ecx-60]
;             MOVmd     rect.top, dword ptr [ecx-56]
;             MOVmd     rect.right, dword ptr [ecx-52]
;             MOVmd     rect.bottom, dword ptr [ecx-48]

             MOVmd     rect.left, dword ptr [esi]
             MOVmd     rect.top, dword ptr [esi+4]
             MOVmd     rect.right, dword ptr [esi+8]
             MOVmd     rect.bottom, dword ptr [esi+12]

            INVOKE     MoveWindow, hChild, rect.left, rect.top, rect.right, rect.bottom, TRUE
            INVOKE     SetParent, hChild, hCtrl

            .if sw44      ; sw44 = From Extract
               INVOKE     CopyRect, addr Trect, addr Srect
               INVOKE     CopyRect, addr Srect, addr rect
                 push     hCtrl
                MOVmd     hCtrl, hChild
               INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234
                  mov     eax, xGrp
                  add     eax, SizeB
                  add     Srect.left, eax
                  mov     eax, yGrp
                  add     eax, SizeT
                  add     Srect.top, eax
               INVOKE     MoveGrabbers, 5, 4
                  pop     hCtrl
               INVOKE     CopyRect, addr Srect, addr Trect
            .endif

         .endif
      .endif
         jmp     GetMore

Ret0:
         ret
ChkUnder ENDP

;======================================================
; Converts a 32 bit num value to a Dec, Hex, Oct or Bin ascii string.
;=====================================================
;INVOKE     BaseAscii, Num, addr szBuff, 1, 10, 1, 0
BaseAscii PROC InPut:DWORD, OutPut, Len4, Base, Fill, Term, NoSign
LOCAL    LBuff[32]: BYTE

      pushad
         xor     esi, esi
         mov     eax, InPut                ; Input
         mov     ebx, OutPut
         mov     byte ptr [ebx], '0'
      .if sdword ptr eax < 0 && !NoSign    ; Check for negative number
            neg     eax                    ; and invert the value
            mov     byte ptr [ebx], 2dh
            inc     ebx
      .endif
      .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
      .endw
         xor     edi, edi
         mov     ecx, esi
      .if Len4 > ecx && Fill == 1           ; Zero fill
            xor     eax, eax
         .while (eax < Len4)
               mov     byte ptr [ebx+eax], '0'
               inc     eax
         .endw
            sub     Len4, ecx
            add     edi, Len4
      .endif
      .while (ecx)
            mov     al, byte ptr LBuff[esi-1]
            mov     byte ptr [ebx+edi], al
            inc     edi
            dec     esi
            dec     ecx
      .endw
      .if Term
            mov     byte ptr [ebx+edi], 0h
       .endif
       popad
          ret
BaseAscii ENDP

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

;=====================================================
; Build the resource file
;=====================================================
BuildRes PROC uses ebx esi edi
LOCAL    Crect:RECT
LOCAL    Erect:RECT
LOCAL    tm:TEXTMETRIC
LOCAL    pt:POINT
LOCAL    Var1:DWORD, Var2, Var3, LoopIt, cAddr, LenD, CntD, Len4, Cnt4, Work
LOCAL    DefOn:DWORD, hTemp, Index
LOCAL    szBuff[1024*2]:BYTE, szBuff1[4096*4]:BYTE, szWork[64]:BYTE, szWork1[64]:BYTE

comment^
      INVOKE     GetDC, hCtrl
         mov     hDC, eax
      INVOKE     SelectObject, hDC, hFontDlg
      INVOKE     GetTextMetrics, hDC, addr tm
      INVOKE     GetTextExtentPoint32, hDC, addr szTest, 62, addr pt
      INVOKE     ReleaseDC, hCtrl, hDC
         xor     edx, edx
         mov     eax, pt.x
         mov     ecx, 31
         div     ecx
         add     eax, 1
         xor     edx, edx
         mov     ecx, 2
         div     ecx
         mov     ConvX, eax
       MOVmd     ConvY, tm.tmHeight
^
;DSPValue hWnd, ConvX, 1, 'm'
;DSPValue hWnd, ConvY, 1, 'm'

         mov     DefOn, 0 ;1
         and     Output, 0

      INVOKE     lstrcpy, DefinesDlg, addr szNULL ;szCRLF
      INVOKE     lstrcpy, Defines, addr szNULL
      INVOKE     lstrcpy, Equates, addr szEquHeader
      INVOKE     lstrcat, Equates, addr szCRLF
      INVOKE     lstrcpy, Accelerator, addr szNULL
      INVOKE     GetDlgItemInt, hDlg0, 511, 0, 0
         mov     RStartID, eax
         mov     ecx, hREditTab
      INVOKE     GetDefines, ecx, hDlg0, RStartID
      INVOKE     GetDlgItemInt, hDlg1, 511, 0, 0
         mov     MStartID, eax
         mov     ecx, hREditTab+4
      INVOKE     GetDefines, ecx, hDlg1, MStartID
      .if Output > 0 && Output < 4
;         INVOKE     lstrcat, Equates, addr szCRLF
      .endif
      .if Output
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szResource
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szNULL
      .else
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szSpace
      .endif
      INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
      INVOKE     SendMessage, hREdit, EM_GETSEL, addr PosX, addr PosX

; or WS_VISIBLE
;---------- [Sort the Tab Index's] ----------
      INVOKE     CreateWindowEx, 0, addr ListboxClass, 0,\
                 WS_CHILD or WS_BORDER or WS_VSCROLL or\
                 LBS_HASSTRINGS or LBS_SORT or LBS_NOTIFY or\
                 LBS_NOINTEGRALHEIGHT,\
                 100, 50, 250, 200, hREdit, 44, hInst, 0
         mov     hTemp, eax

         mov     byte ptr szBuff, 0
         and     Cnt4, 0
         and     Index, 0
       MOVmd     Cnt, ArrayCnt
         inc     Cnt

      .while (Cnt)                            ; Find valid control handles in the array
            mov     eax, Index
         .if hArray+[eax*8+4]                 ; Check for valid handle
               mov     ebx, hArray+[eax*8]    ; Extract array count
               mov     edx, hArray+[eax*8+4]  ; Extract handle
               mov     eax, ebx
               and     eax, 0ffffh
               mov     CtrlType, eax
               shr     ebx, 16
            .if CtrlType == 7501
                  mov     hCtrl, edx
                  inc     Cnt4
            .endif
              push     ebx

            INVOKE     BaseAscii, Cnt4, addr szWork, 4, 10, 1, 1, 1
            INVOKE     lstrcat, addr szBuff, addr szWork

            INVOKE     GetOffset, 1
               pop     ebx
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
               mov     sPos, ecx
               add     ecx, StrSize
               mov     edx, dword ptr [ecx-4] ; Matching parent handle
            INVOKE     BaseAscii, edx, addr szWork, 8, 10, 1, 1, 1
            INVOKE     lstrcat, addr szBuff, addr szWork
               mov     ecx, sPos
               lea     edx, Ctrls.TabIndex
               sub     edx, CtrlsStart
               add     ecx, edx
            INVOKE     BaseAscii, [ecx], addr szWork, 3, 10, 1, 1, 1
            INVOKE     lstrcat, addr szBuff, addr szWork
               mov     edx, Index
            INVOKE     BaseAscii, hArray+[edx*8], addr szWork, 10, 10, 1, 1, 1
            INVOKE     lstrcat, addr szBuff, addr szWork
;XXXXXX
               mov     edx, Index
            INVOKE     BaseAscii, hArray+[edx*8+4], addr szWork, 8, 10, 1, 1, 1
            INVOKE     lstrcat, addr szBuff, addr szWork
            INVOKE     lstrcat, addr szBuff, addr szNULL
            INVOKE     SendMessage, hTemp, LB_ADDSTRING, 0, addr szBuff
               mov     byte ptr szBuff, 0
         .endif
            inc     Index
            dec     Cnt
      .endw

         and     Index, 0
      INVOKE     SendMessage, hTemp, LB_GETCOUNT, 0, 0
         mov     Cnt, eax
      .while (Cnt)
         INVOKE     SendMessage, hTemp, LB_GETTEXT, Index, addr szBuff
         INVOKE     lstrcpyn, addr szWork, addr szBuff+15, 11 ;9
         INVOKE     AsciiBase, addr szWork, 10
            mov     ecx, Index
            mov     hArray+[ecx*8], eax
         INVOKE     lstrcpy, addr szWork, addr szBuff+25 ;21 ;19
         INVOKE     AsciiBase, addr szWork, 10
            mov     ecx, Index
            mov     hArray+[ecx*8+4], eax
            inc     Index
            dec     Cnt
      .endw

      INVOKE     DestroyWindow, hTemp

;---------- [Get dialog handles] ---------
         and     LenD, 0
       MOVmd     CntD, ArrayCnt ;2048 ;1024 ;512 ;64
inc     CntD
         xor     ecx, ecx
      .while (CntD)                          ; Find valid control handles in the array
            mov     eax, LenD
         .if hArray+[eax*8+4]                ; Check for valid handle
               mov     ebx, hArray+[eax*8]   ; Extract array count
               mov     edx, hArray+[eax*8+4] ; Extract handle
               mov     eax, ebx
               and     eax, 0ffffh
            .if eax == 7501
                  mov     hDlg+[ecx*4], edx
                  inc     ecx
            .endif
         .endif
            inc     LenD
            dec     CntD
      .endw

      .if !ecx
            jmp     CheckOut
      .endif
         mov     CntD, ecx
         and     LenD, 0

         mov     eax, LenD
       MOVmd     hCtrl, hDlg+[eax*4]
         inc     LenD
         dec     CntD

;---------- [Build the output] ----------
         and     sw2, 0
         and     Len, 0
       MOVmd     Cnt, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt

GetMore:
      .while (Cnt)                           ; Find valid control handles in the array
            mov     eax, Len
         .if hArray+[eax*8+4]                ; Check for valid handle
               mov     ebx, hArray+[eax*8]   ; Extract array count
               mov     edx, hArray+[eax*8+4] ; Extract handle
               mov     eax, ebx
               and     eax, 0ffffh
               mov     CtrlType, eax
               shr     ebx, 16
mov     CtrlNum, ebx
               inc     Len
               dec     Cnt
            .break
         .endif
            inc     Len
            dec     Cnt
      .endw
;inc     Test4

;---------- [Run out] ----------
      .if !Cnt
         .if CntD
               mov     eax, LenD
             MOVmd     hCtrl, hDlg+[eax*4]
               inc     LenD
               dec     CntD
               and     Len, 0
             MOVmd     Cnt, ArrayCnt ;2048 ;1024 ;512 ;64
inc     Cnt

.if DefOn
INVOKE     lstrcat, DefinesDlg, addr szCRLF
INVOKE     lstrcat, Equates, addr szCRLF
.endif
and     DefOn, 0

               jmp     GetMore
         .endif

         INVOKE     lstrcpy, addr szBuff, addr szEnd
         INVOKE     lstrcat, addr szBuff, addr szCRLF
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff
         INVOKE     lstrcat, DefinesDlg, addr szCRLF

CheckOut:
            mov     eax, PosX
            dec     PosX
         INVOKE     SendMessage, hREdit, EM_SETSEL, PosX, eax

         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szStatic ;Equates
         INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0

         INVOKE     lstrcat, Defines, DefinesDlg
         INVOKE     lstrcat, Defines, addr szCRLF
         INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, Defines

         .if Output == 1 || Output == 3 || Output == 6
               mov     ecx, hREditTab
            INVOKE     SendMessage, ecx, WM_GETTEXT, 64000, DefinesDlg
            INVOKE     lstrcat, DefinesDlg, addr szCRLF
;            INVOKE     lstrcat, DefinesDlg, addr szCRLF
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, DefinesDlg
         .endif

         .if Output == 2 || Output == 3 || Output == 5 || Output == 6
               mov     ecx, hREditTab+4
            INVOKE     SendMessage, ecx, WM_GETTEXT, 64000, DefinesDlg
            INVOKE     lstrcat, DefinesDlg, addr szCRLF
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, DefinesDlg
         .endif

         .if Output == 3 || Output == 5 || Output == 6
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, Accelerator
         .endif

            jmp     Ret0
      .endif
;DSPValue hWnd, Test4, 1, 'm'
;DSPValue hWnd, ebx, 1, 'm'

;---------- [Get offset in the structure array] ----------
        push     ebx
      INVOKE     GetOffset, 1
;DSPValue hWnd, 4444, 1, 'm'
         pop     ebx
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
         mov     sPos, ecx
         mov     Var2, ecx
         add     ecx, StrSize
         mov     eax, dword ptr [ecx-4]    ; Matching parent handle

      .if eax == hCtrl   ; Match dialog handle
            mov     eax, dword ptr [ecx-8] ; = CntType
            sub     ecx, StrSize
;            add     ecx, 4         ;+++++++

         .if CtrlType != 7501
              push     ecx
               lea     eax, Ctrls.ID
               sub     eax, CtrlsStart
               add     ecx, eax
             MOVmd     Var3, dword ptr[ecx]
               pop     ecx
   
               lea     eax, Ctrls.lpName
               sub     eax, CtrlsStart
               add     ecx, eax
         .endif

         .if CtrlType == 7501
              push     ecx
            INVOKE     GetSizes, hCtrl

            INVOKE     GetWindowLong, hCtrl, GWL_EXSTYLE
            .if !(eax & WS_EX_TOOLWINDOW)
;                  sub     SizeT, 3  :NOTE !!!  Removed 09-16-2002
            .endif
               pop     ecx
               lea     eax, Dlg.lpName
               sub     eax, DlgStart
               add     ecx, eax
               lea     eax, Dlg.Left
               sub     eax, DlgStart
               add     Var2, eax

         .else
               lea     eax, Ctrls.Left
               sub     eax, CtrlsStart
               add     Var2, eax
         .endif
            mov     Var1, ecx

;.if byte ptr [ecx]+4 == 'S' && byte ptr [ecx]+5 == 'T' && byte ptr [ecx]+9 == 'C'
;      mov     byte ptr [ecx]+10, 0
;.endif

         INVOKE     lstrcpy, addr szWork1, Var1
.if byte ptr szWork1+4 == 'S' && byte ptr szWork1+5 == 'T' && byte ptr szWork1+9 == 'C' && Var3 == 1 ||\
    byte ptr szWork1+4 == 'S' && byte ptr szWork1+5 == 'T' && byte ptr szWork1+9 == 'C' && !NameOn
      mov     byte ptr szWork1+10, 0
.endif


;---------- [Check for numeric ID name] ----------
         INVOKE     lstrlen, Var1
            mov     ecx, eax
            xor     eax, eax
            mov     edx, Var1
         .while (ecx)
            .if byte ptr [edx+eax] > 39h
               .break
            .endif
               inc     eax
               dec     ecx
         .endw
         .if !ecx
               jmp     NoDef
         .endif

;---------- [Check for standard ID names] ----------
            mov     Cnt4, 10
            and     Len4, 0
         .while (Cnt4)
               mov     eax, Len4
               mov     edx, ComIDArray[eax*4]
;            INVOKE     lstrcmp, Var1, edx
            INVOKE     lstrcmp, addr szWork1, edx
            .if !eax
                  jmp     NoDef
            .endif
               inc     Len4
               dec     Cnt4
         .endw

            mov     DefOn, 1
         .if byte ptr szBuff1 == 0
;            INVOKE     lstrcat, DefinesDlg, addr szCRLF
         .endif

         INVOKE     lstrcat, DefinesDlg, addr szDefine
         INVOKE     lstrcat, DefinesDlg, addr szWork1 ;Var1
         INVOKE     lstrcat, Equates, addr szWork1 ;Var1

            mov     eax, CtrlType
            sub     eax, 7501
            mov     ecx, SizeArray[eax*4]

         INVOKE     lstrcpy, addr szWork, addr szWork1 ;Var1
         INVOKE     lstrlen, addr szWork
            mov     ecx, 30 ;20
            sub     ecx, eax
  
         INVOKE     lstrcpyn, addr szWork, addr szFill, ecx
         INVOKE     lstrcat, DefinesDlg, addr szWork
         INVOKE     lstrcat, Equates, addr szWork
         INVOKE     lstrcat, Equates, addr szEqu

            mov     ecx, sPos
         INVOKE     BaseAscii, [ecx], addr szWork, 1, 10, 1, 1, 0
         INVOKE     lstrcat, DefinesDlg, addr szWork
         INVOKE     lstrcat, Equates, addr szWork
         INVOKE     lstrcat, DefinesDlg, addr szCRLF
         INVOKE     lstrcat, Equates, addr szCRLF

NoDef:
         .if CtrlType == 7501
            .if sw2
               INVOKE     lstrcpy, addr szBuff, addr szEnd
               INVOKE     lstrcat, addr szBuff, addr szCRLF
               INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
               INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff
            .endif
               mov     sw2, 1
            INVOKE     lstrcpy, addr szBuff, addr szWork1 ;Var1
            INVOKE     lstrcat, addr szBuff, addr szDlgEX

            .if ConvertOn
                  mov     LoopIt, 4
                  xor     eax, eax
               .while (LoopIt)
                     mov     ecx, Var2
                     mov     edx, [ecx]
                  .if LoopIt == 1 || LoopIt == 2
                        sub     edx, SizeB
                     .if LoopIt == 1
                           sub     edx, SizeT
                     .endif
                     .if LoopIt == 2
                           sub     edx, SizeB
                     .endif
                  .endif
                     mov     rect.left[eax*4], edx
                     inc     eax
                     add     Var2, 4
                     dec     LoopIt
               .endw
                 call     PixelToUnit
                  xor     eax, eax
                  mov     LoopIt, 4
               .while (LoopIt)
                     mov     ecx, rect.left[eax*4]
                    push     eax
                  INVOKE     BaseAscii, ecx, addr szWork, 1, 10, 1, 1, 0
                  INVOKE     lstrcat, addr szBuff, addr szWork
                  .if LoopIt > 1
                     INVOKE     lstrcat, addr szBuff, addr szComma
                  .endif
                     pop     eax
                     inc     eax
                     dec     LoopIt
               .endw

            .else
                  xor     esi, esi
                  mov     LoopIt, 4
               .while (LoopIt)
                     mov     ecx, Var2
                     mov     eax, [ecx]
                  .if LoopIt == 1 || LoopIt == 2
                        sub     eax, SizeB
                     .if LoopIt == 1
                           sub     eax, SizeT
                     .endif
                     .if LoopIt == 2
                           sub     eax, SizeB
                     .endif
                  .endif
                     xor     edx, edx
                  .if LoopIt == 4 || LoopIt == 2
                       imul     eax, 4
                        mov     ebx, ConvX
                  .else
                       imul     eax, 8
                        mov     ebx, ConvY
                  .endif
                     div     ebx
.if edx > 4
      inc     eax
.endif
                     mov     edi, eax

                     mov     ecx, sPos
                     lea     eax, Dlg.Chg
                     sub     eax, DlgStart
                     add     ecx, eax
                     mov     eax, [ecx]
                  .if !eax
                        sub     ecx, 16
                        mov     edi, [ecx+esi*4]
                  .endif
                  INVOKE     BaseAscii, edi, addr szWork, 1, 10, 1, 1, 0
                  INVOKE     lstrcat, addr szBuff, addr szWork
                  .if LoopIt > 1
                     INVOKE     lstrcat, addr szBuff, addr szComma
                  .endif
                     inc     esi
                     dec     LoopIt
                     add     Var2, 4
               .endw
            .endif

            INVOKE     lstrcat, addr szBuff, addr szCRLF
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff

            INVOKE     lstrcpy, addr szBuff, addr szCapt
            INVOKE     lstrcat, addr szBuff, addr szQuote
               mov     ecx, sPos
;               add     ecx, 168   ;+++++++++
               lea     eax, Dlg.lpCaption
               sub     eax, DlgStart
               add     ecx, eax
            INVOKE     lstrcat, addr szBuff, ecx
            INVOKE     lstrcat, addr szBuff, addr szQuote
            INVOKE     lstrcat, addr szBuff, addr szCRLF
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff

            INVOKE     lstrcpy, addr szBuff, addr szFont
               mov     ecx, sPos
;               add     ecx, 8    ;++++++++
               lea     eax, Dlg.lpFont
               sub     eax, DlgStart
               add     ecx, eax
            INVOKE     lstrcat, addr szBuff, ecx
            INVOKE     lstrcat, addr szBuff, addr szCRLF
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff

            INVOKE     lstrcpy, addr szBuff, addr szSty
               mov     eax, sPos
;               add     eax, 204   ;+++++++++
               lea     edx, Dlg.Style
               sub     edx, DlgStart
               add     eax, edx
               mov     ecx, [eax]
.if (ecx & WS_CLIPCHILDREN)
               xor     ecx, WS_CLIPCHILDREN
.endif
;.if (ecx & WS_CLIPSIBLINGS)
;               xor     ecx, WS_CLIPSIBLINGS
;.endif
.if !(ecx & WS_VISIBLE)
               xor     ecx, WS_VISIBLE
.endif

               mov     eax, sPos
;               add     eax, 739     ;++++++++++++
               lea     edx, Dlg.Code
               sub     edx, DlgStart
               add     edx, 31
               add     eax, edx
            .if byte ptr[eax] == '1'   ; Restore the popup style
                   or     ecx, WS_POPUP
            .endif
            INVOKE     BaseAscii, ecx, addr szWork, 8, 16, 1, 1, 1  ; ??????
            INVOKE     lstrcat, addr szBuff, addr szx
            INVOKE     lstrcat, addr szBuff, addr szWork
            INVOKE     lstrcat, addr szBuff, addr szCRLF
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff

            INVOKE     lstrcpy, addr szBuff, addr szEXSty
               mov     ecx, sPos
;               add     ecx, 200   ;+++++++
               lea     edx, Dlg.ExStyle
               sub     edx, DlgStart
               add     ecx, edx

            INVOKE     BaseAscii, [ecx], addr szWork, 8, 16, 1, 1, 1  ; ??????
            INVOKE     lstrcat, addr szBuff, addr szx
            INVOKE     lstrcat, addr szBuff, addr szWork
            INVOKE     lstrcat, addr szBuff, addr szCRLF
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff

               mov     ecx, sPos
               lea     eax, Dlg.Class
               sub     eax, DlgStart
               add     ecx, eax
            INVOKE     lstrcpy, addr szWork, ecx
            INVOKE     lstrlen, addr szWork
            .if eax
               INVOKE     lstrcpy, addr szBuff, addr szClass
               INVOKE     lstrcat, addr szBuff, addr szQuote
               INVOKE     lstrcat, addr szBuff, addr szWork
               INVOKE     lstrcat, addr szBuff, addr szQuote
               INVOKE     lstrcat, addr szBuff, addr szCRLF
               INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
               INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff
            .endif

            INVOKE     lstrcpy, addr szBuff, addr szBegin
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff

         .else
;---------- [Caption] ----------
            INVOKE     lstrcpy, addr szBuff, addr szCont
            .if CtrlType != 7523 && CtrlType != 7524 && CtrlType != 7525   ; Bitmap Icon
               INVOKE     lstrcat, addr szBuff, addr szQuote
            .endif
               mov     ecx, sPos
;               add     ecx, 36    ;+++++++
               lea     edx, Ctrls.lpCaption
               sub     edx, CtrlsStart
               add     ecx, edx
            INVOKE     lstrcat, addr szBuff, ecx
            .if CtrlType != 7523 && CtrlType != 7524 && CtrlType != 7525   ; Bitmap Icon
               INVOKE     lstrcat, addr szBuff, addr szQuote
            .endif
            INVOKE     lstrcat, addr szBuff, addr szComma
;               mov     ecx, sPos
;            INVOKE     BaseAscii, [ecx], addr szWork, 1, 10, 1, 1, 0
;            INVOKE     lstrcat, addr szBuff, addr szWork

;---------- [Item ID] ----------
               mov     ecx, sPos
;               add     ecx, 4   ;+++++++++
               lea     eax, Ctrls.lpName
               sub     eax, CtrlsStart
               add     ecx, eax

         INVOKE     lstrcpy, addr szWork1, ecx
.if byte ptr szWork1+4 == 'S' && byte ptr szWork1+5 == 'T' && byte ptr szWork1+9 == 'C' && Var3 == 1 ||\
    byte ptr szWork1+4 == 'S' && byte ptr szWork1+5 == 'T' && byte ptr szWork1+9 == 'C' && !NameOn
      mov     byte ptr szWork1+10, 0
.endif

            INVOKE     lstrcat, addr szBuff, addr szWork1 ;ecx
            INVOKE     lstrcat, addr szBuff, addr szComma
            INVOKE     lstrcat, addr szBuff, addr szQuote
               mov     eax, CtrlType
               sub     eax, 7501
             MOVmd     cAddr, ClassArray[eax*4]

               mov     ecx, sPos
               lea     eax, Ctrls.Class
               sub     eax, CtrlsStart
               add     ecx, eax

            .if byte ptr [ecx] != 0
               INVOKE     lstrcat, addr szBuff, ecx
            .else
               INVOKE     lstrcat, addr szBuff, cAddr
            .endif

            INVOKE     lstrcat, addr szBuff, addr szQuote
            INVOKE     lstrcat, addr szBuff, addr szComma

;---------- [Style] ----------
               mov     ecx, sPos
;               add     ecx, 72   ;+++++++++
               lea     eax, Ctrls.Style
               sub     eax, CtrlsStart
               add     ecx, eax

;N O T E !!!!!!!!!!!!
               mov     eax, CtrlType
            .if eax != 7503 ;&& eax != 7508
                  mov     eax, [ecx]
.if (eax & WS_CLIPSIBLINGS)
                  xor     eax, WS_CLIPSIBLINGS
.endif
                  mov     [ecx], eax
            .endif
;********************

            INVOKE     BaseAscii, [ecx], addr szWork, 8, 16, 1, 1, 1  ; ??????
            INVOKE     lstrcat, addr szBuff, addr szx
            INVOKE     lstrcat, addr szBuff, addr szWork
            INVOKE     lstrcat, addr szBuff, addr szComma

;---------- [x, y, and size] ----------

            .if ConvertOn == 9999
                  mov     LoopIt, 4
                  xor     eax, eax
               .while (LoopIt)
                     mov     ecx, Var2
                     mov     edx, [ecx]
                     mov     rect.left[eax*4], edx
                     inc     eax
                     add     Var2, 4
                     dec     LoopIt
               .endw
                 call     PixelToUnit
                  xor     eax, eax
                  mov     LoopIt, 4
               .while (LoopIt)
                     mov     ecx, rect.left[eax*4]
                    push     eax
                  INVOKE     BaseAscii, ecx, addr szWork, 1, 10, 1, 1, 0
                  INVOKE     lstrcat, addr szBuff, addr szWork
                  INVOKE     lstrcat, addr szBuff, addr szComma
                     pop     eax
                     inc     eax
                     dec     LoopIt
               .endw

            .else
                  xor     esi, esi
                  mov     LoopIt, 4
               .while (LoopIt)
                     mov     ecx, Var2
                     mov     eax, [ecx]
                  .if LoopIt == 4 || LoopIt == 2
                       imul     eax, 4
                        mov     ebx, ConvX
                  .else
                       imul     eax, 8
                        mov     ebx, ConvY
                  .endif
                     xor     edx, edx
                     div     ebx
                     mov     edi, eax

                     mov     ecx, sPos
                     lea     eax, Ctrls.Chg
                     sub     eax, CtrlsStart
                     add     ecx, eax
                     mov     eax, [ecx]
                  .if !eax
                        sub     ecx, 16
                        mov     edi, [ecx+esi*4]
                  .endif
   
                  INVOKE     BaseAscii, edi, addr szWork, 1, 10, 1, 1, 0
                  INVOKE     lstrcat, addr szBuff, addr szWork
                  INVOKE     lstrcat, addr szBuff, addr szComma
                     inc     esi
                     dec     LoopIt
                     add     Var2, 4
               .endw
            .endif

;---------- [EXStyle] ----------
               mov     ecx, sPos
;               add     ecx, 68   ;+++++++
               lea     eax, Ctrls.ExStyle
               sub     eax, CtrlsStart
               add     ecx, eax
.if byte ptr[ecx] == WS_EX_TRANSPARENT
      mov     byte ptr[ecx], 0
.endif
            INVOKE     BaseAscii, [ecx], addr szWork, 8, 16, 1, 1, 1  ; ??????
            INVOKE     lstrcat, addr szBuff, addr szx
            INVOKE     lstrcat, addr szBuff, addr szWork
            INVOKE     lstrcat, addr szBuff, addr szCRLF
            INVOKE     SendMessage, hREdit, EM_SETSEL, -1, 0
            INVOKE     SendMessage, hREdit, EM_REPLACESEL, FALSE, addr szBuff
         .endif

      .endif
      .if Cnt
            jmp     GetMore
      .endif

Ret0:
         xor     eax, eax
         ret
BuildRes ENDP

;=====================================================
; GetDefines PROCEDURE
;=====================================================
GetDefines PROC  uses esi edi  hwnd:DWORD, hdlg, ItemID
LOCAL    ft:FINDTEXT
LOCAL    cr:CHARRANGE
LOCAL    tr:TEXTRANGE
LOCAL    CtrlsOn:DWORD, FirstTime, SavStart
LOCAL    szBuff0[256]:BYTE, szBuff1[256]:BYTE, szBuff2[64]:BYTE

            mov     byte ptr szBuff1, 0
            and     FirstTime, 0
            mov     ecx, Accelerator
            mov     byte ptr[ecx], 0
            mov     ft.chrg.cpMin, 0
            mov     ft.chrg.cpMax, -1
            lea     eax, offset szUnder
            mov     ft.lpstrText, eax

GetMore:
         INVOKE     SendMessage, hwnd, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax == -1
               mov     ecx, Accelerator
            .if byte ptr[ecx] != 0
               INVOKE     lstrcat, Accelerator, addr szFindE
               INVOKE     lstrcat, Accelerator, addr szCRLF
               INVOKE     lstrcat, Accelerator, addr szCRLF
            .endif
               jmp     Ret0
         .endif
         .if eax != -1
            .if !FirstTime
                 push     eax
               INVOKE     lstrcat, Defines, addr szCRLF
               INVOKE     lstrcat, Equates, addr szCRLF
                  pop     eax
                  mov     FirstTime, 1
                  mov     ecx, hdlg
               .if ecx == hDlg0
                     add     Output, 1
               .elseif ecx == hDlg1
                     add     Output, 2
               .endif
            .endif
               mov     SavStart, eax
               mov     ft.chrg.cpMin, eax
            .if eax > 5
                  sub     eax, 5
            .else
                  mov     eax, 0
            .endif
               mov     tr.chrg.cpMin, eax
               add     eax, 20
               mov     tr.chrg.cpMax, eax
               lea     eax, szBuff1
               mov     tr.lpstrText, eax
            INVOKE     SendMessage, hwnd, EM_GETTEXTRANGE, 0, addr tr
               mov     ecx, eax
               xor     esi, esi
               xor     edi, edi
               mov     byte ptr szBuff0, 0
            .if !tr.chrg.cpMin
                  mov     al, byte ptr szBuff1[esi]
                  mov     byte ptr szBuff0[edi], al
                  inc     esi
                  inc     edi
                  dec     ecx
            .endif

            .while (ecx)
                  mov     al, byte ptr szBuff1[esi]
               .if al == 0ah && !szBuff0 || al == 0dh && !szBuff0 ||\
                   al == 20h && !szBuff0 || al == 22h && !szBuff0
.elseif al == '"'
      jmp     NoGo
               .elseif al == 0dh && szBuff0 || al == 2ch && szBuff0 || al == 20h && szBuff0
                     mov     byte ptr szBuff0[edi], 0
                  .break
               .else
                     mov     byte ptr szBuff0[edi], al
                     inc     edi
               .endif
                  inc     esi
                  dec     ecx
            .endw
         .endif

         INVOKE     lstrcpy, addr szBuff1, addr szBuff0

          MOVmd     ft.chrg.cpMin, tr.chrg.cpMin
            mov     ft.chrg.cpMax, 0
            lea     eax, szBuff0
            mov     ft.lpstrText, eax

;---------- [Check for dups] ----------
         INVOKE     SendMessage, hwnd, EM_FINDTEXT, 0, addr ft
         .if eax == -1
            INVOKE     lstrcat, Defines, addr szDefine
            INVOKE     lstrcat, Defines, addr szBuff0
            INVOKE     lstrcat, Equates, addr szBuff0
            INVOKE     lstrlen, addr szBuff0
               mov     ecx, 20
               sub     ecx, eax
            INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
            INVOKE     lstrcat, Defines, addr szBuff0
            INVOKE     lstrcat, Equates, addr szBuff0
            INVOKE     lstrcat, Equates, addr szEqu
            INVOKE     BaseAscii, ItemID, addr szBuff0, 1, 10, 1, 1, 0
            INVOKE     lstrcat, Defines, addr szBuff0
            INVOKE     lstrcat, Equates, addr szBuff0
            INVOKE     lstrcat, Defines, addr szCRLF
            INVOKE     lstrcat, Equates, addr szCRLF
               inc     ItemID
         .endif

NoGo:
;           push     tr.chrg.cpMax
            mov     eax, hdlg
;---------- [Get accelerators] ----------
         .if eax == hDlg1
               lea     eax, szMenuI
               mov     ft.lpstrText, eax
            INVOKE     SendMessage, hwnd, EM_FINDTEXT, 0, addr ft
            .if eax != -1
                  mov     ft.chrg.cpMin, eax
                MOVmd     ft.chrg.cpMax, tr.chrg.cpMax
                  lea     eax, szSlashB
                  mov     ft.lpstrText, eax
               INVOKE     SendMessage, hwnd, EM_FINDTEXT, FR_DOWN, addr ft
               .if eax != -1
                     mov     tr.chrg.cpMin, eax
                     mov     ft.chrg.cpMin, eax
                     lea     eax, szQuote
                     mov     ft.lpstrText, eax
                  INVOKE     SendMessage, hwnd, EM_FINDTEXT, FR_DOWN, addr ft
                  .if eax != -1
                        inc     eax
                        mov     tr.chrg.cpMax, eax
                        lea     eax, szBuff2
                        mov     tr.lpstrText, eax

                        mov     ecx, Accelerator
                     .if byte ptr[ecx] == 0
                        INVOKE     lstrcpy, Accelerator, addr szAccel
                           add     Output, 3
                     .endif
                     INVOKE     SendMessage, hwnd, EM_GETTEXTRANGE, 0, addr tr
                        mov     esi, 2
                        xor     edi, edi
                        mov     byte ptr szBuff0, 0
                        mov     ecx, 5
                     INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
                     INVOKE     lstrcat, Accelerator, addr szBuff0
                        and     CtrlsOn, 0
                     .if byte ptr szBuff2[esi] == 'C' && byte ptr szBuff2[esi+1] == 't'
                           mov     CtrlsOn, 1
                        .if byte ptr szBuff2[esi+5] != 'F'
                           INVOKE     lstrcat, Accelerator, addr szQuote
                              mov     esi, 2
                              xor     edi, edi
                              mov     ax, word ptr szBuff2[esi+5]
                              mov     word ptr szBuff0[edi], ax
                              mov     byte ptr szBuff0[edi+2], 0
                           INVOKE     lstrcat, Accelerator, addr szBuff0
                        .else
                           INVOKE     lstrcpy, addr szBuff0, addr szVK
                              mov     esi, 2
                              xor     edi, edi
                              mov     ax, word ptr szBuff2[esi+5]
                              mov     word ptr szBuff0[edi+3], ax
                              mov     byte ptr szBuff0[edi+5], 0

FinishIt:
                           INVOKE     lstrcat, Accelerator, addr szBuff0
                        .endif
                        INVOKE     lstrcat, Accelerator, addr szComma
                           mov     ecx, 2
                        .if byte ptr szBuff2+2 != 'F' && byte ptr szBuff2+7 != 'F'
                              add     ecx, 2
                        .endif
                        INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
                        INVOKE     lstrcat, Accelerator, addr szBuff0
                        INVOKE     lstrcat, Accelerator, addr szBuff1
                        INVOKE     lstrcat, Accelerator, addr szComma
                        INVOKE     lstrlen, addr szBuff1
                           mov     ecx, 20
                           sub     ecx, eax
                        INVOKE     lstrcpyn, addr szBuff0, addr szFill, ecx
                        INVOKE     lstrcat, Accelerator, addr szBuff0
                        INVOKE     lstrcat, Accelerator, addr szVKey
                        .if CtrlsOn
                           INVOKE     lstrcat, Accelerator, addr szControl
                        .endif
                        INVOKE     lstrcat, Accelerator, addr szCRLF
                     .elseif byte ptr szBuff2[esi] == 'F'
                        INVOKE     lstrcpy, addr szBuff0, addr szVK
                           xor     esi, esi
                           xor     edi, edi
                           mov     ax, word ptr szBuff2[esi+2]
                           mov     word ptr szBuff0[edi+3], ax
                           mov     byte ptr szBuff0[edi+5], 0
                           jmp     FinishIt
                     .endif
                  .endif
               .endif
            .endif
         .endif

;            pop     tr.chrg.cpMax
;          MOVmd     ft.chrg.cpMin, tr.chrg.cpMax
          MOVmd     ft.chrg.cpMin, SavStart
            inc     ft.chrg.cpMin
            mov     ft.chrg.cpMax, -1
            lea     eax, offset szUnder
            mov     ft.lpstrText, eax
            jmp     GetMore

Ret0:
         xor     eax, eax
         ret
GetDefines ENDP

;===============================================================
; Open file PROCEDURE
;===============================================================
OpenFileA  PROC
LOCAL    ofn:OPENFILENAME
LOCAL    EditS:EDITSTREAM
LOCAL    hFile:DWORD
LOCAL    SavPathName[256]:Byte

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

      .if sw3 == 4
            jmp     ByPass
      .endif
      INVOKE     lstrcpy, addr PathName, addr RootPath

      .if sw3 == 1
         INVOKE     lstrcpy, addr PathName, addr szResPath
         INVOKE     lstrcat, addr PathName, addr szEndR
      .endif
      .if sw3 == 2
         INVOKE     lstrcat, addr PathName, addr szSample
         jmp     ByPass
      .endif
      .if sw3 == 3 || sw3 == 6
         INVOKE     lstrcat, addr PathName, addr szStyles
         jmp     ByPass
      .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
         lea     eax, PathName
         mov     ofn.lpstrFile, eax
         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
            jmp     EndOpen
      .endif
      INVOKE     SetCurrentDirectory, addr RootPath ;SavPathName

ByPass:
      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

operr:
      .if sw3 == 4
         INVOKE     ProcessMRUFiles, hDlg3, 1, MenuCnt, addr PathName, addr szRedit, hFMenu
         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

      .if sw3 == 3
         INVOKE     SendMessage, hStyles, EM_STREAMIN, SF_TEXT, addr EditS
      .elseif sw3 == 6
         INVOKE     SendMessage, hDefaults, EM_STREAMIN, SF_TEXT, addr EditS
      .else
         INVOKE     SendMessage, hREdit, EM_STREAMIN, SF_TEXT, addr EditS
      .endif
      INVOKE     CloseHandle, hFile
      .if sw3 == 1 || sw3 == 4
         INVOKE     SetWindowText, hWnd, addr PathName
         .if sw3 == 1
            INVOKE     lstrlen, addr PathName
            .while (eax)
               .if byte ptr PathName[eax] == '\'
                  .break
               .endif
                  dec     eax
            .endw
               inc     eax
            INVOKE     lstrcpyn, addr szResPath, addr PathName, eax
         .endif
      .endif
      INVOKE     SendMessage,  hREdit, EM_SETMODIFY, FALSE, 0
      .if sw3 != 2 && sw3 != 3 && sw3 != 6
         INVOKE     ProcessMRUFiles, hDlg3, 0, MenuCnt, addr PathName, addr szRedit, hFMenu
      .endif

EndOpen:
           and     sw3, 0
           ret
OpenFileA  ENDP

;=====================================================
; Save file PROCEDURE
;=====================================================
SaveFile PROC
LOCAL    ofn:OPENFILENAME
LOCAL    EditS:EDITSTREAM
LOCAL    hFile:DWORD


      INVOKE     SendMessage, hREdit, WM_GETTEXTLENGTH, 0, 0
      .if !eax || eax < 5
            jmp     EndSave
      .endif
         INVOKE     GetWindowText, hWnd, addr PathName, lengthof PathName
         INVOKE     lstrlen, addr PathName
         .if !eax
            INVOKE     lstrcpy, addr PathName, addr szRC
         .endif
      .if sw6 == 1
            jmp     SavIt
      .endif

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

;---------- [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, PathName
         mov     ofn.lpstrFile, eax
         mov     ofn.nMaxFile, lengthof PathName
         mov     ofn.lpstrTitle, offset szSaveTitle
         mov     ofn.Flags, OFN_OVERWRITEPROMPT or OFN_CREATEPROMPT or\
                 OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST
      INVOKE     GetSaveFileName, addr ofn
         cmp     eax, FALSE          ; Cancel'ed or error occurred
          je     EndSave

SavIt:
      INVOKE     CreateFile, addr PathName,\
                 GENERIC_READ or GENERIC_WRITE ,\
                 FILE_SHARE_READ or FILE_SHARE_WRITE,\
                 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
         cmp     eax, -1             ; Error?
         jne     savcrok

saverr:
         jmp     EndSave

savcrok:
         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
      INVOKE     CloseHandle, hFile
      INVOKE     SendMessage,  hREdit, EM_SETMODIFY, FALSE, 0

EndSave:
         and     sw6, 0

         ret
SaveFile 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

;=====================================================
; Edit Stream Save Callback PROCEDURE
;=====================================================
EditStreamWrite PROC  lpCookie:DWORD, pbBuff, cb, pcb
      INVOKE     WriteFile, lpCookie, pbBuff, cb, pcb, 0
         mov     eax, 0              ; File completely read
         ret
EditStreamWrite 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

;=====================================================
; Check for children within the groupbox PROCEDURE
;=====================================================
ChkChildren PROC
LOCAL    Trect:RECT
LOCAL    hChild:DWORD, Incr

      INVOKE     CopyRect, addr Trect, addr Srect
         and     Incr, 0
       MOVmd     Cnt, ArrayCnt
inc     Cnt
      .while (Cnt)               ; Get handle of controls in the array
            mov     eax, Incr
            mov     ecx, hArray[eax+4]
            mov     hChild, ecx
            mov     ecx, hArray[eax]
            and     ecx, 0ffffh
            mov     CtrlType, ecx
         INVOKE     IsChild, hCtrl, hChild
         .if eax
              push     hCtrl
             MOVmd     hCtrl, hChild
;            .if !xGrp || !yGrp
               INVOKE     MouseMUD, hCtrl, WM_LBUTTONDOWN, 0, 1234
;            .endif
            INVOKE     GetWindowRect, hCtrl, addr Srect
               mov     eax, Srect.left
               sub     Srect.right, eax
               mov     eax, Srect.top
               sub     Srect.bottom, eax
               mov     eax, Prect.left
               sub     Srect.left, eax
               mov     eax, Prect.top
               sub     Srect.top, eax

               mov     eax, xGrp
               add     Srect.left, eax
               mov     eax, yGrp
               add     Srect.top, eax

              push     dis.itemID
               mov     dis.itemID, 0
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
               add     ecx, CtrlsLeftOrg
               add     ecx, 16
               mov     byte ptr[ecx], 6  ; Change
               pop     dis.itemID

            INVOKE     MoveGrabbers, 5, 4
               pop     hCtrl

         .endif
            add     Incr, 8
            dec     Cnt
      .endw
         mov     CtrlType, 7503
      INVOKE     CopyRect, addr Srect, addr Trect
         ret
ChkChildren ENDP

;=====================================================
; Mouse move - up - down - del
;=====================================================
MouseMUD PROC uses ebx esi edi hwnd:DWORD, wmsg, wparam, lparam
LOCAL    pt:POINT
LOCAL    Crect:RECT
LOCAL    SavGrp:DWORD, Val
LOCAL    szBuff[64]:BYTE

      INVOKE     GetCursor
      .if eax == h898 || eax == h899
.if lparam != 1234
            mov     eax, 1
            ret
.endif
      .endif

      .if wmsg == WM_LBUTTONDBLCLK
            mov     wmsg, WM_LBUTTONDOWN
      .endif
      .if wmsg == WM_RBUTTONDOWN && wparam != MK_LBUTTON or MK_RBUTTON
         INVOKE     EnableMenuItem, hRMenu, IDM_COPY, MF_ENABLED
         INVOKE     EnableMenuItem, hRMenu, IDM_PASTE, MF_GRAYED
         INVOKE     SetFocus, hForm
            jmp     PopUp

      .elseif wmsg == WM_LBUTTONDOWN && (wparam & MK_CONTROL) ||\
              wmsg == WM_MOUSEMOVE && (wparam & MK_CONTROL)
            mov     eax, 1
            ret

      .elseif wmsg == WM_LBUTTONUP && (wparam & MK_CONTROL)
   mov     eax, hwnd
.if CtrlType == 7503 && eax == hGrp
      mov     eax, 1
      ret
.endif
            and     xGrp, 0
            and     yGrp, 0

;---------- [Check to see if the control has already been selected] ----------
            mov     edx, hwnd
            xor     eax, eax
            mov     ecx, MultiCnt
         .while (ecx)     ; See if handle of the control has already been selected
            .if hMultiArray[eax+4] == edx
                MOVmd     hWorkArray, hMultiArray[eax]
                MOVmd     hWorkArray+4, hMultiArray[eax+4]

                  xor     eax, eax
                  mov     ebx, 8
                  mov     ecx, MultiCnt
               .while (ecx)     ; Copy to work
                  .if hMultiArray[eax+4] != edx
                      MOVmd     hWorkArray[ebx], hMultiArray[eax]
                      MOVmd     hWorkArray[ebx+4], hMultiArray[eax+4]
                        add     eax, 8
                        add     ebx, 8
                  .else
                        add     eax, 8
                  .endif
                     dec     ecx
               .endw

                  xor     eax, eax
                  mov     ecx, MultiCnt
               .while (ecx)     ; Copy back
                   MOVmd     hMultiArray[eax], hWorkArray[eax]
                   MOVmd     hMultiArray[eax+4], hWorkArray[eax+4]
                     add     eax, 8
                     dec     ecx
               .endw
                  mov     eax, 1
                  ret

            .endif
               add     eax, 8
               dec     ecx
         .endw

         INVOKE     CreateWindowEx, 0, addr MultiClass, 0,\
                    WS_CHILD or WS_VISIBLE or WS_BORDER,\
                    0, 0, 6, 6, hwnd, 0, hInst, 0
            mov     ecx, MultiCnt
         .if ecx < 32
               mov     hMultiArray+[ecx*8], eax      ; Save parent handle
             MOVmd     hMultiArray+[ecx*8+4], hwnd   ; Save control handle
              imul     ecx, 20
               mov     edx, UnDoArray
             MOVmd     [edx+ecx], hwnd
               inc     MultiCnt
         .else
            INVOKE     DestroyWindow, eax
         .endif
.if !hSMove
    MOVmd     hSMove, hwnd
    MOVmd     CtrlHnd, hwnd
.endif
            mov     eax, 1
            ret

; For CtrlType 7503 hwnd = Groupbox parent
      .elseif wmsg == WM_LBUTTONDOWN
         INVOKE     GetWindowRect, hwnd, addr Savrect

         .if lparam != 5678
               mov     edx, hwnd
               xor     eax, eax
               xor     ebx, ebx
               mov     ecx, MultiCnt
            .while (ecx)     ; See if handle of the control is in the multi sel array
               .if hMultiArray[eax+4] == edx
                     mov     ecx, hMultiArray[eax]
                     mov     hMultiArray[eax], 0
                     mov     hMultiArray[eax+4], 0
                    imul     ebx, 20
                     mov     edx, UnDoArray
                     mov     dword ptr[edx+ebx], 0
                  INVOKE     DestroyWindow, ecx
                  .if MultiCnt == 1
                        and     MultiCnt, 0
                  .endif
                  .break  
               .endif
                  add     eax, 8
                  inc     ebx
                  dec     ecx
            .endw
         .endif

            and     hGrpOn, 0
         INVOKE     GetParent, hwnd
            mov     edx, eax
            xor     eax, eax
            mov     ecx, GrpCnt ;32
         .while (ecx) ; Find handle of Groupbox parent in the array
            .if hGrpArray[eax+4] == edx
                  mov     hGrpOn, 1
                MOVmd     hGrp, hGrpArray[eax]
                MOVmd     hParent, hGrpArray[eax]
                MOVmd     SavGrp, hGrpArray[eax+4]
               .break  
            .endif
               add     eax, 8
               dec     ecx
         .endw

            and     BorderOn, 0
         .if hStyle && lparam != 1234
            INVOKE     StyleProc, hStyle, WM_COMMAND, 5006, 0
               and     hStyle, 0
         .endif

            and     ComboOn, 0
            xor     eax, eax
            mov     ecx, ArrayCnt ;2048 ;1024 ;512 ;64
inc     ecx
         .while (ecx)                  ; Find handle of active control in the array
               mov     edx, hwnd
            .if hArray[eax+4] == edx
                  mov     ebx, hArray[eax]
                  and     ebx, 0ffffh
                  mov     CtrlType, ebx
               .if CtrlType == 7509  ; Combobox
                     mov     ComboOn, 1
                  INVOKE     SendMessage, hwnd, CB_GETDROPPEDCONTROLRECT, 0, addr CBrect
                     mov     eax, CBrect.left
                     sub     CBrect.right, eax
                     mov     eax, CBrect.top
                     sub     eax, 6
                     sub     CBrect.bottom, eax
               .endif
               .break
            .endif
               add     eax, 8
               dec     ecx
         .endw

         INVOKE     BringWindowToTop, hwnd
         INVOKE     RedrawWindow, hwnd, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN
         .if lparam != 6969
            INVOKE     LoadCursor, 0, IDC_ARROW
            INVOKE     SetCursor, eax
         .endif
         INVOKE     SetCapture, hwnd
         INVOKE     GetParent, hwnd
         .if !hGrpOn
               mov     hParent, eax
         .endif
          MOVmd     hCtrl, hwnd
            and     PosX, 0
            and     PosY, 0
         INVOKE     GetWindowRect, hForm, addr Prect
            mov     eax, hParent
         .if eax == hForm
            INVOKE     GetWindowRect, hwnd, addr Srect
         .elseif CtrlType == 7503
            INVOKE     GetWindowRect, hGrp, addr Srect
               mov     eax, SizeB
               sub     Prect.left, eax
               sub     Prect.right, eax
               mov     eax, SizeT
               sub     Prect.top, eax
         .else
            INVOKE     GetWindowRect, hGrp, addr Prect
               mov     eax, SizeB
               sub     Prect.left, eax
               sub     Prect.right, eax
               mov     eax, SizeT
               sub     Prect.top, eax
            INVOKE     GetWindowRect, hwnd, addr Srect
         .endif

;---------- [Get the right & bottom boundries of the parent window] ----------
            mov     eax, Prect.right
            mov     ParR, eax
            mov     eax, Prect.bottom
            mov     ParB, eax

            mov     eax, hParent
         .if eax == hForm
               sub     ParR, 3 ;6
               sub     ParB, 3 ;22
         .endif

         .if hGrpOn
            INVOKE     GetWindowLong, SavGrp, GWL_STYLE
            .if (eax & WS_BORDER)
                  mov     BorderOn, 1
            .endif
         
            INVOKE     GetWindowRect, hForm, addr Crect
               mov     eax, Prect.left
               sub     eax, Crect.left
               sub     eax, SizeB
               mov     xGrp, eax
               mov     eax, Prect.top
               sub     eax, Crect.top
               sub     eax, SizeT
               mov     yGrp, eax
         .endif

         .if lparam != 1234 && lparam != 5678
            INVOKE     ControlRect, addr Srect, 0, 0
            INVOKE     RedrawWindow, hwnd, 0, 0,\
                       RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN
         .endif

;         .if lparam == 1234 || lparam == 5678
               mov     eax, Srect.left
               sub     Srect.right, eax
               mov     eax, Srect.top
               sub     Srect.bottom, eax
            .if ComboOn
                  sub     Srect.bottom, 6
            .endif
               mov     eax, Prect.left
            .if CtrlType == 7503 && lparam == 1234 || CtrlType == 7503 && lparam == 5678
                  add     eax, SizeB
            .endif
               add     eax, SizeB
               sub     Srect.left, eax
               mov     eax, Prect.top
            .if CtrlType == 7503 && lparam == 1234 || CtrlType == 7503 && lparam == 5678
                  add     eax, SizeT
            .endif
               add     eax, SizeT
               sub     Srect.top, eax

         .if lparam == 1234 || lparam == 5678
            .if ComboOn && lparam == 1234
                  mov     eax, CBrect.bottom
                  sub     eax, Srect.bottom
                  add     Srect.bottom, eax
                  sub     Srect.bottom, 6
            .endif
            INVOKE     ReleaseCapture
               mov     eax, 1
               ret
         .endif

         .if ComboOn
               mov     eax, CBrect.bottom
               sub     eax, Srect.bottom
               add     Srect.bottom, eax
         .endif
         .if CtrlType == 7513
               mov     Srect.left, 0
               mov     Srect.top, 0
               mov     Srect.bottom, 28
         .endif
         INVOKE     MoveGrabbers, 5, 4

         .if !hSizeData
            INVOKE     CreateDialogParam, hInst, 4902, hWnd, offset SizeDataProc, 0
         .endif
 MOVmd     hSMove, hwnd
 MOVmd     CtrlHnd, hwnd
 MOVmd     SavCtrl, CtrlType
;INVOKE     SetFocus, hForm
   mov     DownOn, 1
            mov     eax, 1
            ret

      .elseif wmsg == WM_MOUSEMOVE
         .if !DownOn
            .if hSizeData
               INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
                  and     hSizeData, 0
            .endif
               jmp     Ret0
         .endif
         .if lparam != 6969
            INVOKE     LoadCursor, 0, IDC_ARROW
            INVOKE     SetCursor, eax
         .endif
         .if wparam == MK_LBUTTON
            INVOKE     GetWindowRect, hwnd, addr Srect
            INVOKE     GetCursorPos, addr pt
            INVOKE     ScreenToClient, hwnd, addr pt
               mov     eax, pt.x
               sub     eax, Srect.left
               mov     ebx, pt.y
               sub     ebx, Srect.top

            .if NoMoveOn
                  xor     eax, eax
                  xor     ebx, ebx
            .endif

            .if !PosX && !PosY
                  mov     PosX, eax
                  mov     PosY, ebx
                  mov     ecx, Srect.right
                  sub     ecx, Srect.left
                  mov     PosR, ecx
                  mov     ecx, Srect.bottom
                  sub     ecx, Srect.top
                  mov     PosB, ecx

            .endif
               sub     eax, PosX
               sub     ebx, PosY
               add     Srect.left, eax
               add     Srect.top, ebx
               add     Srect.right, eax
               add     Srect.bottom, ebx

            .if ComboOn
                  mov     eax, CBrect.bottom
                  mov     ecx, Srect.top
                  mov     Srect.bottom, ecx
                  add     Srect.bottom, eax
            .endif

            .if BorderOn
                  dec     Srect.left
                  dec     Srect.top
                  dec     Srect.right
                  dec     Srect.bottom
            .endif

;---------- [Keep the control within the parent boundries] ----------
               mov     ecx, ParR
               mov     edx, ParB
            .if Srect.right > ecx
                  mov     Srect.right, ecx
                  sub     ecx, PosR
                  mov     Srect.left, ecx
            .endif
               mov     ebx, 1
            .if Srect.bottom > edx && ComboOn
                  and     ebx, 0
            .endif
            .if ComboOn
                  mov     eax, CBrect.bottom
                  sub     eax, 22
                  add     edx, eax
            .endif

            .if hGrpOn
                  sub     edx, 3
            .endif
            .if Srect.bottom > edx
               .if ComboOn
                     sub     edx, CBrect.bottom
                     add     edx, 22
               .endif
                  mov     Srect.bottom, edx
                  sub     edx, PosB
                  mov     Srect.top, edx
            .endif

               mov     eax, Prect.left
               add     eax, SizeB
            .if hGrpOn
                  add     eax, 3
            .endif
            .if Srect.left < eax || Srect.left > 0fffh
                  mov     Srect.left, eax
                  add     eax, PosR
                  mov     Srect.right, eax
            .endif

               mov     eax, Prect.top
               add     eax, SizeT
            .if hGrpOn
                  add     eax, 8
            .endif
            .if Srect.top < eax || Srect.top > 0fffh
                  mov     Srect.top, eax
                  add     eax, PosB
                  mov     Srect.bottom, eax
            .endif

            .if !hSizeData
               INVOKE     CreateDialogParam, hInst, 4902, hWnd, offset SizeDataProc, 0
            .endif

            .if SnapOn
                 call     SnapTo
            .endif
            INVOKE     ControlRect, addr Srect, 1, 0
              push     Srect.left
              push     Srect.top

               mov     eax, Prect.left
               add     eax, SizeB
               sub     Srect.left, eax
               mov     eax, Prect.top
               add     eax, SizeT
               sub     Srect.top, eax

            .if hGrpOn
                  mov     eax, xGrp
                  add     eax, SizeB
                  add     Srect.left, eax
                  mov     eax, yGrp
                  add     eax, SizeT
                  add     Srect.top, eax
            .endif

            .if lparam != 6969
               INVOKE     PosProc, hwnd, Srect.left, Srect.top, 11
            .endif

               pop     Srect.top
               pop     Srect.left
         .endif
            jmp     Ret0

      .elseif wmsg == WM_LBUTTONUP
   and     ParentOn, 0
.if !DownOn
MOVmd     hCtrl, hwnd
      jmp     Ret0
.endif
            and     DownOn, 0
         INVOKE     ControlRect, addr Srect, 2, 0
         INVOKE     ReleaseCapture
         .if hSizeData
            INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
               and     hSizeData, 0
         .endif
         .if CtrlType == 7514    ; Statusbar
               jmp     NoMove
         .endif

            mov     eax, Srect.left
            sub     Srect.right, eax
            mov     eax, Srect.top
            sub     Srect.bottom, eax
         .if ComboOn
               sub     Srect.bottom, 6
         .endif

            mov     eax, Prect.left
            add     eax, SizeB
            sub     Srect.left, eax
            sub     Savrect.left, eax
            mov     eax, Prect.top
            add     eax, SizeT
            sub     Srect.top, eax
            sub     Savrect.top, eax

         .if CtrlType == 7513    ; Toolbar
               mov     Srect.left, 0
               mov     Srect.top, 0
               mov     Savrect.left, 0
               mov     Savrect.top, 0
               mov     Srect.bottom, 28
               jmp     NoMove ;Ret0

         .endif

         INVOKE     MoveWindow, hwnd, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE

NoMove:
         .if CtrlType == 7503
               xor     eax, eax
               mov     edx, hGrp
               mov     ecx, GrpCnt ;32
            .while (ecx)         ; Find handle of Groupbox parent in the array
               .if hGrpArray[eax] == edx
                     mov     ecx, hGrpArray[eax+4]
                     mov     hCtrl, ecx
                  .break  
               .endif
                  add     eax, 8
                  dec     ecx
            .endw
            INVOKE     MoveWindow, hCtrl, 0, 0, Srect.right, Srect.bottom, TRUE
              push     hGrpOn
              call     ChkChildren
               pop     hGrpOn
         .endif

         .if hGrpOn
               mov     eax, xGrp
               add     eax, SizeB
               add     Srect.left, eax
               add     Savrect.left, eax
               mov     eax, yGrp
               add     eax, SizeT
               add     Srect.top, eax
               add     Savrect.top, eax
         .endif

         .if ComboOn
               mov     eax, CBrect.bottom
               mov     Srect.bottom, eax
               sub     Srect.bottom, 6
         .endif

         INVOKE     RedrawWindow, hwnd, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN

         .if hGrpOn
               and     hGrpOn, 0
            INVOKE     RedrawWindow, hGrp, 0, 0,\
                       RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN
         .endif

         .if CtrlType == 7526  ; Animate
               mov     ecx, -1
               shl     ecx, 16
               mov     ax, -1
               mov     cx, ax
               mov     Val, ecx
               and     Cnt, 0
               mov     ecx, AniCnt
            .while (ecx)
                  mov     edx, Cnt
               .if hAniArray+[edx*4]
                    push     ecx
                  INVOKE     SendMessage, hAniArray+[edx*4], ACM_PLAY, 20, Val
                     pop     ecx
               .endif
                  inc     Cnt
                  dec     ecx
            .endw
         .endif

            mov     ecx, Savrect.left
            mov     edx, Savrect.top
         .if ecx != Srect.left || edx != Srect.top
               mov     dis.itemID, 0
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
               add     ecx, CtrlsLeftOrg
               add     ecx, 16
               mov     byte ptr[ecx], 5      ; Change
         .endif

         .if BorderOn
            INVOKE     MoveGrabbers, 4, 0
         .else
            INVOKE     MoveGrabbers, 5, 0
         .endif
 MOVmd     hSMove, hwnd
 MOVmd     CtrlHnd, hwnd
 MOVmd     SavCtrl, CtrlType
INVOKE     SetFocus, hForm
            and     BorderOn, 0
            jmp     Ret0

      .elseif wmsg == WM_COMMAND
            mov     eax, wparam
           cwde

         .if eax == IDM_COPY
;---------- [Get offset in the structure array] ----------
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx

               mov     eax, ecx
               add     eax, CtrlsCntType
               mov     ebx, dword ptr[eax]
               and     ebx, 0000ffffh
            .if CtrlType == 7513 || CtrlType == 7514
                  xor     ebx, ebx
            .endif
               mov     CopyP.ID, ebx
               mov     eax, ecx
               add     eax, CtrlsLeft
             MOVmd     CopyP.Left, dword ptr[eax]
             MOVmd     CopyP.Top, dword ptr[eax+4]
             MOVmd     CopyP.Wth, dword ptr[eax+8]
             MOVmd     CopyP.Hgt, dword ptr[eax+12]

               lea     eax, Ctrls.ExStyle
               sub     eax, CtrlsStart
             MOVmd     CopyP.ExStyle, dword ptr[ecx+eax]
             MOVmd     Ctrls.ExStyle, dword ptr[ecx+eax]
               lea     eax, Ctrls.Style
               sub     eax, CtrlsStart
             MOVmd     CopyP.Style, dword ptr[ecx+eax]
             MOVmd     Ctrls.Style, dword ptr[ecx+eax]
               lea     eax, Ctrls.Class
               sub     eax, CtrlsStart
            INVOKE     lstrcpy, addr CopyP.Class, addr [ecx+eax] 
               and     PasteOn, 0

         .elseif eax == IDM_DEL
               and     hSMove, 0
               and     CtrlHnd, 0
               mov     dis.itemID, 1

;---------- [Get offset in the structure array] ----------
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx

               mov     eax, ecx
               add     eax, CtrlsCntType
               mov     ebx, dword ptr[eax]
               and     ebx, 0000ffffh
            .if ebx == 7513
                  and     ToolOn, 0
            .elseif ebx == 7514
                  and     StatusOn, 0
            .endif
               sub     ebx, 7501
               sub     CtrlCnt+[ebx*4], 1

            INVOKE     lstrcpy, addr szBuff, addr [ecx+edx*4] 
            INVOKE     SendMessage, hWndCombo, CB_FINDSTRINGEXACT, -1, addr szBuff
            INVOKE     SendMessage, hWndCombo, CB_DELETESTRING, eax, 0

            INVOKE     GetParent, hwnd
               mov     hParent, eax
               mov     hCtrl, eax
            INVOKE     DestroyWindow, hwnd
               dec     ArrayCnt

;---------- [Shift handle left if close] ----------
               xor     eax, eax
               mov     ecx, ArrayCnt
               inc     ecx
            .while (ecx)               ; Find handle of active control in the array
                  mov     edx, hwnd
               .if hArray[eax+4] == edx
                   MOVmd     hArray[eax], hArray[eax+8]
                   MOVmd     hArray[eax+4], hArray[eax+12]
                     add     eax, 8
                     dec     ecx
                  .while (ecx)         ; Shift the array to the left
                      MOVmd     hArray[eax], hArray[eax+8]
                      MOVmd     hArray[eax+4], hArray[eax+12]
                        add     eax, 8
                        dec     ecx
                  .endw
                     .break  
               .endif
                  add     eax, 8
                  dec     ecx
            .endw

               mov     eax, hParent
            .if eax == hForm
                  mov     CtrlType, 7501
            .else
               INVOKE     GetParent, eax  ; Get the parent of the Groupbox
                  mov     hParent, eax
                  mov     CtrlType, 7503
               INVOKE     RedrawWindow, hParent, 0, 0,\
                          RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN
            .endif

              push     hParent
            INVOKE     FormProc, hParent, WM_LBUTTONDOWN, 0, 0
               pop     hParent
            INVOKE     FormProc, hParent, WM_LBUTTONUP, 0, 0
         .endif
         jmp     Ret0

      .elseif wmsg == WM_LBUTTONDBLCLK
            mov     eax, 1
            ret
      .endif
         jmp     Ret0

PopUp:
      INVOKE     GetWindowRect, hwnd, addr Crect
         mov     ecx, lparam        ; x/y pos of cursor
         mov     ebx, ecx
         and     ebx, 0000ffffh     ; ebx = LOWORD(lparam) = x pos
         shr     ecx, 16            ; ecx = HIWORD(lparam) = y pos
         add     ebx, Crect.left
         add     ecx, Crect.top
         add     ebx, 0 ;6 
         add     ecx, 0 ;10
      INVOKE     TrackPopupMenu, hRMenu, TPM_LEFTALIGN or TPM_LEFTBUTTON,\
                 ebx, ecx, 0, hwnd, addr Crect
       MOVmd     hCtrl, hwnd

Ret0:
         xor     eax, eax
         ret
MouseMUD ENDP

;=====================================================
; Multiple selectPROCEDURE
;=====================================================
MultiProc PROC  uses ebx edi  hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_PAINT
         INVOKE     MoveWindow, hSizeL, 0, 0, 0, 0, TRUE
         INVOKE     MoveWindow, hSizeT, 0, 0, 0, 0, TRUE
         INVOKE     MoveWindow, hSizeR, 0, 0, 0, 0, TRUE
         INVOKE     MoveWindow, hSizeB, 0, 0, 0, 0, TRUE
            jmp     DefWin

      .else
DefWin:

         INVOKE     DefWindowProc, hwnd, wmsg, wparam, lparam
            ret
      .endif

Ret0:
         xor     eax, eax
         ret

MultiProc  ENDP

;=====================================================
; Size PROCEDURE
;=====================================================
SizeProc PROC  uses ebx edi  hwnd:DWORD, wmsg, wparam, lparam
LOCAL    pt:POINT
LOCAL    Crect:RECT
LOCAL    LockR:DWORD, LockB, SavGrp
LOCAL    szBuff[512]:BYTE

; For CtrlType 7503 hCtrl = Groupbox

      .if wmsg == WM_LBUTTONDBLCLK
            mov     wmsg, WM_LBUTTONDOWN
      .endif

      .if wmsg == WM_LBUTTONDOWN
.if ParentOn && !CtrlHnd || CtrlType == 7526
      jmp     Ret0

.elseif ParentOn && CtrlHnd ;&& CtrlType != 7501 && CtrlType != 7503
      and     ParentOn, 0
    MOVmd     hCtrl, CtrlHnd
    MOVmd     CtrlType, SavCtrl
.endif

         and     hGrpOn, 0
      INVOKE     GetParent, hCtrl
         mov     edx, eax
         xor     eax, eax
         mov     ecx, GrpCnt ;32
      .while (ecx)     ; Find handle of Groupbox or Groupbox control parent in the array
         .if !edx
            .break
         .endif
         .if hGrpArray[eax+4] == edx
               mov     hGrpOn, 1
             MOVmd     hGrp, hGrpArray[eax]
             MOVmd     hParent, hGrpArray[eax]
             MOVmd     SavGrp, hGrpArray[eax+4]
            .break
         .elseif hGrpArray[eax] == edx
             MOVmd     hCtrl, hGrpArray[eax]
            .break
         .endif
            add     eax, 8
            dec     ecx
      .endw

;DSPValue hWnd, hGrpOn, 1, 't'
         INVOKE     SetCapture, hwnd
         INVOKE     GetParent, hCtrl
         .if !hGrpOn
               mov     hParent, eax
;DSPValue hWnd, 1111, 1, 't'
         .endif
            and     PosX, 0
            and     PosY, 0
            and     ComboOn, 0
         INVOKE     GetWindowRect, hParent, addr Prect
         INVOKE     GetWindowRect, hCtrl, addr Srect
         INVOKE     GetWindowRect, hCtrl, addr Savrect

            mov     eax, SizeB
            sub     Prect.left, eax
            sub     Prect.right, eax
            mov     eax, SizeT
            sub     Prect.top, eax

;---------- [Get the right & bottom boundries of the parent window] ----------
            mov     eax, Prect.right
            mov     ParR, eax
            mov     eax, Prect.bottom
            mov     ParB, eax

            mov     eax, hParent
         .if eax == hForm
               sub     ParR, 3 ;6
               sub     ParB, 3 ;22
         .endif

            xor     eax, eax
            mov     ecx, ArrayCnt ;2048 ;1024 ;512 ;64
inc     ecx
         .while (ecx)                  ; Find handle of active control in the array
               mov     edx, hCtrl
            .if hArray[eax+4] == edx
                  mov     ebx, hArray[eax]
                  and     ebx, 0ffffh
                  mov     CtrlType, ebx
               .if CtrlType == 7509  ; Combobox
                     mov     ComboOn, 1
                  INVOKE     SendMessage, hCtrl, CB_GETDROPPEDCONTROLRECT, 0, addr CBrect
                     mov     eax, CBrect.left
                     sub     CBrect.right, eax
                     mov     eax, CBrect.top
                     sub     CBrect.bottom, eax
               .endif
               .break  
            .endif
               add     eax, 8
               dec     ecx
         .endw

            and     BorderOn, 0

         .if hGrpOn
            INVOKE     GetWindowLong, SavGrp, GWL_STYLE
            .if (eax & WS_BORDER)
                  mov     BorderOn, 1
            .endif

            INVOKE     GetWindowRect, hForm, addr Crect
               mov     eax, Prect.left
               sub     eax, Crect.left
               sub     eax, SizeB
               mov     xGrp, eax
               mov     eax, Prect.top
               sub     eax, Crect.top
               sub     eax, SizeT
               mov     yGrp, eax
         .endif

         .if hParent
;DSPValue hWndStat, 2222, 1, 's'
            INVOKE     ControlRect, addr Srect, 0, 0
         .else
;DSPValue hWndStat, 3333, 1, 's'
            INVOKE     ControlRect, addr Srect, 0, 1
         .endif
         .if !hSizeData
            INVOKE     CreateDialogParam, hInst, 4902, hWnd, offset SizeDataProc, 0
         .endif

      .elseif wmsg == WM_MOUSEMOVE
.if CtrlType == 7526  ; Animate
      jmp     Ret0
.endif

.if ParentOn
         .if hSizeData
            INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
               and     hSizeData, 0
         .endif
      jmp     Ret0
.endif

         .if wparam == MK_LBUTTON ;&& Test4 == 8888
            .if hParent
               INVOKE     GetWindowRect, hParent, addr Prect
            .else
               INVOKE     GetWindowRect, hWnd, addr Prect
                  and     Prect.left, 0
                  and     Prect.top, 0
                  and     Prect.right, 0
                  and     Prect.bottom, 0
            .endif

            .if !ComboOn
               INVOKE     GetWindowRect, hCtrl, addr Srect
            .else
               INVOKE     SendMessage, hCtrl, CB_GETDROPPEDCONTROLRECT, 0, addr Srect
                  add     Srect.bottom, 6
            .endif

             MOVmd     LockR, Srect.right
             MOVmd     LockB, Srect.bottom
               mov     eax, hParent

            .if eax == hForm
                  mov     eax, SizeB
                  mov     ecx, SizeT
                  add     Prect.left, eax
                  sub     Prect.right, eax
                  add     Prect.top, ecx
                  sub     Prect.bottom, ecx

            .elseif eax == hGrp
               .if BorderOn
                     inc     Prect.left
                     inc     Prect.top
               .endif
            .else
                  inc     Prect.left
                  inc     Prect.top
            .endif

               mov     eax, Srect.left
               sub     Srect.right, eax
               mov     eax, Srect.top
               sub     Srect.bottom, eax

            INVOKE     GetCursorPos, addr pt
            INVOKE     ScreenToClient, hCtrl, addr pt
               mov     eax, pt.x
               sub     eax, Srect.left
               mov     ebx, pt.y
               sub     ebx, Srect.top

.if NoMoveOn
      xor     eax, eax
      xor     ebx, ebx
.endif

            .if !PosX && !PosY
                  mov     PosX, eax
                  mov     PosY, ebx
            .endif
               sub     eax, PosX
               sub     ebx, PosY
               mov     ecx, hwnd

            .if ecx == hSizeL
                  add     Srect.left, eax
                  mov     eax, LockR
                  sub     eax, Srect.left
                  add     eax, Srect.left
                  mov     Srect.right, eax
                  sub     eax, 5
               .if eax < Srect.left
                     mov     Srect.left, eax
               .endif
                  mov     eax, Srect.top
                  add     Srect.bottom, eax

            .elseif ecx == hSizeR
                  add     eax, Srect.left
                  add     Srect.right, eax
                  mov     eax, Srect.left
                  add     eax, 5
               .if eax > Srect.right
                     mov     Srect.right, eax
               .endif
                  mov     eax, Srect.top
                  add     Srect.bottom, eax

            .elseif ecx == hSizeT
                  add     Srect.top, ebx
                  mov     eax, LockB
                  sub     eax, Srect.top
                  add     eax, Srect.top
                  mov     Srect.bottom, eax
                  sub     eax, 5
               .if eax < Srect.top
                     mov     Srect.top, eax
               .endif
                  mov     eax, Srect.left
                  add     Srect.right, eax

            .elseif ecx == hSizeB
                  add     ebx, Srect.top
                  add     Srect.bottom, ebx
                  mov     eax, Srect.top
                  add     eax, 5
               .if eax > Srect.bottom
                     mov     Srect.bottom, eax
               .endif
                  mov     eax, Srect.left
                  add     Srect.right, eax
            .else
                  jmp     Ret0
            .endif

            .if !hSizeData
               INVOKE     CreateDialogParam, hInst, 4902, hWnd, offset SizeDataProc, 0
            .endif

            .if hParent
;---------- [Keep the controls within the parent boundries] ----------
                  mov     ecx, ParR
                  mov     edx, ParB

                  mov     eax, Prect.left
                  mov     ebx, hParent
               .if ebx == hGrp
                     add     eax, 3
               .endif
               .if Srect.left < eax
                     mov     Srect.left, eax
               .endif

                  mov     eax, Prect.top
                  mov     ebx, hParent
               .if ebx == hGrp
                     add     eax, 8
               .endif
               .if Srect.top < eax
                     mov     Srect.top, eax
               .endif

                  mov     ebx, hParent
               .if ebx == hGrp
                     sub     ecx, 3
               .endif
               .if Srect.right > ecx
                     mov     Srect.right, ecx
               .endif

                  mov     ebx, hParent
               .if ebx == hGrp
                     sub     edx, 3
               .endif
               .if Srect.bottom > edx && CtrlType != 7509
                     mov     Srect.bottom, edx
               .endif

               .if SnapOn
                     mov     eax, hwnd
                  .if eax == hSizeL
                        xor     edx, edx
                        mov     eax, Srect.left
                        mov     ecx, Prect.left
                        sub     eax, ecx
                        mov     ebx, Grid
                       idiv     ebx
                       imul     eax, Grid
                        mov     ebx, Srect.left
                        add     eax, ecx
                     .if eax < ecx
                           mov     eax, ecx
                     .endif
                        mov     Srect.left, eax

                  .elseif eax == hSizeT
                        xor     edx, edx
                        mov     eax, Srect.top
                        mov     ecx, Prect.top
                        sub     eax, ecx
                        mov     ebx, Grid
                       idiv     ebx
                       imul     eax, Grid
                        mov     ebx, Srect.top
                        add     eax, ecx
                     .if eax < ecx
                           mov     eax, ecx
                     .endif
                        mov     Srect.top, eax

;                  .elseif eax == hSizeR
;                        xor     edx, edx
;                        mov     eax, Srect.right
;                        mov     ebx, Grid
;                       idiv     ebx
;                       imul     eax, Grid
;                        mov     Srect.right, eax

;                  .elseif eax == hSizeB
;                        xor     edx, edx
;                        mov     eax, Srect.bottom
;                        mov     ebx, Grid
;                       idiv     ebx
;                       imul     eax, Grid
;                        mov     Srect.bottom, eax
                  .endif
               .endif

               .if CtrlType != 7513 && CtrlType != 7514 && CtrlType != 7526
                  INVOKE     ControlRect, addr Srect, 1, 0
               .endif

            .else

;---------- [Form window] ----------
               INVOKE     GetWindowRect, hWork, addr Prect
               INVOKE     GetWindowRect, hCtrl, addr Crect

;---------- [Keep the form window within the work area] ----------
                  mov     ecx, Prect.left
                  mov     edx, Prect.top
               .if ecx > Srect.left
                     mov     Srect.left, ecx
               .endif
               .if edx > Srect.top
                     mov     Srect.top, edx
               .endif
                  mov     ecx, Prect.right
                  mov     edx, Prect.bottom
               .if ecx < Srect.right
;                     mov     Srect.right, ecx
               .endif
               .if edx < Srect.bottom
;                     mov     Srect.bottom, edx
               .endif

               INVOKE     ControlRect, addr Srect, 1, 1
            .endif

               mov     eax, Srect.left
               sub     Srect.right, eax
               mov     eax, Srect.top
               sub     Srect.bottom, eax
            .if CtrlType == 7513
                  add     Srect.right, 5
                  mov     Srect.bottom, 28
            .endif

            INVOKE     PosProc, hCtrl, Srect.right, Srect.bottom, 12
            .if CtrlType == 7513
                  sub     Srect.right, 5
            .endif
         .endif

      .elseif wmsg == WM_LBUTTONUP
.if CtrlType == 7526  ; Animate
   INVOKE     ReleaseCapture
      jmp     Ret0
.endif
.if ParentOn
;and     ParentOn, 0
      jmp     Ret0
.endif
;DSPValue hWnd, 1234, 1, 't'

         .if hParent
            INVOKE     ControlRect, addr Srect, 2, 0
         .else
            INVOKE     ControlRect, addr Srect, 2, 1
         .endif
            INVOKE     ReleaseCapture
         .if hSizeData
            INVOKE     SizeDataProc, hSizeData, WM_COMMAND, IDCANCEL, 0
               and     hSizeData, 0
         .endif
         .if ComboOn
               sub     Srect.bottom, 6
         .endif

         .if hParent
               mov     eax, Prect.left
               sub     Srect.left, eax
               mov     eax, Prect.top
               sub     Srect.top, eax
         .endif
         INVOKE     MoveWindow, hCtrl, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE

         .if CtrlType == 7503
               xor     eax, eax
               mov     edx, hGrp
               mov     ecx, GrpCnt ;32
            .while (ecx)     ; Find handle of Groupbox parent in the array
               .if hGrpArray[eax] == edx
                     mov     ecx, hGrpArray[eax+4]
 ;                    mov     hCtrl, ecx
                  .break  
               .endif
                  add     eax, 8
                  dec     ecx
            .endw

            INVOKE     MoveWindow, ecx, 0, 0, Srect.right, Srect.bottom, TRUE ;hCtrl
              push     hGrpOn
              call     ChkChildren
               pop     hGrpOn
         .endif

         .if hGrpOn
               mov     eax, xGrp
               add     eax, SizeB
               add     Srect.left, eax
               mov     eax, yGrp
               add     eax, SizeT
               add     Srect.top, eax
         .endif

         .if ComboOn
;               add     Srect.bottom, 6
         .endif

         .if hParent
            .if CtrlType == 7523 && !hGrpOn || CtrlType == 7524 && !hGrpOn || CtrlType == 7525 && !hGrpOn
               INVOKE     RedrawWindow, hCtrl, 0, 0,\
                          RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW ;or RDW_ALLCHILDREN
            .endif

            .if hGrpOn
                  and     hGrpOn, 0
               INVOKE     RedrawWindow, hGrp, 0, 0,\
                          RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN
            .endif

            .if CtrlType == 7513 || CtrlType == 7514 || CtrlType == 7526
                  jmp     Ret0
            .endif

            .if BorderOn
               INVOKE     MoveGrabbers, 4, 0
            .else
               INVOKE     MoveGrabbers, 5, 0
            .endif
               and     BorderOn, 0
.if CtrlType == 7527
   INVOKE     ReloadCtrl, 0
.endif
               mov     eax, Savrect.right
               sub     eax, Savrect.left
               mov     ebx, Savrect.bottom
               sub     ebx, Savrect.top
            .if eax != Srect.right || ebx != Srect.bottom
                  mov     dis.itemID, 0
               INVOKE     GetOffset, 0
                  mov     StrSize, eax
                 imul     ebx, StrSize
                  add     ecx, ebx
                  add     ecx, CtrlsLeftOrg
                  add     ecx, 16
                  mov     byte ptr[ecx], 4
            .endif

;            .if CtrlType == 7502
;                  mov     dis.itemID, 3 ;2^^^^^^^^^^^^
;;---------- [Get offset in the structure array] ----------
;               INVOKE     GetOffset, 0
;                  mov     StrSize, eax
;                 imul     ebx, StrSize
;                  add     ecx, ebx
;               INVOKE     lstrcpy, addr szBuff, addr [ecx+edx*4]
;               INVOKE     ReloadCtrl, addr szBuff
;               INVOKE     BringWindowToTop, hCtrl
;            .endif

         .else
            INVOKE     GetClientRect, hCtrl, addr Srect
            INVOKE     MoveGrabbers, 2, 0
         .endif

      .else
         INVOKE     DefWindowProc, hwnd, wmsg, wparam, lparam
            ret
      .endif

Ret0:
         xor     eax, eax
         ret

SizeProc  ENDP

;=====================================================
; SnapTo PROCEDURE
;=====================================================
SnapTo PROC  uses ebx

         xor     edx, edx
         mov     eax, Srect.left
         mov     ecx, Prect.left
         add     ecx, SizeB
         sub     eax, ecx
         mov     ebx, Grid
        idiv     ebx
        imul     eax, Grid
         mov     ebx, Srect.left
         add     eax, ecx
      .if eax < ecx
            mov     eax, ecx
      .endif
         mov     Srect.left, eax
         sub     ebx, eax
         sub     Srect.right, ebx

         xor     edx, edx
         mov     eax, Srect.top
         mov     ecx, Prect.top
         add     ecx, SizeT
         sub     eax, ecx
         mov     ebx, Grid
        idiv     ebx
        imul     eax, Grid
         mov     ebx, Srect.top
         add     eax, ecx
      .if eax < ecx
            mov     eax, ecx
      .endif
         mov     Srect.top, eax
         sub     ebx, eax
         sub     Srect.bottom, ebx
         ret

SnapTo  ENDP

;=====================================================
; Capture the drawing areas DC's PROCEDURE
;=====================================================
CaptureDC PROC hwnd:DWORD, SizeF, hWndDC, hWndMemDC, hWndBmp, hScrWndDC, hWndRgn, hOldWndRgn
LOCAL    Drect:RECT
LOCAL    hTempDC:DWORD, hTempMemDC, hTempBmp, hScrTempDC, hTempRgn
LOCAL    Hgt:DWORD, Wth

      .if !hFormMemDC && !SizeF || !hWorkMemDC && SizeF
         INVOKE     GetWindowRect, hwnd, addr Drect
            mov     eax, Drect.right
            sub     eax, Drect.left
            mov     Wth, eax
            mov     eax, Drect.bottom
            sub     eax, Drect.top
            mov     Hgt, eax
         INVOKE     GetWindowDC, hwnd
            mov     hTempDC, eax                       ; A complete window DC
            mov     ecx, hWndDC
            mov     [ecx], eax
         INVOKE     CreateCompatibleDC, hTempDC
            mov     hTempMemDC, eax                    ; A compatible memory DC for the window DC
            mov     ecx, hWndMemDC
            mov     [ecx], eax
         INVOKE     CreateCompatibleBitmap, hTempDC, Wth, Hgt
            mov     hTempBmp, eax                      ; A compatible bitmap for the window DC
            mov     ecx, hWndBmp
            mov     [ecx], eax
         INVOKE     SelectObject, hTempMemDC, hTempBmp ; Select the bitmap into the window DC
         INVOKE     BitBlt, hTempMemDC, 0, 0, Wth, Hgt, hTempDC, 0, 0, SRCCOPY
         INVOKE     GetDC, 0
            mov     hScrTempDC, eax                    ; A DC for the entire screen
            mov     ecx, hScrWndDC
            mov     [ecx], eax
         INVOKE     CreateRectRgn, Drect.left, Drect.top, Drect.right, Drect.bottom
            mov     hTempRgn, eax                      ; A region for the rectangle
            mov     ecx, hWndRgn
            mov     [ecx], eax
         INVOKE     SelectObject, hScrTempDC, hTempRgn ; Select the rectangle rgn into the screen DC
            mov     ecx, hOldWndRgn                    ; Save the previous region
            mov     [ecx], eax
         INVOKE     ReleaseDC, hwnd, hTempDC
      .endif
         ret

CaptureDC ENDP

;=====================================================
; Paint the DC area PROCEDURE
;=====================================================
PaintDC PROC hwnd:DWORD, SizeF
LOCAL    Drect:RECT

      .if hFormMemDC && !SizeF || hWorkMemDC && SizeF
         INVOKE     GetWindowDC, hwnd
            mov     hDC, eax
         INVOKE     GetWindowRect, hwnd, addr Drect
            mov     eax, Drect.left
            sub     Drect.right, eax
            mov     eax, Drect.top
            sub     Drect.bottom, eax
            mov     ecx, hFormMemDC
         .if SizeF
               mov     ecx, hWorkMemDC
         .endif
         INVOKE     BitBlt, hDC, 0, 0, Drect.right, Drect.bottom, ecx, 0, 0, SRCCOPY
         INVOKE     ReleaseDC, hwnd, hDC
      .endif
         ret

PaintDC ENDP

;=====================================================
; Destroy the DC's PROCEDURE
;=====================================================
DestroyDC PROC SizeF:DWORD

      .if hFormMemDC && !SizeF
         INVOKE     DeleteDC, hFormDC
         INVOKE     DeleteDC, hFormMemDC
         INVOKE     DeleteObject, hFormBmp
         INVOKE     SelectObject, hScrFormDC, hOldFormRgn
         INVOKE     DeleteObject, hFormRgn
         INVOKE     ReleaseDC, 0, hScrFormDC
            mov     hFormMemDC, 0

      .elseif hWorkMemDC && SizeF
         INVOKE     DeleteDC, hWorkDC
         INVOKE     DeleteDC, hWorkMemDC
         INVOKE     DeleteObject, hWorkBmp
         INVOKE     SelectObject, hScrWorkDC, hOldWorkRgn
         INVOKE     DeleteObject, hWorkRgn
         INVOKE     ReleaseDC, 0, hScrWorkDC
            mov     hWorkMemDC, 0
      .endif
         ret

DestroyDC ENDP

;=====================================================
; Draw the control rectangle PROCEDURE
;=====================================================
ControlRect PROC Drect:DWORD, Oper, SizeF

      .if Oper == 0
         INVOKE     CaptureDC, hForm, 0, addr hFormDC, addr hFormMemDC,\
                    addr hFormBmp, addr hScrFormDC, addr hFormRgn, addr hOldFormRgn
         .if !SizeF        ; SizeF = sizing Form
            INVOKE     FrameRect, hScrFormDC, Drect, hBlackBR
         .else
            INVOKE     CaptureDC, hWork, SizeF, addr hWorkDC, addr hWorkMemDC,\
                       addr hWorkBmp, addr hScrWorkDC, addr hWorkRgn, addr hOldWorkRgn
            INVOKE     FrameRect, hScrWorkDC, Drect, hBlackBR
         .endif
      .elseif Oper == 1
         INVOKE     PaintDC, hForm, 0
         .if !SizeF
            INVOKE     FrameRect, hScrFormDC, Drect, hBlackBR
         .else
            INVOKE     PaintDC, hWork, SizeF
            INVOKE     FrameRect, hScrWorkDC, Drect, hBlackBR
         .endif
      .elseif Oper == 2
         INVOKE     PaintDC, hForm, 0
         INVOKE     DestroyDC, 0
         .if !SizeF
         .else
            INVOKE     PaintDC, hWork, SizeF
            INVOKE     DestroyDC, SizeF
         .endif
      .endif
         ret

ControlRect ENDP

End DllEntry
