   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  L:\AsmEdit\include\DSPMACRO.asm

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

WinMain         PROTO  :DWORD, :DWORD, :DWORD, :DWORD
TabCtlDlg       PROTO  :DWORD, :DWORD, :DWORD, :DWORD
ControlDlg      PROTO  :DWORD, :DWORD, :DWORD, :DWORD
BuildDlg        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
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
RealTimeCtrl    PROTO  :DWORD
ReadInput       PROTO  :DWORD, :DWORD
LoadListS       PROTO  :DWORD, :DWORD, :DWORD, :DWORD
GetStyles       PROTO  :DWORD, :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  'Control Builder',0
ClassName      db  'Control Builder',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

;SysAnimate32
;ACS_AUTOPLAY
;ACS_CENTER
;ACS_TIMER
;ACS_TRANSPARENT

MainClass      db  'Main 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

ClassArray     dd  MainClass,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

szClass01      db  'MainClass',0
szClass02      db  'StaticClass',0
szClass03      db  'ButtClass',0
szClass04      db  'EditClass',0
szClass05      db  'RichEdit',0
szClass06      db  'ComboClass',0
szClass07      db  'ListboxClass',0
szClass08      db  'TreeVClass',0   
szClass09      db  'ListVClass',0
szClass10      db  'ToolClass',0
szClass11      db  'StatisClass',0
szClass12      db  'ScrollHClass',0
szClass13      db  'ScrollVClass',0
szClass14      db  'ProgressClass',0
szClass15      db  'TrackbarClass',0
szClass16      db  'UpDownClass',0
szClass17      db  'TabCtrlClass',0
szClass18      db  'SysMonthClass',0
szClass19      db  'SysPickClass',0
szClass20      db  'BitmapClass',0
szClass21      db  'IconClass',0
szClass22      db  'IconAniClass',0
szClass23      db  'AnimateClass',0
szClass24      db  'IPAddressClass',0
szClass25      db  'HotKeyClass',0
szClass26      db  'CustomClass',0

szClassArray   dd  szClass01,szClass02,szClass03,szClass03,szClass03,szClass03,szClass04,
                   szClass05,szClass06,szClass07,szClass08,szClass09,szClass10,szClass11,
                   szClass12,szClass13,szClass14,szClass15,szClass16,szClass17,szClass18,
                   szClass19,szClass20,szClass21,szClass22,szClass23,szClass24,szClass25,
                   szClass26

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
szStylesF      db  '\Res\Styles.sty',0
szStylesS      db  'Styles.sty',0
szGlobe        db  'globe.ani',0
szAnimateAvi   db  'globe.avi',0

szRedit        db  'CtrlBuild',0
szREGSZ        db  'REG_SZ',0
szMaiD         db  'DefMai',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
szTbrD         db  'DefTbr',0
szStsD         db  'DefSts',0
szScHD         db  'DefScH',0
szScVD         db  'DefScV',0
szPrgD         db  'DefPrg',0
szTraD         db  'DefTra',0
szUpDD         db  'DefUpD',0
szTabD         db  'DefTab',0
szSyMD         db  'DefSyM',0
szSyPD         db  'DefSyP',0
szBmpD         db  'DefBmp',0
szIcoD         db  'DefIco',0
szAIcD         db  'DefAIc',0
szAniD         db  'DefAni',0
szIPAD         db  'DefIPA',0
szHotD         db  'DefHot',0
szCusD         db  'DefCus',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  'The Styles.sty file is missing or is',0dh,0ah
               db  ' corrupted',0
szError3       db  'The MAXIMUM number of controls has been reached',0
szError4       db  'The Templates folder is missing or is',0dh,0ah
               db  ' corrupted',0

fmat1          db  '%01u',0
fmat2          db  '%02u',0

;---------- [The first 4 are for EXStyles, last 12 are for Styles] ----------
ddMai          dd  0,0,0,0,5,21,0,0,0,0,0,0,0,0,0,0
ddSta          dd  0,0,0,0,2,3,5,35,0,0,0,0,0,0,0,0
ddGrp          dd  0,0,0,0,2,3,5,14,0,0,0,0,0,0,0,0
ddRad          dd  0,0,0,0,2,3,5,11,15,0,0,0,0,0,0,0
ddChk          dd  0,0,0,0,2,3,5,11,15,0,0,0,0,0,0,0
ddBut          dd  0,0,0,0,2,3,5,11,0,0,0,0,0,0,0,0
ddEdi          dd  9,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddRed          dd  8,0,0,0,2,3,5,8,9,17,21,22,23,30,0,0
ddCob          dd  0,0,0,0,2,3,5,8,16,22,23,0,0,0,0,0
ddLib          dd  9,0,0,0,2,3,5,8,15,20,22,0,0,0,0,0
ddTrv          dd  9,0,0,0,2,3,5,14,15,16,29,0,0,0,0,0
ddLiv          dd  9,0,0,0,2,3,5,15,20,21,23,0,0,0,0,0
ddTbr          dd  0,0,0,0,2,3,5,7,19,29,0,0,0,0,0,0
ddSts          dd  0,0,0,0,2,3,5,14,0,0,0,0,0,0,0,0
ddScH          dd  0,0,0,0,2,3,5,14,0,0,0,0,0,0,0,0
ddScV          dd  0,0,0,0,2,3,5,15,0,0,0,0,0,0,0,0
ddPrg          dd  0,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddTra          dd  0,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddUpD          dd  0,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddTab          dd  0,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddSyM          dd  0,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddSyP          dd  0,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddBmp          dd  0,0,0,0,2,3,5,28,35,0,0,0,0,0,0,0
ddIco          dd  0,0,0,0,2,3,5,17,35,0,0,0,0,0,0,0
ddAIc          dd  0,0,0,0,2,3,5,17,35,0,0,0,0,0,0,0
ddAni          dd  0,0,0,0,2,3,5,14,15,17,0,0,0,0,0,0
ddIDA          dd  8,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddHot          dd  9,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0
ddCus          dd  0,0,0,0,2,3,5,0,0,0,0,0,0,0,0,0

ddMaiD         dd  16    dup(?)
ddStaD         dd  16    dup(?)
ddGrpD         dd  16    dup(?)
ddRadD         dd  16    dup(?)
ddChkD         dd  16    dup(?)
ddButD         dd  16    dup(?)
ddEdiD         dd  16    dup(?)
ddRedD         dd  16    dup(?)
ddCobD         dd  16    dup(?)
ddLibD         dd  16    dup(?)
ddTrvD         dd  16    dup(?)
ddLivD         dd  16    dup(?)
ddTbrD         dd  16    dup(?)
ddStsD         dd  16    dup(?)
ddScHD         dd  16    dup(?)
ddScVD         dd  16    dup(?)
ddPrgD         dd  16    dup(?)
ddTraD         dd  16    dup(?)
ddUpDD         dd  16    dup(?)
ddTabD         dd  16    dup(?)
ddSyMD         dd  16    dup(?)
ddSyPD         dd  16    dup(?)
ddBmpD         dd  16    dup(?)
ddIcoD         dd  16    dup(?)
ddAIcD         dd  16    dup(?)
ddAniD         dd  16    dup(?)
ddIDAD         dd  16    dup(?)
ddHotD         dd  16    dup(?)
ddCusD         dd  16    dup(?)

szOpenTitle    db  'Open A Resource File',0
szSaveTitle    db  'Save File As',0
szFilter       db  'TXT Files',0,'*.txt',0,0
szTxt          db  'xxxx.txt',0

szMainh        db  'hWnd',0
szStah         db  'hStat',0
szGrph         db  'hGroup',0
szRadh         db  'hRadio',0
szChkh         db  'hCheck',0
szButh         db  'hButt',0
szEdith        db  'hEdit',0
szREdith       db  'hREdit',0
szComboh       db  'hCombobox',0
szListBh       db  'hListbox',0
szTreeVh       db  'hTreeview',0
szListVh       db  'hListview',0
szToolh        db  'hToolbar',0
szStatush      db  'hStatus',0
szScrollHh     db  'hScrollH',0
szScrollVh     db  'hScrollV',0
szProgressh    db  'hProgressbar',0
szTrackh       db  'hTrackbar',0
szUpDownh      db  'hUpDown',0
szTabh         db  'hTab',0
szMonthh       db  'hMonth',0
szPickh        db  'hDatePick',0
szBitmaph      db  'hBitmap',0
szIconh        db  'hIcon',0
szIconAnih     db  'hIconAni',0
szAnimateh     db  'hAnimate',0
szIPAddressh   db  'hIPAddress',0
szHotkeyh      db  'hHotkey',0
szCustomh      db  'hCustom',0

HandArray      dd  szMainh,szStah,szGrph,szRadh,szChkh,szButh,szEdith,szREdith,
                   szComboh,szListBh,szTreeVh,szListVh,szToolh,szStatush,szScrollHh,
                   szScrollVh,szProgressh,szTrackh,szUpDownh,szTabh,szMonthh,szPickh,
                   szBitmaph,szIconh,szIconAnih,szAnimateh,szIPAddressh,szHotkeyh,szCustomh

szMain         db  'Main Window',0 ; 7501
szSta          db  'Static',0      ; 7502 static
szGrp          db  'Group',0       ; 7503 button
szRad          db  'Radio',0       ; 7504 button
szChk          db  'Check',0       ; 7505 button
szBut          db  'Butt',0        ; 7506 button
szEdit         db  'Edit',0        ; 7507 edit
szREdit        db  'REdit',0       ; 7508 RichEdit20A
szCombo        db  'Combobox',0    ; 7509 combobox
szListB        db  'Listbox',0     ; 7510 listbox
szTreeV        db  'Treeview',0    ; 7511 SysTreeView32
szListV        db  'Listview',0    ; 7512 SysListView32
szTool         db  'Toolbar',0
szStatus       db  'Statusbar',0
szScrollH      db  'ScrollbarH',0
szScrollV      db  'ScrollbarV',0
szProgress     db  'Progressbar',0 ;
szTrack        db  'Trackbar',0
szUpDown       db  'UpDoun',0
szTab          db  'Tab',0
szMonth        db  'MonthDate',0
szPick         db  'DatePick',0
szBitmap       db  'Bitmap',0
szIcon         db  'Icon',0
szIconAni      db  'IconAni',0
szAnimate      db  'Animate',0
szIPAdress     db  'IPAdress',0
szHotKey       db  'HotKey',0
szCustom       db  'Custom',0
szGrp4         db  'WC_GRP4',0

TextArray      dd  szMain,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

szMoveGrp      db  'Move the groupbox',0
szKeepSel      db  'Keep toolbar selection',0
szSingle       db  'NO Main Window',0
szNoMove       db  'Lock position - size',0
szOption       db  'Options',0
szAlign        db  'Align/Size',0
szReal         db  'Real Mode Ctrl',0
szRestore      db  'Restore Ctrl',0
szUpStyle      db  'Update Styles',0
szCancel       db  'Close Styles List',0

TabTitle1      db  'Controls',0
TabTitle2      db  'Build',0
Parent1        db  'Parent1',0
Child1         db  'Child1',0
Child2         db  'Child2',0
Child3         db  'Child3',0
szColName      db  'Filename',0

szCRLF         db  0dh,0ah,0
szCR           db  0dh,0
szNULL         db  0
szSpace        db  ' ',0
szQuote        db  '"',0
szComma        db  ',',0
szUnder        db  '_',0
szAstr         db  '*',0
szSlashB       db  '\',0
szBackS        db  '\Res\',0
szCS           db  ', ',0
szOR           db  ' or ',0
szEndP         db  '*.*',0
szEndR         db  '\*.rc',0
szClearM       db  '                 ',0
szClear        db  '                    ',0
szALL          db  'All Files',0,'*.*',0,0

szAppName      db  'AppName',0
szTextC        db  'szText',0
szNULLText     db  'NULL',0
szParent       db  'hwnd',0
szdd           db  ' dd  ?',0
szdb           db  " db  '",0
szdbEnd        db  "',0",0

szTemplatesC   db  '\Templates\Controls\',0
szWinCenter    db  'WinCenter.gen',0
szWinShow      db  'WinShow.gen',0
szCreateFont   db  'CreateFont.gen',0
szEditSubClass db  'REditSubClass.gen',0
szREditProc    db  'REditProc.gen',0
szCombobox1    db  'Combobox1.gen',0
szListbox1     db  'Listbox1.gen',0
szTreeview1    db  'Treeview1.gen',0
szListview1    db  'Listview1.gen',0
szProgress1    db  'Progess1.gen',0

szSupportA01   db  "FontName       db  'MS Sans Serif',0",0dh,0ah,0dh,0ah,0
szSupportT01   db  "Parent1        db  'Parent1',0",0dh,0ah
               db  "Child1         db  'Child1',0",0dh,0ah
               db  "Child2         db  'Child2',0",0dh,0ah
               db  "Child3         db  'Child3',0",0dh,0ah,0

szSupportL01   db  "szColName      db  'Filename',0",0dh,0ah,0dh,0ah,0
szSupportF01   db  "szSlashB       db  '\',0",0dh,0ah
               db  "szAll          db  '*.*',0",0dh,0ah,0

szSupportA02   db  'hFontL         dd  ?',0dh,0ah,0
szSupportT02   db  'hImageList     dd  ?',0dh,0ah,0
szSupportE01   db  'lpRichEdit     dd  ?',0dh,0ah,0
szSupportF02   db  'hFind          dd  ?',0dh,0ah,0
szSupportL02   db  'Row            dd  ?',0dh,0ah,0
szSupportF03   db  'szBuff         db  256  dup(?)',0dh,0ah,0
szSupportA03   db  'lf             LOGFONT         <?>',0dh,0ah,0
szSupportF04   db  'FindData       WIN32_FIND_DATA <?>',0dh,0ah,0
szSupportT03   db  'tvis           TV_INSERTSTRUCT <?>',0dh,0ah,0
szSupportL03   db  'lvc            LV_COLUMN       <?>',0dh,0ah
               db  'lvi            LV_ITEM         <?>',0dh,0ah,0

szECX          db  'ecx',0
szEDX          db  'edx',0
szC            db  'C',0

szXXMM         db  'XXMM',0
szYYMM         db  'YYMM',0
szXWth         db  'XWth',0
szYHth         db  'YHth',0

sz7501C        db  '7501C',0
sz7501         db  '7501',0
sz7508         db  '7508',0
sz7509         db  '7509',0
sz7510         db  '7510',0
sz7511         db  '7511',0
sz7512         db  '7512',0
sz7517         db  '7517',0

szRichEditProc db  'RichEditProc    PROTO  :DWORD, :DWORD, :DWORD, :DWORD',0dh,0ah,0dh,0ah,0

szCreate0M     db  '         mov     ecx, XXMM',0dh,0ah
               db  '         mov     edx, YYMM',0dh,0ah,0dh,0ah,0

szCreate1M     db  ';---------- [Create the Maim Window] ----------',0dh,0ah
               db  '      INVOKE     CreateWindowEx, ',0
szCreate1      db  ';---------- [Create the Control Window] ----------',0dh,0ah
               db  '         INVOKE     CreateWindowEx, ',0
szCreate2      db  ', addr ',0
szCreate3      db  ', addr ',0
szCreate3N     db  ', NULL',0
szCreate4M     db  ',\',0dh,0ah
               db  '                 ',0
szCreate4      db  ',\',0dh,0ah
               db  '                    ',0
szCreate5      db  ', hInst, NULL',0dh,0ah, 0
szCreate6M     db  '         mov     ',0
szCreate6      db  '            mov     ',0
szCreate7      db  ', eax',0dh,0ah,0dh,0ah,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

szID           db  '(ID)',0
szHand         db  '(Handle)',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

.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  ?
hOpt           dd  ?
hSizePos       dd  ?
hDef           dd  ?
hWndGrp        dd  ?
hKeepSel       dd  ?
hSingle        dd  ?
hNoMove        dd  ?
hWndTool       dd  ?
hWndCombo      dd  ?
hWndList       dd  ?
hWndListD      dd  ?
hWndListS      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  ?

hImageList     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  ?
hSMove         dd  ?
h502           dd  ?
h503           dd  ?
h898           dd  ?
h899           dd  ?
hSizeData      dd  ?
hPat           dd  ?

hDefHeap       dd  ?
Classes        dd  ?
Handles        dd  ?
Text           dd  ?
ControlsB      dd  ?
UnDoArray      dd  ?
hLoadStyles    dd  ?
hBuff          dd  ?
hOutput        dd  ?

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  ?
HideType       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  ?
SingleOn       dd  ?
NoMoveOn       dd  ?
BorderOn       dd  ?
ConvertOn      dd  ?
hGrpOn         dd  ?
ParentOn       dd  ?
DownOn         dd  ?
FontOn         dd  ?
NameOn         dd  ?
RevOn          dd  ?
DblOn          dd  ?
PopUpOn        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  ?
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(?)
szBuffH        db  20  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(?)
szSupCode      db  32  dup(?)

.Data

szTest         db  'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890',0

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

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

Dialog         STRUCT
   ID          dd 2000
   StartID     dd 2001       ; +4
   lpMenu      db 32  dup(?) ; +8
   lpHandle    db 32  dup(?) ; +40
   lpClass     db 32  dup(?) ; +72
   lpCaption   db 512 dup(?) ; +104
   ExStyle     dd 0          ; +616 680
   Style       dd 0          ; +620 684
   Left        dd 55         ; +624 692
   Top         dd 65         ; +628 696
   Wth         dd 40         ; +632 700
   Hgt         dd 20         ; +636 704
   Code        db 'eettttxseeee00000000000000000000' ; +640 708
   CStyles     dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0   ; +672
   Border      dd 0          ; +688 740
   CntType     dd 0          ; +488 744
   Handle      dd 0          ; +492 748 + 4 = 752
Dialog         ENDS
Dlg            Dialog         <>

Controls       STRUCT
   ID          dd 2001
   lpHandle    db 32  dup(?) ; +4
   lpClass     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
   Code        db 'etttxseeeee000000000000000000000' ; +352 608 -16
   CStyles     dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
   hGrp        dd 0
   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 ?
   lpClass     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 ?
DlgLeft        dd ?
DlgCode        dd ?
DlgCStyles     dd ?
DlgBorder      dd ?
DlgCntType     dd ?
DlgHandle      dd ?

CtrlsStart     dd ?
CtrlsLeft      dd ?
CtrlsCode      dd ?
CtrlsCStyles   dd ?
CtrlshGrp      dd ?
CtrlsBorder    dd ?
CtrlsCntType   dd ?
CtrlsHandle    dd ?

hHide          dd ?
hReal          dd ?
h607           dd ?
h608           dd ?
SavOff         dd ?
sEXStyle       dd ?
sStyle         dd ?
hBut616        dd ?
hBut617        dd ?
hBut618        dd ?
hBut619        dd ?
ExtOn          dd ?
PopupWnd       dd ?
InGrp          dd ?
SBarSize       dd ?

tvis           TV_INSERTSTRUCT      <?>
tci            TC_ITEM              <?>
lf             LOGFONT              <?>
rect           RECT                 <?>
Hrect          RECT                 <?>
Prect          RECT                 <?>
Srect          RECT                 <?>
CBrect         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 MainClass, hInst
         INVOKE     UnregisterClass, offset GroupClass, hInst
         INVOKE     UnregisterClass, offset SizeClassV, hInst
         INVOKE     UnregisterClass, offset SizeClassH, hInst
         INVOKE     UnregisterClass, offset MultiClass, hInst
            xor     eax, eax
      .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 MainClass
         mov     wc.hbrBackground, COLOR_BTNFACE+1 ;COLOR_WINDOW+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 ;COLOR_WINDOW+1 ;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 > 529
            jmp     NoCenter
      .endif

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

;---------- [Center the window] ----------
         mov     Wth, 721
         mov     Hgt, 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:
               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, hBitmap
LOCAL    szBuff[256]:BYTE, szDrive[10]:BYTE

      .if wmsg == WM_CREATE
;---------- [Create the status bar window] ----------
         INVOKE     CreateWindowEx, 0, addr StatClass, 0,\
                    WS_CHILD or WS_BORDER or WS_VISIBLE or SBS_SIZEGRIP,\
                    0, 0, 0, 0, hwnd, 0, hInst, 0  
            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     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     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, 10000
            mov     Classes, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 10000
            mov     Handles, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 10000
            mov     Text, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 20000
            mov     ControlsB, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 2000
            mov     UnDoArray, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 51200
            mov     hLoadStyles, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 51200
            mov     hBuff, eax
         INVOKE     HeapAlloc, hDefHeap, 0, 100000
            mov     hOutput, eax

;---------- [Get the Imagelist] ----------
         INVOKE     ImageList_Create, 16, 16, ILC_COLOR16, 5, 10
            mov     hImageList, eax
         INVOKE     LoadBitmap, hInst, 900
            mov     hBitmap, eax
         INVOKE     ImageList_Add, hImageList, hBitmap, NULL
         INVOKE     DeleteObject, hBitmap

         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     lstrlen, addr szBuff
            .while (eax)
               .if byte ptr szBuff[eax] == '\'
                  .break
               .endif
                  dec     eax
            .endw
               add     eax, 2
            INVOKE     lstrcpyn, addr szBuff, addr szBuff, eax
            INVOKE     lstrcpy, addr PathName, addr szBuff
            INVOKE     lstrcpy, addr RootPath, addr PathName
         .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     GetSystemMetrics, SM_CYHSCROLL
            mov     SBarSize, eax

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

         INVOKE     lstrcpy, addr szBuff, addr RootPath
         INVOKE     lstrcat, addr szBuff, addr szStylesF

         INVOKE     ReadInput, addr szBuff, 0
           test     eax, eax
             js     Ret0

      .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 ;48
            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 < 501 && !hAsmEdit         ; Height
            INVOKE     GetWindowRect, hWnd, addr rect
               mov     eax, rect.left
               sub     rect.right, eax
               mov     eax, rect.top
               add     eax, 529
               mov     rect.bottom, eax
            INVOKE     MoveWindow, hWnd, rect.left, rect.top, rect.right, 529, TRUE
               mov     edx, 501
               sub     edx, 20    ; Statusbar
               mov     Hgt, edx

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

NoCheck:
         .if TabSelect == 0
            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
               dec     Hgt
            INVOKE     MoveWindow, hREdit, 0, 0, Wth, Hgt, TRUE
               inc     Hgt
         .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
               mov     rect.top, 238 ;213
               mov     rect.bottom, 203
            .if Hgt < 479
                  sub     Hgt, 290 ;280 ;266
                  mov     eax, Hgt
                  mov     rect.bottom, eax
                  add     rect.top, eax
                  add     rect.top, 5
            .else
                  mov     Hgt, 183 ;197
                  mov     rect.top, 427 ;425
            .endif
            INVOKE     MoveWindow, hWndList, 10, 238, 180, Hgt, TRUE ;213
            INVOKE     MoveWindow, hBut618, 10, rect.top, 84, 15, TRUE
            INVOKE     MoveWindow, hBut619, 105, rect.top, 84, 15, TRUE
            INVOKE     ShowWindow, hWndListS, SW_SHOW
;            INVOKE     MoveWindow, hWndListS, 10, 238, 180, rect.bottom, TRUE ;213
            INVOKE     MoveWindow, hWndListS, 10, 238, 180, Hgt, TRUE ;213
            INVOKE     ShowWindow, hWndListS, SW_HIDE
         .endif
;10, 213, 179, 203

         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 == 0
                     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
         INVOKE     ImageList_Destroy, hImageList

         .if hOpt
            INVOKE     SendMessage, hOpt, WM_CLOSE, 0, 0
         .endif
         .if hSizePos
            INVOKE     SendMessage, hSizePos, WM_CLOSE, 0, 0
         .endif

;         .if hAsmEdit && sw1 == 2244       ; Return from AsmEdit close Tab
;             jmp     GetOut
;         .endif
            and     Len, 0
            mov     Cnt, 8
         .while (Cnt)
               mov     ecx, Len
            .if dword ptr Classes[ecx*4] != 0
               INVOKE     HeapFree, hDefHeap, 0, Classes[ecx*4]
                  mov     ecx, Len
                  mov     dword ptr Classes[ecx*4], 0
            .endif
               inc     Len
               dec     Cnt
         .endw

            and     Len, 0
            mov     Cnt, 24
         .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

         .if hAsmEdit  ; Calling programs parent
               and     SingleOn, 0
               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
            .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 ;1576
            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_LBUTTONUP && !(wparam & MK_CONTROL) && MultiCnt
           Call     ClearMult
      .endif

      .if wmsg == WM_LBUTTONDOWN && !DlgOn || wmsg == WM_LBUTTONDOWN && SingleOn
         .if !SingleOn
               mov     CtrlType, 7501
         .else
             MOVmd     CtrlType, InputType
         .endif
         .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 && !SingleOn
         INVOKE     SetFocus, hForm
         INVOKE     IsWindowVisible, hWndListS
         .if eax
            INVOKE     ShowWindow, hWndListS, SW_HIDE
            INVOKE     EnableWindow, hBut618, 0
            INVOKE     EnableWindow, hBut619, 0
            INVOKE     SendMessage, hWndList, LB_SETCURSEL, -1, 0
         .endif

      .elseif wmsg == WM_MOUSEMOVE && !DlgOn
         INVOKE     IsWindowVisible, hWndListS
         .if eax
            INVOKE     ShowWindow, hWndListS, SW_HIDE
            INVOKE     EnableWindow, hBut618, 0
            INVOKE     EnableWindow, hBut619, 0
            INVOKE     SendMessage, hWndList, LB_SETCURSEL, -1, 0
         .endif

;---------- [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 && !SingleOn || InputType > 7501 && SingleOn
            .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 && !hReal
         INVOKE     SetFocus, hForm

      .elseif wmsg == WM_LBUTTONUP && !DlgOn || wmsg == WM_LBUTTONUP && SingleOn
         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 == 0 && CtrlOn
         .else
               and     CtrlType, 0
               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 !SingleOn
            .if ecx < 20 || edx < 20
                  jmp     Ret0
            .endif
         .else
            .if ecx < 12 || edx < 12
                  and     CtrlType, 0
                  jmp     Ret0
            .endif
         .endif

.if InputType > 7501 && SingleOn
  push     ecx
  push     edx
   pop     rect.bottom
   pop     rect.right
 MOVmd     hForm, hWork
INVOKE     CreateControls, hwnd, 0
INVOKE     EnableWindow, hBut616, 1
   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
            INVOKE     EnableWindow, hBut616, 1

;---------- [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
            .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, 7 ;10
      .endif
         xor     eax, eax

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

      .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

      .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 ;6
            add     Srect.left, eax
            mov     eax, Crect.top
            add     eax, ResT ;22
            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_SYSCOMMAND
            mov     eax, wparam
         .if eax == SC_CLOSE || eax == SC_MAXIMIZE || eax == SC_MINIMIZE
               mov     eax, 1
               ret
         .endif
      .endif

         mov     eax, hwnd
      .if eax == hReal
            jmp     ThatsAll
      .endif

      .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
         .if sw1           ; From changing styles
               mov     eax, 1
               ret
         .endif
         INVOKE     GetWindowRect, hForm, addr Prect
         INVOKE     GetWindowRect, hWnd, addr Crect
          MOVmd     hCtrl, hwnd
            mov     eax, hwnd
         .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
               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
            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

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 == 0
               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
         INVOKE     IsWindowVisible, hWndListS
         .if eax
            INVOKE     ShowWindow, hWndListS, SW_HIDE
            INVOKE     EnableWindow, hBut618, 0
            INVOKE     EnableWindow, hBut619, 0
            INVOKE     SendMessage, hWndList, LB_SETCURSEL, -1, 0
         .endif

;---------- [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 == 0
               .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 == 0 && InputType == 7501 && !hUnder ||\
                TabSelect == 0 && 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
                  .if !hAsmEdit
                     INVOKE     PosProc, hwnd, 0, 0, 9
                  .else
                     INVOKE     PosProc, hwnd, 0, 0, 10
                  .endif
               .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 == 0 && 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
mov     byte ptr Ctrls.Code+29, '0'

.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
mov     byte ptr Ctrls.Code+29, '1'
MOVmd     Ctrls.hGrp, hwnd
                  .break  
               .endif
                  add     eax, 8
                  dec     ecx
            .endw
         .endif

         INVOKE     CreateControls, hwnd, 0
.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 == 0 && 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
                  INVOKE     RtlZeroMemory, addr hDlgMem, 124
                  INVOKE     RtlZeroMemory, addr hArray, 65544
                  INVOKE     RtlZeroMemory, addr GrpCnt, 2576 ;1576
                  INVOKE     RtlZeroMemory, addr hDlg, 6152

                     and     InputType, 0
                     and     hUnder, 0
                     and     hForm, 0
                     and     DlgOn, 0
                     and     CtrlOn, 0
                     and     ToolOn, 0
                     and     StatusOn, 0
                     and     CtrlNum, 0
                     and     IDCnt, 0
                     mov     Dlg.ID, 2000
                     mov     Dlg.StartID, 2001
                  .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
                  INVOKE     EnableWindow, hBut616, 0
                  .if hReal
                       INVOKE     DestroyWindow, hReal
                          and     hReal, 0
                          and     hHide, 0
                        INVOKE     EnableWindow, hBut617, 0
                  .endif

               .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, 25 ;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
      .if hForm
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            mov     SavOff, ecx
      .endif
      .if hForm
            mov     eax, SavOff
            add     eax, DlgCode
      .else
            lea     eax, Dlg.Code
      .endif
         mov     ecx, SBarSize
      .if byte ptr[eax+20] == '1'
            add     Crect.right, ecx
      .endif
      .if byte ptr[eax+21] == '1'
            add     Crect.bottom, ecx
      .endif
         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

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

      INVOKE     CreateDialogParam, hInst, 4805, hTab, offset BuildDlg, 0
         mov     hTabSeL2, 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 < 2)
         .if Cnt == 0
               mov     eax, hWork
               mov     ecx, Cnt
               mov     hREditTab+[ecx*4], eax
         .else
            INVOKE     CreateWindowEx, NULL, addr RichEdit, NULL,\
                       WS_CHILD or WS_VISIBLE or WS_CLIPCHILDREN 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
         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:
         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 == 0
          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 == 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
         INVOKE     CheckDlgButton, hDlg1, 606, BST_UNCHECKED
         INVOKE     ShowWindow, h607, SW_HIDE
         INVOKE     ShowWindow, h608, SW_HIDE
      .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     EndDialog, hdlg, wparam
         mov     eax, TRUE
         jmp     TabCtlRet

GetOut:
         mov     eax, FALSE

TabCtlRet:
         RET
TabCtlDlg 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
;=======================================
ControlDlg 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, TypeC, SavSel, SelState
LOCAL    szBuff[512]:BYTE, szBuff0[256]:BYTE, szBuff1[256]:BYTE

      .if wmsg == WM_INITDIALOG
          MOVmd     hDlg0, hdlg
            mov     Grid, 3

            lea     eax, Dlg.ID
            mov     DlgStart, eax
            lea     ecx, Dlg.Left
            sub     ecx, eax
            mov     DlgLeft, ecx
            lea     ecx, Dlg.Code
            sub     ecx, eax
            mov     DlgCode, ecx
            lea     ecx, Dlg.CStyles
            sub     ecx, eax
            mov     DlgCStyles, 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.Left
            sub     ecx, eax
            mov     CtrlsLeft, ecx
            lea     ecx, Ctrls.Code
            sub     ecx, eax
            mov     CtrlsCode, ecx
            lea     ecx, Ctrls.CStyles
            sub     ecx, eax
            mov     CtrlsCStyles, ecx
            lea     ecx, Ctrls.hGrp
            sub     ecx, eax
            mov     CtrlshGrp, 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 szSingle, 10, 32, 124, 12, 612
            mov     hSingle, eax

         INVOKE     CreateButt, hdlg, 0, BS_AUTOCHECKBOX, addr szNoMove, 10, 45, 124, 12, 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 szReal, 10, 62, 84, 15, 616
            mov     hBut616, eax
         INVOKE     CreateButt, hdlg, 0, BS_PUSHBUTTON, addr szRestore, 105, 62, 84, 15, 617
            mov     hBut617, eax
         INVOKE     CreateButt, hdlg, 0, BS_PUSHBUTTON, addr szUpStyle, 10, 427, 84, 15, 618
            mov     hBut618, eax
         INVOKE     CreateButt, hdlg, 0, BS_PUSHBUTTON, addr szCancel, 105, 427, 84, 15, 619
            mov     hBut619, eax
         INVOKE     EnableWindow, hBut616, 0
         INVOKE     EnableWindow, hBut617, 0
         INVOKE     EnableWindow, hBut618, 0
         INVOKE     EnableWindow, hBut619, 0

;---------- [Create the Styles Listbox] ---------- or WS_VISIBLE
         INVOKE     CreateWindowEx, 0, addr ListboxClass, 0,\
                    WS_CHILD or WS_BORDER or WS_VSCROLL or\
                    LBS_HASSTRINGS or LBS_NOTIFY or LBS_MULTIPLESEL or\
                    LBS_NOINTEGRALHEIGHT or WS_CLIPSIBLINGS,\
                    10, 217, 180, 203, hdlg, 44, hInst, 0  ;10, 213, 180, 203
            mov     hWndListS, eax

         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, 216, 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,\
                    10, 238, 179, 183, 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, hWndListS, WM_SETFONT, hFontL, TRUE
         INVOKE     SendMessage, hWndListS, 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, 64
         INVOKE     RegQueryValueEx, hReg, addr szCusD, 0, addr lpType, addr ddCusD, addr lpcbData
         .if eax == ERROR_FILE_NOT_FOUND
              call     SetAllDefaults
         .endif

            lea     eax, offset szMaiD
            mov     szData, eax
            lea     eax, ddMaiD
            mov     Data, eax
            mov     Cnt1, 29 ;23 ;12
         .while (Cnt1)
               mov     lpcbData, 64 ;40
            INVOKE     RegQueryValueEx, hReg, szData, 0, addr lpType, Data, addr lpcbData
               add     szData, 7
               add     Data, 64 ;40
               dec     Cnt1
         .endw
         INVOKE     RegCloseKey, hReg

            jmp     DialogDone

      .elseif wmsg == WM_CTLCOLORLISTBOX || wmsg == WM_CTLCOLOREDIT
         .if hBR
            INVOKE     DeleteObject, hBR
               and     hBR, 0
         .endif
            mov     eax, lparam
         .if eax == hWndListS
            INVOKE     SetBkColor, wparam, 00000000h
            INVOKE     SetTextColor, wparam, 00ffff00h
            INVOKE     GetStockObject, BLACK_BRUSH
         .else
            INVOKE     SetBkColor, wparam, 00ffffe0h
            INVOKE     SetTextColor, wparam, 0
            INVOKE     CreateSolidBrush, 00ffffe0h
         .endif
            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
;push     eax
;INVOKE     MessageBox, NULL, addr szBuffR, addr AppName, MB_OK
;pop     eax

               .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

;---------- [Styles Listbox] ----------
      .if eax == 44 && ecx == LBN_SELCHANGE
         INVOKE     SendMessage, hWndListS, LB_GETCARETINDEX, 0, 0
            mov     SavSel, eax
         INVOKE     SendMessage, hWndListS, LB_GETTEXT, SavSel, addr szBuff0
         .if byte ptr szBuff0 == 0 || byte ptr szBuff0 == ' ' || byte ptr szBuff0 == '*'
            INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, SavSel
            INVOKE     RedrawWindow, hWndListS, 0, 0,\
                       RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_UPDATENOW or\
                       RDW_ALLCHILDREN or RDW_INTERNALPAINT
               mov     ecx, LBN_SELCANCEL
               shl     ecx, 16
               mov     ax, 44
               mov     cx, ax
            INVOKE     ControlDlg, hdlg, WM_COMMAND, ecx, hWndListS
            INVOKE     ControlDlg, hdlg, WM_PAINT, 0, 0
         .endif
         INVOKE     SendMessage, hWndListS, LB_GETSEL, SavSel, 0
         .if eax
               mov     eax, 1
         .endif
            mov     SelState, eax

         .if CtrlType == 7501
            .if SavSel > 0 && SavSel < 4 || SavSel > 20 && SavSel < 23
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 1
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 2
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 3
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 22
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .endif

         .elseif CtrlType > 7501
            .if SavSel == 1
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 2
            .elseif SavSel == 2
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 1
            .endif
         .endif

         .if CtrlType == 7502
            .if SavSel > 13 && SavSel < 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 14
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel > 17 && SavSel < 24
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 18
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 19
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 20
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 22
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 23
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel == 30 || SavSel == 31
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 32
            .elseif SavSel == 32
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 30
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 31
            .endif

         .elseif CtrlType == 7504
            .if SavSel == 14
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
            .elseif SavSel == 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 14
            .elseif SavSel > 16 && SavSel < 20
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 18
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 19
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel > 19 && SavSel < 23
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 20
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 22
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .endif

         .elseif CtrlType == 7505
            .if SavSel == 14
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
            .elseif SavSel == 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 14
            .elseif SavSel > 18 && SavSel < 22
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 19
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 20
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel > 21 && SavSel < 25
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 22
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 23
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 24
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .endif

         .elseif CtrlType == 7506
            .if SavSel == 14
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
            .elseif SavSel == 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 14
            .elseif SavSel > 19 && SavSel < 23
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 20
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 22
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel > 22 && SavSel < 26
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 23
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 24
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 25
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .endif

         .elseif CtrlType == 7507 || CtrlType == 7508
            .if SavSel > 13 && SavSel < 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 14
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel == 18
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 19
            .elseif SavSel == 19
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 18
            .endif

         .elseif CtrlType == 7509
            .if SavSel == 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 16
            .elseif SavSel == 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
            .elseif SavSel == 25
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 26
            .elseif SavSel == 26
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 25
            .endif

         .elseif CtrlType == 7512
            .if SavSel > 13 && SavSel < 18
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 14
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel == 29
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 30
            .elseif SavSel == 30
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 29
            .endif

         .elseif CtrlType == 7515 || CtrlType == 7516
            .if SavSel > 13 && SavSel < 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 14
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel > 15 && SavSel < 20
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 18
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 19
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel > 19 && SavSel < 22
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 20
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .endif

         .elseif CtrlType == 7518
            .if SavSel > 14 && SavSel < 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 15
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel > 16 && SavSel < 19
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 18
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel > 18 && SavSel < 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 19
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 20
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .elseif SavSel == 21
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 19
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 20
            .endif

         .elseif CtrlType == 7519
            .if SavSel > 15 && SavSel < 18
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .endif

         .elseif CtrlType == 7520
            .if SavSel > 15 && SavSel < 18
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 16
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
               .if SavSel == 17
                  INVOKE     SendMessage, hWndListS, LB_SETSEL, 1, 23
               .endif
            .endif
         .elseif CtrlType == 7523 || CtrlType == 7524
            .if SavSel == 17 || SavSel == 28
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 17
               INVOKE     SendMessage, hWndListS, LB_SETSEL, 0, 28
               INVOKE     SendMessage, hWndListS, LB_SETSEL, SelState, SavSel
            .endif
         .endif


;---------- [Check the control combobox for control selection] ----------
      .elseif 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 && 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 control selection] ----------
      .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     ; Single control only
         INVOKE     SendMessage, hSingle, BM_GETCHECK, 0, 0
         .if eax == BST_CHECKED && !DlgOn
               mov     SingleOn, 1
               and     SizeB, 0
               and     SizeT, 0

         .elseif eax == BST_UNCHECKED && !DlgOn && ArrayCnt
            INVOKE     SendMessage, hSingle, BM_SETCHECK, BST_CHECKED, 0

         .else
            INVOKE     SendMessage, hSingle, BM_SETCHECK, BST_UNCHECKED, 0
               and     SingleOn, 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, hdlg, offset OptionsProc, 0
            INVOKE     SetFocus, hMenuN
         .endif

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

      .elseif eax == 616     ; Set the control to real mode
         INVOKE     IsWindowVisible, hWndListS
         .if eax
            INVOKE     ShowWindow, hWndListS, SW_HIDE
         .endif
         INVOKE     SetFocus, hMenuN
         .if hReal || !CtrlType
               jmp     DialogDone
         .endif
          MOVmd     HideType, CtrlType
         INVOKE     CopyRect, addr Hrect, addr Srect
         INVOKE     SendMessage, hWndList, LB_SETCURSEL, -1, 0
         INVOKE     RealTimeCtrl, 0
         INVOKE     EnableWindow, hBut617, 1

      .elseif eax == 617     ; Restore the control
         INVOKE     SetFocus, hMenuN
         .if hReal
            INVOKE     DestroyWindow, hReal
            INVOKE     ShowWindow, hHide, SW_SHOW

             MOVmd     hCtrl, hHide
             MOVmd     CtrlType, HideType
            .if CtrlType == 7503
                MOVmd     hGrp, hHide
            .endif
            .if CtrlType == 7501
               INVOKE     GetClientRect, hHide, addr Srect
               INVOKE     MoveGrabbers, 2, 0
            .else
               INVOKE     CopyRect, addr Srect, addr Hrect
               INVOKE     MoveGrabbers, 5, 0
            .endif

               and     hReal, 0
               and     hHide, 0
         .endif
         INVOKE     EnableWindow, hBut617, 0

      .elseif eax == 618     ; Load styles Listbox
         .if hReal
               jmp     DialogDone
         .endif
         INVOKE     SetFocus, hMenuN
         INVOKE     GetStyles, hWndListS, 0
           call     SetStyles
         INVOKE     ShowWindow, hWndListS, SW_HIDE
         INVOKE     EnableWindow, hBut618, 0
         INVOKE     EnableWindow, hBut619, 0
         INVOKE     RedrawWindow, hWndList, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN

      .elseif eax == 619     ; Hide Listbox
         INVOKE     SetFocus, hMenuN
         INVOKE     ShowWindow, hWndListS, SW_HIDE
         INVOKE     EnableWindow, hBut618, 0
         INVOKE     EnableWindow, hBut619, 0
         INVOKE     RedrawWindow, hWndList, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN

      .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
         INVOKE     IsWindowVisible, hWndListS
         .if eax
            INVOKE     ShowWindow, hWndListS, SW_HIDE
            INVOKE     EnableWindow, hBut618, 0
            INVOKE     EnableWindow, hBut619, 0
            INVOKE     SendMessage, hWndList, LB_SETCURSEL, -1, 0
         .endif
            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 &&!SingleOn ||\
          InputType == 7501 && SingleOn
         INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, InputType, FALSE
            and     InputType, 0
            jmp     DialogDone
      .endif

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

      .endif

         jmp     DialogDone

DialogDone:
         mov     eax, FALSE

DialogRet:
         ret
ControlDlg 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

;======================================================
; Find Replace Procedure
;======================================================
FindRep PROC lpInput:DWORD, lpReplace, Funct
LOCAL    ft:FINDTEXT
LOCAL    cr:CHARRANGE
LOCAL    charF:CHARFORMAT2
LOCAL    szBuff0[64]:BYTE

         mov     charF.cbSize, sizeof charF
         mov     charF.dwMask, CFM_COLOR
      INVOKE     SendMessage, hREdit, EM_HIDESELECTION, 1, 0

      .if Funct == 8            ; Highlight
            jmp     FindFirst4
      .endif

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

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

FindFirst4:
         mov     ft.chrg.cpMin, 0
         mov     ft.chrg.cpMax, -1
         mov     word ptr szBuff0, 003bh
         lea     eax, szBuff0
         mov     ft.lpstrText, eax

FindNext4:
      INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
      .if eax != -1
            mov     ft.chrg.cpMin, eax
            inc     ft.chrg.cpMin
            mov     cr.cpMin, eax
            lea     eax, offset szCR
            mov     ft.lpstrText, eax
         INVOKE     SendMessage, hREdit, EM_FINDTEXT, FR_DOWN, addr ft
         .if eax != -1
               mov     cr.cpMax, eax
            INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr
             MOVmd     charF.crTextColor, 000000ffh
            INVOKE     SendMessage, hREdit, EM_SETCHARFORMAT, SCF_SELECTION, ADDR charF
             MOVmd     charF.crTextColor, 00000000h
         .endif
            lea     eax, szBuff0
            mov     ft.lpstrText, eax
            jmp     FindNext4
      .endif
         mov     cr.cpMin, 0
         mov     cr.cpMax, 0
      INVOKE     SendMessage, hREdit, EM_EXSETSEL, 0, addr cr

AllDone:
      INVOKE     SendMessage, hREdit, EM_HIDESELECTION, 0, 0

         ret
FindRep ENDP

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

      .if wmsg == WM_INITDIALOG
          MOVmd     hDlg1, hdlg
         INVOKE     GetDlgItem, hdlg, 603
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 604
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 605
         INVOKE     EnableWindow, eax, 0
         INVOKE     GetDlgItem, hdlg, 607
            mov     h607, eax
         INVOKE     ShowWindow, h607, SW_HIDE
         INVOKE     GetDlgItem, hdlg, 608
            mov     h608, eax
         INVOKE     ShowWindow, h608, SW_HIDE

      .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     Extract
         INVOKE     SetFocus, hREdit
         INVOKE     SendMessage,  hREdit, WM_GETTEXTLENGTH, 0, 0
         .if eax
            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 == 603
            mov     sw6, 4
         INVOKE     SetFocus, hMenuN
           call     SaveFile
         INVOKE     SetFocus, hREdit

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

      .elseif eax == 606
         INVOKE     SetFocus, hMenuN
         INVOKE     FillBuffer, addr szSupCode, sizeof szSupCode, ' ', 1
         INVOKE     IsDlgButtonChecked, hdlg, 606

         .if eax == BST_CHECKED
            INVOKE     ShowWindow, h607, SW_SHOW
            INVOKE     ShowWindow, h608, SW_SHOW

            INVOKE     SendMessage, h608, LB_RESETCONTENT, 0, 0
               and     Len1, 0
             MOVmd     Cnt1, ArrayCnt
               inc     Cnt1

GetMore:
            .while (Cnt1)                          ; Find valid control handles in the array
                  mov     eax, Len1
               .if hArray+[eax*8+4]                ; Check for valid handle
                     mov     edx, hArray+[eax*8]   ; Extract array control ID
                     and     edx, 0ffffh
                     mov     TempType, edx
                  .if edx == 7501 || edx > 7507 && edx < 7513 || edx == 7517
                        sub     edx, 7501
                     .if byte ptr szSupCode[edx] == ' '
                           mov     byte ptr szSupCode[edx], '1'
                        .if TempType > 7502 && TempType < 7507
                              mov     dword ptr szSupCode+2, '1111'
                        .endif
                           INVOKE     lstrcpy, addr szBuff0, szClassArray[edx*4]
                           INVOKE     SendMessage, h608, LB_ADDSTRING, 0, addr szBuff0
                              mov     ecx, eax
                           INVOKE     SendMessage, h608, LB_SETITEMDATA, ecx, TempType
                     .endif
                 .endif
              .endif
                  inc     Len1
                  dec     Cnt1
            .endw

         .else
            INVOKE     ShowWindow, h607, SW_HIDE
            INVOKE     ShowWindow, h608, SW_HIDE
         .endif
      .endif

BuildDone:
         mov     eax, FALSE

BuildRet:
         ret
BuildDlg 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, 464 ;368 ;120
      .while (ecx)
            mov     edx, dword ptr ddMai[eax]
            mov     dword ptr ddMaiD[eax], edx
            add     eax, 4
            dec     ecx
      .endw

         lea     eax, offset szMaiD
         mov     szData, eax
         lea     eax, ddMaiD
         mov     Data, eax
         mov     Cnt1, 29 ;23 ;12
      .while (Cnt1)
         INVOKE     RegSetValueEx, hReg, szData, 0, REG_BINARY, Data, 64 ;40
            add     szData, 7
            add     Data, 64 ;40
            dec     Cnt1
      .endw

      INVOKE     RegCloseKey, hReg

         ret
SetAllDefaults ENDP

;=======================================
; GetDefaults Procedure
;=======================================
GetDefaults PROC hList:DWORD
LOCAL    hReg:DWORD, Cnt1, TypeC, Index, Incr, SavCnt, 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, 64 ;40
         add     eax, offset ddMaiD
         mov     TypeC, eax

      .if hList == 1234
            mov     eax, SavSel
           imul     eax, 64 ;40
            mov     ecx, 16 ;10
         .while (ecx)
               mov     edx, dword ptr ddMai[eax]
               mov     dword ptr ddMaiD[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     Incr, 0
            and     Index, 0
            mov     Cnt1, eax
            mov     eax, hList
         .if eax == hList12
            .if Cnt1 > 4
                  mov     Cnt1, 4
            .endif
         .else
               add     Incr, 4
            .if Cnt1 > 12
                  mov     Cnt1, 12
            .endif
         .endif
         .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
                  mov     ecx, Index
                  mov     eax, dword ptr szArray[ecx*4]
                  mov     ecx, TypeC
                  mov     edx, Incr
                  mov     [ecx+edx*4], eax  ; Default styles
                  inc     Incr
            .endif
               inc     Index
               dec     Cnt1
         .endw
      .endif

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

      .if hList != 1234
            lea     eax, ddMaiD
      .else
            lea     eax, ddMai
      .endif

         mov     ecx, SavSel
        imul     ecx, 64 ;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, 64 ;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     LoadListS, hList12, hLoadStyles, 7501, 1

            .elseif Cnt1 == 3
               INVOKE     LoadListS, hList13, hLoadStyles, 7501, 2
            .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, hList12, LB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hList13, LB_RESETCONTENT, 0, 0
         INVOKE     SendMessage, hList11, CB_GETCURSEL, 0, 0
           push     eax
            add     eax, 7501
           push     eax
         INVOKE     LoadListS, hList12, hLoadStyles, eax, 1
            pop     eax
         INVOKE     LoadListS, hList13, hLoadStyles, eax, 2
            pop     eax
            mov     ecx, eax
           imul     ecx, 64 ;40
            add     ecx, offset ddMaiD
            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

;---------- [Set default styles] ----------
            mov     Cnt1, 1
           push     TypeC
         .while (Cnt1 < 3)
            .if Cnt1 == 1           ; Extended styles
                  mov     Cnt, 4
            .else                   ; Window and Control styles
                  mov     Cnt, 12
                  add     TypeC, 16
            .endif
            .while (Cnt)
                  mov     ecx, TypeC
                  mov     eax, [ecx]
               .if eax
                  .if Cnt1 == 1
                     INVOKE     SendMessage, hList12, LB_SETSEL, 1, [ecx]
                  .else
                     INVOKE     SendMessage, hList13, LB_SETSEL, 1, [ecx]
                  .endif
               .endif
                  add     TypeC, 4
                  dec     Cnt
            .endw
               inc     Cnt1
            .if Cnt1 == 2
                  pop     TypeC
            .endif
         .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         ; Update control defaults styles
         INVOKE     SendMessage, hList11, CB_GETCURSEL, 0, 0
         .if eax == CB_ERR
; Do Message
               jmp     SetDefaultsDone
         .endif
           imul     eax, 64
            add     eax, offset ddMaiD
            mov     TypeC, eax
   
            xor     eax, eax
            and     Incr, 0
            mov     Cnt1, 16
         .while (Cnt1)
               mov     ecx, TypeC
               mov     edx, Incr
               mov     [ecx+edx*4], eax  ; Clear all control styles
               inc     Incr
               dec     Cnt1
         .endw

         INVOKE     GetDefaults, hList12
         INVOKE     GetDefaults, hList13

      .endif

         jmp     SetDefaultsDone

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

SetDefaultsDone:
         mov     eax, FALSE

SetDefaultsRet:
         ret
SetDefaults ENDP

;=====================================================
; SubClass the Rich Edit control PROCEDURE
;=====================================================
RichEditProc PROC hwnd:DWORD, wmsg, wparam, lparam

      .if wmsg == WM_RBUTTONDOWN
            jmp     PopUp
      .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

Ret0:
         mov     eax, 0
         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, hFontE ;S
         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
LOCAL     szBuff[64]:BYTE

      .if wmsg == WM_PAINT
          MOVmd     hCtrl, hwnd
            mov     CtrlType, 7511
            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     lstrcat, addr szBuff, addr szClear
         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, hFontE ;S
         INVOKE     SetTextColor, hEDC, 0
         INVOKE     DrawText, hEDC, addr szBuff, -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
LOCAL     szBuff[64]:BYTE

      .if wmsg == WM_PAINT
          MOVmd     hCtrl, hwnd
            mov     CtrlType, 7512 ;7511
            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     lstrcat, addr szBuff, addr szClear
         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, 18 ;15
         INVOKE     SelectObject, hEDC, hFontE ;S
         INVOKE     SetTextColor, hEDC, 0
         INVOKE     DrawText, hEDC, addr szBuff, -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, Cnt1, 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 !PasteOn
         and     Ctrls.ExStyle, 0
         and     Ctrls.Style, 0
.endif
         and     Dlg.Border, 0
         and     Ctrls.Border, 0

      .if InputType == 7501
         INVOKE     lstrcpy, addr szBuff1, addr szMain
         INVOKE     lstrcpy, addr szBuffH, addr szMainh
            mov     byte ptr Dlg.Code+29, '0'
            mov     byte ptr Dlg.Code+30, '0'
            mov     byte ptr Dlg.Code+31, '0'
            mov     Dlg.ExStyle, 0
            mov     Dlg.Style, 0

           call     LoadDefStyles
          MOVmd     Dlg.ExStyle, sEXStyle
          MOVmd     Dlg.Style, sStyle

;DSPValue hWnd, Dlg.ExStyle, 1, 'm'
;DSPValue hWnd, Dlg.Style, 1, 'm'

          MOVmd     w1, Dlg.ExStyle
          MOVmd     w2, Dlg.Style

         INVOKE     lstrcpy, addr szBuffT, addr szBuff1
         INVOKE     CreateWindowEx, w1,\
                    addr MainClass, 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     ControlDlg, hDlg0, WM_COMMAND, 620, 0  ; Check for grid
            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, WS_EX_STATICEDGE, 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

      .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
            mov     rect.right, 16
         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 animate 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
            lea     eax, Dlg.lpHandle
            sub     eax, DlgStart
            mov     StrOff, eax
      .else
            lea     eax, Ctrls.lpHandle
            sub     eax, CtrlsStart
            mov     StrOff, eax
      .endif

         mov     ecx, StrAddr
         add     ecx, StrOff
.if !sw44 || PasteOn
      INVOKE     lstrcpy, ecx, addr szBuffH
.endif
         mov     ecx, StrAddr
         add     ecx, StrOff
        push     ecx
.if !sw44 || PasteOn
      .if CtrlType != 7501
         INVOKE     lstrcat, ecx, addr szBuff2
      .endif
.endif


      .if CtrlType == 7501
            lea     eax, Dlg.lpClass
            sub     eax, DlgStart
            mov     StrOff, eax
      .else
            lea     eax, Ctrls.lpClass
            sub     eax, CtrlsStart
            mov     StrOff, eax
      .endif
         mov     ecx, StrAddr
         add     ecx, StrOff

         mov     eax, CtrlType
         sub     eax, 7501
;       MOVmd     cAddr, ClassArray[eax*4]
      .if CtrlType != 7529
         INVOKE     lstrcpy, ecx, ClassArray[eax*4]
      .else
         INVOKE     lstrcpy, ecx, addr CustClass
      .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

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

;---------- [Update the control styles in the structure] ----------
         mov     edi, StrAddr
      .if CtrlType == 7501
            add     edi, DlgCStyles
      .else
            add     edi, CtrlsCStyles
      .endif
         lea     esi, ddMaiD
         mov     ebx, CtrlType
         sub     ebx, 7501
        imul     ebx, 64      ; 4 x 16
         add     esi, ebx
         xor     eax, eax
         mov     ecx, 16
      .while (ecx)
            mov     ebx, dword ptr[esi+eax*4]
            mov     dword ptr[edi+eax*4], ebx
            inc     eax
            dec     ecx
      .endw

;---------- [Allocate or reallocate memory] ----------
         mov     ecx, CtrlType
         sub     ecx, 7501
         mov     MemSave, ecx
      .if dword ptr hDlgMem+[ecx*4] == 0
         INVOKE     HeapAlloc, hDefHeap, 0, 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, offset dword ptr hDlgMem+[ecx*4], BlockSize
.if eax == STATUS_NO_MEMORY || eax == STATUS_ACCESS_VIOLATION || eax == 0
;DSPValue hWnd, eax, 1, 'm'
   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] ----------
;DSPValue hWnd, StrAddr, 1, 'm'
;DSPValue hWnd, StrSize, 1, 'm'
;DSPValue hWnd, Cnt, 1, 'm'

         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
;mov     esi, hDlgMem
;mov     eax, [esi]
;DSPValue hWnd, eax, 1, 'm'
;   mov     ecx, 104
;INVOKE     MessageBox, NULL, addr [esi+ecx], addr AppName, MB_OK

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, hAddr, hHand
LOCAL    szBuff2[10]:BYTE

         mov     eax, InputType
         sub     eax, 7501
       MOVmd     cAddr, ClassArray[eax*4]
       MOVmd     hAddr, HandArray[eax*4]

      .if !sw44 || PasteOn
         .if PasteOn
             MOVmd     dwEXStyle, Ctrls.ExStyle
             MOVmd     dwStyle, Ctrls.Style
         .endif
          MOVmd     tAddr, TextArray[eax*4]

            mov     ecx, CtrlCnt+[eax*4]
            inc     ecx
         INVOKE     BaseAscii, ecx, addr szBuff2, 2, 10, 1, 1, 0

         INVOKE     lstrcpy, addr szBuffT, tAddr

         INVOKE     lstrcat, addr szBuffT, addr szBuff2

         INVOKE     lstrcpy, addr szBuffH, hAddr
          MOVmd     Ctrls.ExStyle, dwEXStyle
          MOVmd     Ctrls.Style, dwStyle

         .if !PasteOn
            .if InputType < 7514 || InputType == 7527 || InputType == 7528
                 call     LoadDefStyles
                MOVmd     Ctrls.ExStyle, sEXStyle
                MOVmd     Ctrls.Style, sStyle
                MOVmd     dwEXStyle, Ctrls.ExStyle
                MOVmd     dwStyle, Ctrls.Style
            .endif
         .endif
      .else
          MOVmd     dwEXStyle, Ctrls.ExStyle
          MOVmd     dwStyle, Ctrls.Style
            lea     eax, Ctrls.lpCaption
            mov     tAddr, eax
         INVOKE     lstrcpy, addr szBuffT, tAddr
      .endif

         mov     eax, hwnd
;      .if eax == hForm
             or     dwStyle, WS_CLIPSIBLINGS
;      .endif
      INVOKE     CreateWindowEx, dwEXStyle, cAddr, addr szBuffT, dwStyle,\
                 rect.left, rect.top, rect.right, rect.bottom, hwnd, InputType, hInst, 0
         mov     hHand, eax
      INVOKE     SetWindowLong, hHand, GWL_EXSTYLE, dwEXStyle
      INVOKE     SetWindowLong, hHand, GWL_STYLE, dwStyle
         inc     rect.bottom
      INVOKE     MoveWindow, hHand, rect.left, rect.top, rect.right, rect.bottom, TRUE
         dec     rect.bottom
      INVOKE     MoveWindow, hHand, rect.left, rect.top, rect.right, rect.bottom, TRUE
         mov     eax, hHand

      .if InputType == 7510
            mov     ecx, eax
           push     eax
         INVOKE     SendMessage, ecx, LB_ADDSTRING, 0, addr szBuffT ;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

;=====================================================
; 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 szHand
         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+30] == '1' ;$$$$
             or     eax, WS_EX_TOPMOST
      .endif
pop     ecx

         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     edx
         mov     edx, SavOff
      .if CtrlType != 7501
            add     edx, CtrlsBorder
      .else
            add     edx, DlgBorder
      .endif
         mov     ebx, dword ptr[edx]
      .if ebx
            mov     ebx, WS_BORDER
      .endif

         pop     edx
         pop     eax
          or     eax, ebx
         mov     ebx, SavOff
         add     ebx, DlgCode
      .if CtrlType == 7501 && byte ptr [ebx+31] == '1' ;$$$$
             or     eax, WS_POPUP
      .endif

      .if CtrlType > 7506 && CtrlType < 7513
            mov     ebx, SavOff
            add     ebx, CtrlsCode
         .if byte ptr [ebx+20] == '1'  ; Set VSCROLL code
                or     eax, WS_VSCROLL
         .endif
         .if byte ptr [ebx+21] == '1'  ; Set HSCROLL code
                or     eax, WS_HSCROLL
         .endif
      .endif

         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, FormX ;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, FormY ;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, SizeB
            add     eax, SizeB
            mov     esi, SavOff
            add     esi, DlgCode
         .if byte ptr[esi+20] == '1'
               add     eax, SBarSize
         .endif
      .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, SizeT
            add     eax, SizeB
            mov     esi, SavOff
            add     esi, DlgCode
         .if byte ptr[esi+21] == '1'
               add     eax, SBarSize
         .endif
      .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, xPos, yPos, 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, xPos, addr XNum, 1, 10, 1, 1, 0
         INVOKE     BaseAscii, yPos, addr YNum, 1, 10, 1, 1, 0
         .if PosType == 8
               mov     eax, SizeB
               add     pt.x, eax
               mov     eax, SizeT
               add     pt.y, eax
               sub     pt.x, 6
               sub     pt.y, 6
            .if hAsmEdit
;                  add     pt.x, 6
;                  add     pt.y, 6 ;25
            .endif
         .endif
         .if PosType == 15
              add     pt.y, 15
         .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

         .elseif InputType == 7501 || PosType == 10
               mov     eax, SizeB
               add     pt.x, eax
               mov     eax, SizeT
               add     pt.y, eax
;               sub     pt.x, 2
;               add     pt.y, 17
            sub     pt.x, 8
            sub     pt.y, 8

         .elseif PosType == 9
               mov     eax, SizeB
               add     pt.x, eax
               mov     eax, SizeT
               add     pt.y, eax
               sub     pt.x, 7
               sub     pt.y, 7

         .elseif PosType == 6 && SingleOn
               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 szHand
         .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
         .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
               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
               .if CtrlType != 7510  ; 7510 = Listbox
                  INVOKE     SendMessage, hCtrl, WM_SETTEXT, 0, addr szBuff
               .else
                  INVOKE     SendMessage, hCtrl, LB_RESETCONTENT, 0, 0
                  INVOKE     SendMessage, hCtrl, LB_ADDSTRING, 0, addr szBuff
               .endif
               INVOKE     RedrawWindow, hCtrl, 0, 0,\
                          RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW

            .elseif CtrlType == 7511
               INVOKE     TreeviewProc, hCtrl, WM_PAINT, 0, 0

            .elseif CtrlType == 7512
               INVOKE     ListviewProc, hCtrl, WM_PAINT, 0, 0

            .elseif CtrlType > 7502 && CtrlType < 7525 ;7524
               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
        call     SetStyles

            .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
        call     SetStyles
            .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

;=====================================================
; Realtime control PROCEDURE
;=====================================================
RealTimeCtrl PROC uses ebx swOn:DWORD
LOCAL    Wrect:RECT
LOCAL    cAddr:DWORD, tAddr, SavOffS
LOCAL    szBuff[512]:BYTE

      .if hReal
            ret
      .endif

         mov     eax, CtrlType
         sub     eax, 7501
       MOVmd     cAddr, ClassArray[eax*4]

      INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szCaption
         mov     dis.itemID, eax
;---------- [Get offset in the structure array] ----------
      INVOKE     GetOffset, 0
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
         mov     SavOffS, ecx
      .if CtrlType == 7501
            lea     eax, Dlg.lpCaption
            sub     eax, DlgStart
            add     ecx, eax
      .else
            lea     eax, Ctrls.lpCaption
            sub     eax, CtrlsStart
            add     ecx, eax
      .endif
      INVOKE     lstrcpy, addr szBuff, ecx

      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
       MOVmd     sEXStyle, dword ptr [ecx+edx*4]        ; EXStyle
       MOVmd     sStyle, dword ptr [ecx+edx*4+4]        ; Style
      .if CtrlType != 7501
            inc     edx
      .endif
       MOVmd     Srect.left, dword ptr [ecx+edx*4+8]    ; Left
       MOVmd     Srect.top, dword ptr [ecx+edx*4+12]    ; Top
       MOVmd     Srect.right, dword ptr [ecx+edx*4+16]  ; Width
       MOVmd     Srect.bottom, dword ptr [ecx+edx*4+20] ; Height

.if !swOn
INVOKE     CopyRect, addr Hrect, addr Srect
.endif

      .if CtrlType == 7503
           push     hCtrl
         INVOKE     GetParent, hCtrl
            mov     hCtrl, eax
      .endif

         mov     eax, SavOffS
      .if CtrlType == 7501
            add     eax, DlgCode
      .else
            add     eax, CtrlsCode
      .endif

         and     PopupWnd, 0
         and     InGrp, 0
      .if byte ptr[eax+31] == '1'
            mov     PopupWnd, 1
      .endif
      .if byte ptr[eax+29] == '1'
            mov     InGrp, 1
      .endif

      INVOKE     GetParent, hCtrl
      .if eax != hForm && CtrlType != 7501 && InGrp
         .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

       MOVmd     hHide, hCtrl
      INVOKE     GetParent, hCtrl

        push     eax
      .if !swOn
         INVOKE     ShowWindow, hCtrl, SW_HIDE
      .endif
         pop     ecx
         mov     edx, CtrlType
      .if !ecx ;|| CtrlType == 7501 && PopupWnd
         INVOKE     GetWindowRect, hWork, addr Prect
            mov     eax, Prect.left
            add     Srect.left, eax
            mov     eax, Prect.top
            add     Srect.top, eax
            mov     ecx, hWork
            xor     edx, edx
      .endif

        push     ecx
        push     edx

      .if PopupWnd
         INVOKE     GetWindowRect, hWork, addr Prect

.if CtrlType != 7501 && !swOn && hForm  ; swOn = from update styles
INVOKE     GetWindowRect, hForm, addr rect
   mov     eax, rect.left
   sub     eax, Prect.left
   add     eax, SizeB
   mov     Prect.left, eax
   mov     eax, rect.top
   sub     eax, Prect.top
   add     eax, SizeT
   mov     Prect.top, eax
.endif

            mov     eax, Prect.left
   .if !swOn && InGrp
         add     eax, SizeB
         add     eax, xGrp
   .endif
         .if CtrlType != 7501 && swOn
               sub     Srect.left, eax
         .else
               add     Srect.left, eax
         .endif
            mov     eax, Prect.top
   .if  !swOn && InGrp
         add     eax, SizeT
         add     eax, yGrp
   .endif
         .if CtrlType != 7501 && swOn
               sub     Srect.top, eax
         .else
               add     Srect.top, eax
         .endif
      .endif


         mov     ebx, SavOffS
      .if CtrlType == 7501
            add     ebx, DlgLeft
      .else
            add     ebx, CtrlsLeft
      .endif
;mov     eax, Srect.left
;mov     dword ptr[ebx], eax
;mov     eax, Srect.top
;mov     dword ptr[ebx+4], eax


         pop     edx
         pop     ecx

      .if swOn      ; From update styles
         .if CtrlType == 7503
               pop     hCtrl
         .endif
            and     PopupWnd, 0
            and     hHide, 0

   .if swOn == 4
        push     ecx
        push     edx
      INVOKE     DestroyWindow, hCtrl
         pop     edx
         pop     ecx
      INVOKE     CreateWindowEx, sEXStyle, cAddr, addr szBuff, sStyle,\
                 Srect.left, Srect.top, Srect.right, Srect.bottom, ecx, edx, hInst, 0
         mov     ebx, eax

         xor     eax, eax
         mov     edx, hCtrl
         mov     ecx, ArrayCnt
         inc     ecx
      .while (ecx)          ; Find handle of active control in the array
         .if hArray[eax+4] == edx
               mov     hArray[eax+4], ebx
               mov     hCtrl, ebx
            .break  
         .endif
            add     eax, 8
            dec     ecx
      .endw
      .if CtrlType == 7527
            INVOKE     SetWindowLong, hCtrl, GWL_WNDPROC, IPAdressProc
               mov     lpIPAdress, eax
      .endif
   .endif
            ret
      .endif

      .if CtrlType == 7501 && PopupWnd
            mov     eax, SizeB
            sub     Srect.left, eax
            mov     eax, SizeT
            sub     Srect.top, eax
            mov     ecx, hWork
            xor     edx, edx
      .endif
         and     PopupWnd, 0

      .if CtrlType == 7503
            mov     ecx, hForm
      .endif

        push     hCtrl
      INVOKE     CreateWindowEx, sEXStyle, cAddr, addr szBuff, sStyle,\
                 Srect.left, Srect.top, Srect.right, Srect.bottom, ecx, edx, hInst, 0
         mov     hReal, eax
      INVOKE     SetWindowPos, hReal, HWND_TOPMOST,\
                 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE

      .if CtrlType != 7527
         INVOKE     SendMessage, hReal, WM_SETFONT, hFontE, TRUE ;S
      .endif

      .if CtrlType == 7513
         INVOKE     SetWindowLong, hReal, GWL_WNDPROC, ToolbarProc
            mov     lpToolbar, eax

;---------- [Fill the list combo] ----------
      .elseif CtrlType == 7509 || CtrlType == 7510
           call     LoadListCombo

      .elseif CtrlType == 7511
;---------- [Fill the treeview] ----------
           call     LoadTreeview

      .elseif CtrlType == 7512
;---------- [Fill the listview] ----------
           call     LoadListview

      .elseif CtrlType == 7523 || CtrlType == 7524
         .if CtrlType == 7523
            INVOKE     SendMessage, hReal, STM_SETIMAGE, IMAGE_BITMAP, hBmpR
         .else
            INVOKE     SendMessage, hReal, STM_SETIMAGE, IMAGE_ICON, hIcoR
         .endif
         INVOKE     MoveWindow, hReal, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE

      .elseif CtrlType == 7525
            mov     rect.right, 32
            mov     rect.bottom, 32
         INVOKE     SendMessage, hReal, STM_SETIMAGE, IMAGE_ICON, hIcon
         INVOKE     MoveWindow, hReal, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE

      .elseif CtrlType == 7526
         INVOKE     lstrcpy, addr szBuff, addr RootPath
         INVOKE     lstrcat, addr szBuff, addr szBackS
         INVOKE     lstrcat, addr szBuff, addr szAnimateAvi
;            mov     rect.right, 33
;            mov     rect.bottom, 33
         INVOKE     MoveWindow, hReal, Srect.left, Srect.top, Srect.right, Srect.bottom, TRUE
         INVOKE     SendMessage, hReal, ACM_OPEN, 0, addr szBuff
         INVOKE     ShowWindow, hReal, SW_SHOW
            mov     ecx, -1
            shl     ecx, 16
            mov     ax, -1
            mov     cx, ax
         INVOKE     SendMessage, hReal, ACM_PLAY, 20, ecx

      .endif

         pop     hCtrl

      .if CtrlType == 7503
            pop     hCtrl
      .endif

;---------- [Clear the grabber handles] ----------
         mov     Srect.left, -10
         mov     Srect.top, -10
         mov     Srect.right, 0
         mov     Srect.bottom, 0
      INVOKE     MoveGrabbers, 5, 1

         ret

RealTimeCtrl 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 == 610
           call     SetAllDefaults
            jmp     DlgDone
      .endif

      .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
            .if hForm && !SingleOn
               INVOKE     ShowWindow, hForm, SW_HIDE
            .endif
               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     eax, ebx
                     and     eax, 0ffffh
                  INVOKE     DestroyWindow, edx
               .endif
                  inc     Len
                  dec     ArrayCnt
            .endw

               and     Len1, 0
               mov     Cnt1, 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
            INVOKE     RtlZeroMemory, addr hArray, 65544
            INVOKE     RtlZeroMemory, addr GrpCnt, 2576 ;1576
            INVOKE     RtlZeroMemory, addr hDlg, 6152
            INVOKE     SendMessage, hWndCombo, CB_RESETCONTENT, 0, 0
            INVOKE     SendMessage, hWndList, LB_RESETCONTENT, 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
            .if SingleOn
               INVOKE     WorkProc, hWork, WM_LBUTTONDOWN, 0, 0
               INVOKE     WorkProc, hWork, WM_LBUTTONUP, 0, 0
            .endif
               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     ControlDlg, hDlg0, 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     EndDialog, hdlg, wparam
         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?
         mov     eax, wparam           ; Otherwise, see if it's OK or CANCEL
         cmp     eax, IDCANCEL         ; that was pressed
          je     CancleIt              ; and if not either of these
         jmp     DlgDone

ColorDlg:
      .if 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     EndDialog, hdlg, wparam
         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, TypeC
LOCAL    szBuff[512]:BYTE

      .if wmsg == WM_LBUTTONDOWN
.if hReal
      mov     eax, 1
      ret
.endif
            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 ;7524
               mov     eax, 3456
         .endif
         .if CtrlType == 7501 && dis.itemID > 1 && CtrlType == 7501 && dis.itemID < 6 ||\
             eax == 3456 && dis.itemID > 0 && eax == 3456 && dis.itemID < 4 ;3^^^^^^^^^
            .if eax == 3456 && dis.itemID == 1 || CtrlType == 7501 && dis.itemID == 3 ||\  ; = lpHandle
                eax == 3456 && dis.itemID == 2 || CtrlType == 7501 && dis.itemID == 4      ; = lpClass
                   jmp     ThatsAll
            .endif
            .if eax == 3456 && dis.itemID == 3 || CtrlType == 7501 && dis.itemID == 5      ; = 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
            INVOKE     lstrcpy, addr [ecx+edx*4], addr szBuff

         .else

            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     ShowWindow, hWndListS, SW_SHOW
               INVOKE     EnableWindow, hBut618, 1
               INVOKE     EnableWindow, hBut619, 1
                 call     LoadSet
                  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
            .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

         .else
            .if CtrlType == 7501 && dis.itemID > 5 && CtrlType == 7501 && dis.itemID < 8 ||\
                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 == 1
            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, 7
      .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, 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, 127 ;63
      .endif

         pop     ebx

         ret
GetOffset ENDP

;======================================================
; Check for under laying Groupbox controls
;======================================================
ChkUnder PROC uses ebx
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
         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

         .if eax > Srect.left && eax < Srect.right &&\
             ebx > Srect.top && ebx < Srect.bottom

.if sw44
      add     dword ptr [ecx-56], 2 ;1
;;      add     dword ptr [ecx-60], 1
.endif

               mov     eax, Srect.left
               sub     dword ptr [ecx-60], eax
               mov     eax, Srect.top
               sub     dword ptr [ecx-56], 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]
            INVOKE     MoveWindow, hChild, rect.left, rect.top, rect.right, rect.bottom, TRUE
            INVOKE     SetParent, hChild, hCtrl

            .if sw44
               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

;===============================================================
; 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 == 3 || sw3 == 6
         INVOKE     lstrcat, addr PathName, addr szStylesF
         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:
         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

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
      .if sw6 == 4
         INVOKE     lstrcpy, addr PathName, addr RootPath
         INVOKE     lstrcat, addr PathName, addr szSlashB
         INVOKE     lstrcat, addr PathName, addr szTxt
            jmp     OpenIt
      .endif

         INVOKE     GetWindowText, hWnd, addr PathName, lengthof PathName
         INVOKE     lstrlen, addr PathName
         .if !eax
            INVOKE     lstrcpy, addr PathName, addr szTxt
         .endif
      .if sw6 == 1
            jmp     SavIt
      .endif

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


          MOVmd     hCtrl, hwnd
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            mov     SavOff, ecx

         .if CtrlType == 7501
               add     ecx, DlgCode
         .else
               add     ecx, CtrlsCode
         .endif
            and     PopupWnd, 0
            and     InGrp, 0
         .if byte ptr[ecx+31] == '1'
            mov     PopupWnd, 1
         .endif
         .if byte ptr[ecx+29] == '1'
               mov     InGrp, 1
         .endif


         .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
.if !eax && PopupWnd && InGrp
      mov     ecx, SavOff
      add     ecx, CtrlshGrp
      mov     eax, dword ptr[ecx]
.endif
            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
            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

         .if PopupWnd && !InGrp
            INVOKE     GetWindowRect, hWork, addr Prect
            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 && eax != hWork  ; If no main eax = hForm & hWork
               mov     eax, SizeB
               sub     ParR, eax
               sub     ParB, eax

         .elseif eax == hGrp
               mov     eax, SizeB
               add     ParR, eax
               sub     ParR, 4
         .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

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

.if PopupWnd && hForm && !InGrp
   INVOKE     GetWindowRect, hForm, addr Crect
      mov     eax, Crect.left
      sub     eax, Prect.left
      sub     Srect.left, eax
      mov     eax, Crect.top
      sub     eax, Prect.top
      sub     Srect.top, eax
.endif

         .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
            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] ----------
            .if CtrlType == 7501
                  jmp     NoBoundries
            .endif
               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

NoBoundries:
            .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
xor     eax, eax
.if !PopupWnd ;&& hForm ;&& !InGrp
                  mov     eax, xGrp
.endif
                  add     eax, SizeB
                  add     Srect.left, eax
xor     eax, eax
.if !PopupWnd ;&& hForm ;&& !InGrp
                  mov     eax, yGrp
.endif
                  add     eax, SizeT
                  add     Srect.top, eax
            .endif

.if PopupWnd && hForm
   INVOKE     GetWindowRect, hForm, addr Crect
      mov     eax, Crect.left
      sub     eax, Prect.left
   .if InGrp
         add     eax, xGrp
   .endif
      sub     Srect.left, eax
      mov     eax, Crect.top
      sub     eax, Prect.top
   .if InGrp
         add     eax, yGrp
   .endif
      sub     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
            mov     eax, Prect.top
            add     eax, SizeT
            sub     Srect.top, eax
         .if CtrlType == 7513    ; Toolbar
               mov     Srect.left, 0
               mov     Srect.top, 0
               mov     Srect.bottom, 28
               jmp     NoMove ;Ret0
         .endif

;---------- [Check for Popup window] ----------
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
         .if CtrlType == 7501
               add     ecx, DlgCode
         .else
               add     ecx, CtrlsCode
         .endif
         .if byte ptr[ecx+31] == '1' && !hForm ;||\
;             byte ptr[ecx+29] == '1' && byte ptr[ecx+31] == '1'
               mov     eax, SizeB
               sub     Srect.left, eax
               mov     eax, SizeT
               sub     Srect.top, eax
         .endif

.if PopupWnd && hForm
   INVOKE     GetWindowRect, hForm, addr Crect
      mov     eax, Crect.left
      sub     eax, Prect.left
   .if InGrp
         add     eax, xGrp
         add     eax, SizeB
   .endif
      sub     Srect.left, eax
      mov     eax, Crect.top
      sub     eax, Prect.top
   .if InGrp
         add     eax, yGrp
         add     eax, SizeT
   .endif
      sub     Srect.top, eax
.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
               mov     eax, yGrp
               add     eax, SizeT
               add     Srect.top, eax
         .endif

         .if ComboOn
               mov     eax, CBrect.bottom
               mov     Srect.bottom, eax
         .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

         .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.lpClass
               sub     eax, CtrlsStart
            INVOKE     lstrcpy, addr CopyP.lpClass, 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     SendMessage, hWndCombo, CB_SETCURSEL, -1, 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

            .if SingleOn
               INVOKE     SendMessage, hWndCombo, CB_GETCOUNT, 0, 0
               .if !eax
                  INVOKE     RtlZeroMemory, addr hDlgMem, 124
                  INVOKE     RtlZeroMemory, addr hArray, 65544
                  INVOKE     RtlZeroMemory, addr GrpCnt, 2576 ;1576
                  INVOKE     RtlZeroMemory, addr hDlg, 6152
                  INVOKE     SendMessage, hWndTool, TB_CHECKBUTTON, InputType, FALSE
                     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
                  INVOKE     SendMessage, hWndCombo, CB_RESETCONTENT, 0, 0
                  INVOKE     SendMessage, hWndList, LB_RESETCONTENT, 0, 0
                  INVOKE     EnableWindow, hBut616, 0
                  INVOKE     WorkProc, hWork, WM_LBUTTONDOWN, 0, 0
                  INVOKE     WorkProc, hWork, WM_LBUTTONUP, 0, 0
               .else
                  INVOKE     SendMessage, hWndCombo, CB_SETCURSEL, 0, 0
                     mov     ecx, CBN_SELCHANGE
                     shl     ecx, 16
                     mov     ax, 87
                     mov     cx, ax
                  INVOKE     SendMessage, hDlg0, WM_COMMAND, ecx, 0
               .endif
                  jmp     Ret0
            .endif

               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 ;, PopUpOn
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

         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            mov     SavOff, ecx

         .if CtrlType == 7501
               add     ecx, DlgCode
         .else
               add     ecx, CtrlsCode
         .endif
            and     PopupWnd, 0
            and     InGrp, 0
         .if byte ptr[ecx+31] == '1'
            mov     PopupWnd, 1
         .endif
         .if byte ptr[ecx+29] == '1'
               mov     InGrp, 1
         .endif

            and     hGrpOn, 0
         INVOKE     GetParent, hCtrl
.if !eax && PopupWnd && InGrp
      mov     ecx, SavOff
      add     ecx, CtrlshGrp
      mov     eax, dword ptr[ecx]
.endif
            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

         INVOKE     SetCapture, hwnd
         INVOKE     GetParent, hCtrl
         .if !hGrpOn
               mov     hParent, eax
         .endif

;---------- [Check for Popup window] ----------
            and     PopUpOn, 0
         .if !hParent || CtrlType == 7501
            INVOKE     GetOffset, 0
               mov     StrSize, eax
              imul     ebx, StrSize
               add     ecx, ebx
            .if CtrlType == 7501
                  add     ecx, DlgCode
            .else
                  add     ecx, CtrlsCode
            .endif
            .if byte ptr[ecx+31] == '1'
                  mov     PopUpOn, 1
               .if CtrlType != 7501
                   MOVmd     hParent, hForm
               .else
                     and     hParent, 0
               .endif
            .endif
         .endif

            and     PosX, 0
            and     PosY, 0
            and     ComboOn, 0
         INVOKE     GetWindowRect, hParent, addr Prect
         INVOKE     GetWindowRect, hCtrl, addr Srect

            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 && eax != hWork  ; If no main eax = hForm & hWork
               mov     eax, SizeB
               sub     ParR, 0 ;3
               sub     ParB, eax

         .elseif eax == hGrp
               mov     eax, SizeB
               add     ParR, eax
               dec     ParR
         .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
            INVOKE     ControlRect, addr Srect, 0, 0
         .else
            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
            .elseif CtrlType == 7501 && PopUpOn
               INVOKE     GetWindowRect, hWork, 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
                     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] ----------
               .if CtrlType == 7501
                     jmp     NoBoundries
               .endif
               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

NoBoundries:
               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

         .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

         .if CtrlType == 7501 && PopUpOn && eax == 9999
               mov     eax, Prect.left
               add     Srect.left, eax
               mov     eax, Prect.top
               add     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
               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     RealTimeCtrl, 4
.endif
;Removed .if CtrlType == 7502 on 08-13-2002

         .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

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

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

         ret
ReadInput ENDP

;===================================
; Load Default Styles Listbox Procedure
;===================================
LoadDefStyles PROC
LOCAL    Cnt1:DWORD, Incr, TypeS

      .if hWndListD
         INVOKE     DestroyWindow, hWndListD
      .endif

;---------- [Create the Styles Listbox] ---------- or WS_VISIBLE
      INVOKE     CreateWindowEx, 0, addr ListboxClass, 0,\
                 WS_CHILD or WS_BORDER or WS_VSCROLL or\
                 LBS_HASSTRINGS or LBS_NOTIFY or LBS_MULTIPLESEL or\
                 LBS_NOINTEGRALHEIGHT or WS_CLIPSIBLINGS,\
                 10, 213, 179, 203, hWnd, 72, hInst, 0  ;10, 213, 180, 213
         mov     hWndListD, eax

       MOVmd     CtrlType, InputType
         mov     TypeS, 1
         mov     Cnt1, 2
      .while (Cnt1)
         INVOKE     SendMessage, hWndListD, LB_RESETCONTENT, 0, 0
         INVOKE     LoadListS, hWndListD, hLoadStyles, CtrlType, TypeS

;---------- [Set default styles] ----------
            mov     eax, CtrlType
            sub     eax, 7501
           imul     eax, 64
            add     eax, offset ddMaiD
            mov     Incr, eax
         .if TypeS == 1          ; Extended styles
               mov     Cnt, 4
         .else                   ; Window and Control styles
               mov     Cnt, 12
               add     Incr, 16
         .endif
         .while (Cnt)
               mov     ecx, Incr
               mov     eax, [ecx]
            .if eax
               INVOKE     SendMessage, hWndListD, LB_SETSEL, 1, [ecx]
            .endif
               add     Incr, 4
               dec     Cnt
         .endw
         INVOKE     GetStyles, hWndListD, 1
         .if TypeS == 1
              push     sEXStyle
         .endif
            inc     TypeS
            dec     Cnt1
      .endw
         pop     sEXStyle

;DSPValue hWnd, sEXStyle, 1, 'm'
;DSPValue hWnd, sStyle, 1, 'm'

         ret
LoadDefStyles ENDP

;===================================
; Load Styles List Box Procedure
;===================================
LoadListS PROC  uses esi  hList:DWORD, Input, TypeC, TypeS
LOCAL    Styles:DWORD
LOCAL    szBuff0[256]:BYTE, szBuff1[20]:BYTE

         mov     Cnt, 1
         and     sw1, 0
         mov     esi, Input
         xor     eax, eax

Getlen:
      .if byte ptr[esi+eax] == 0dh

RunOut:
            mov     Len, eax
            inc     Len
         INVOKE     lstrcpyn, addr szBuff0, esi, Len
            mov     al, byte ptr szBuff0
         .if al == ' ' || al == 0
               inc     Cnt
         .endif

         .if TypeS == 1 && Cnt == 2
              jmp     AllDone
         .endif
         .if TypeS == 2 && Cnt < 2 || TypeS == 2 && Cnt == 2 && al == 0 ||\
             TypeS == 2 && Cnt == 2 && al == ' '
              jmp     Bypass
         .endif

         .if al != 'Q'
            .if TypeC == 7501 && Cnt < 3 ;|| TypeC == 1 && Cnt > 1 && Cnt < 3  ; 0 = Main Window
               .if byte ptr szBuff0+42 == 'N'
                     jmp     Bypass
               .endif
                  jmp     PressOn

;            .elseif TypeC == 1 && Cnt == 1 && byte ptr szBuff0+42 == 'D'
;                  jmp     PressOn

            .elseif TypeC > 7501 && Cnt < 3
               .if Cnt < 3 && al != '*' && al != ' ' && al != 0 && byte ptr szBuff0+42 != 'C' ||\
                   byte ptr szBuff0+42 == 'N'
                     jmp     Bypass
               .else
                     jmp     PressOn
               .endif
            .endif

;            .if TypeC == 1 && Cnt == 3              ; 1 = Dialog Window
;                  jmp     PressOn
            .if TypeC == 7502 && Cnt == 4           ; 2 = Static Control
                  jmp     PressOn
            .elseif TypeC == 7503 && Cnt == 5       ; 3 = Groupbox Control
               .if byte ptr szBuff0+48 == 'G' || al == '*' || al == ' ' || al == 0
                     jmp     PressOn
               .endif
                  jmp     Bypass
            .elseif TypeC == 7504 && Cnt == 5       ; 4 = Radio button Control
               .if byte ptr szBuff0+46 == 'R' || al == '*' || al == ' ' || al == 0
                     jmp     PressOn
               .endif
                  jmp     Bypass
            .elseif TypeC == 7505 && Cnt == 5       ; 5 = Checkbox Control
               .if byte ptr szBuff0+44 == 'C' || al == '*' || al == ' ' || al == 0
                     jmp     PressOn
               .endif
                  jmp     Bypass
            .elseif TypeC == 7506 && Cnt == 5       ; 6 = Button
               .if byte ptr szBuff0+42 == 'B' || al == '*' || al == ' ' || al == 0
                     jmp     PressOn
               .endif
                  jmp     Bypass
            .elseif TypeC == 7507 && Cnt == 6       ; 6 = Edit Control
                  jmp     PressOn
            .elseif TypeC == 7508 && Cnt == 6       ; 7 = RichEdit Control
                  jmp     PressOn
            .elseif TypeC == 7509 && Cnt == 7       ; 8 = Combobox Control
                  jmp     PressOn
            .elseif TypeC == 7510 && Cnt == 8       ; 9 = Listbox Control
                  jmp     PressOn
            .elseif TypeC == 7511 && Cnt == 9      ; 10 = Treeview Control
                  jmp     PressOn
            .elseif TypeC == 7512 && Cnt == 10     ; 11 = Listview Control
                  jmp     PressOn
            .elseif TypeC == 7513 && Cnt == 11     ; 13 = Toolbar Control
                  jmp     PressOn
            .elseif TypeC == 7513 && Cnt == 20     ; 20 = Common control styles
                  jmp     PressOn
            .elseif TypeC == 7514 && Cnt == 12     ; 12 = Statusbar Control
                  jmp     PressOn
            .elseif TypeC == 7515 && Cnt == 13     ; 13 = Hor Scrollbar Control
                  jmp     PressOn
            .elseif TypeC == 7516 && Cnt == 13     ; 14 = Ver Scrollbar Control
                  jmp     PressOn
            .elseif TypeC == 7517 && Cnt == 14     ; 15 = Progressbar Control
                  jmp     PressOn
            .elseif TypeC == 7518 && Cnt == 15     ; 16 = Trackbar Control
                  jmp     PressOn
            .elseif TypeC == 7519 && Cnt == 16     ; 17 = UpDown Control
                  jmp     PressOn
            .elseif TypeC == 7520 && Cnt == 17     ; 20 = Tab Control
                  jmp     PressOn
            .elseif TypeC == 7521 && Cnt == 18     ; 18 = Monthview Control
                  jmp     PressOn
            .elseif TypeC == 7522 && Cnt == 19     ; 19 = Date/Time Picker Control
                  jmp     PressOn
            .elseif TypeC == 7523 && Cnt == 4      ; 4  = Static Bitmap Control
                  jmp     PressOn
            .elseif TypeC == 7524 && Cnt == 4      ; 4  = Static Bitmap Control
                  jmp     PressOn
            .elseif TypeC == 7525 && Cnt == 4      ; 4  = Static Bitmap Control
                  jmp     PressOn
            .elseif TypeC == 7526 && Cnt == 20     ; 20 = Animate Control
                  jmp     PressOn

            .else
                  jmp     Bypass
            .endif

PressOn:
            .if al != '*' && al != ' ' && al != 0
               INVOKE     lstrcpyn, addr szBuff1, addr szBuff0+32, 9
               INVOKE     AsciiBase, addr szBuff1, 16
                  mov     Styles, eax
                  xor     eax, eax
                  mov     ecx, 32
               .while (ecx)
                  .if byte ptr szBuff0[eax] == ' '
                        mov     byte ptr szBuff0[eax], 0
                        mov     dword ptr szBuff0+42, '    '
                        mov     byte ptr szBuff0+46, ' '
                     .break
                  .endif
                     inc     eax
                     dec     ecx
               .endw

            .else
                  mov     Styles, 1234
            .endif
            INVOKE     SendMessage, hList, LB_ADDSTRING, 0, addr szBuff0
               mov     ecx, eax
            INVOKE     SendMessage, hList, LB_SETITEMDATA, ecx, Styles
         .endif

Bypass:
mov     dword ptr szBuff0+42, '    '
mov     byte ptr szBuff0+46, ' '
mov     byte ptr szBuff0+48, ' '
            cmp     sw1, 4
             je     AllDone
            inc     Len
            add     esi, Len
            xor     eax, eax
            jmp     Getlen
      .elseif byte ptr[esi+eax] == 0h
         .if byte ptr[esi+eax-1] == 0ah
               jmp     AllDone
         .else
               mov     sw1, 4
               jmp     RunOut
         .endif
      .endif
         inc     eax
         jmp     Getlen

AllDone:
         ret                          ; Return to caller
LoadListS ENDP

;=====================================================
; Get styles PROCEDURE
;=====================================================
GetStyles PROC uses ebx hListB:DWORD, NoLoad
LOCAL    Index:DWORD, CStyles, Border, VScroll, HScroll
LOCAL    szBuff1[64]:BYTE, szArray[256]:BYTE

         and     ExtOn, 0
         and     PopupWnd, 0
         and     Border, 0
         and     VScroll, 0
         and     HScroll, 0

      .if !NoLoad
         INVOKE     GetOffset, 0
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            mov     SavOff, ecx
         .if CtrlType == 7501
               add     ecx, DlgCStyles
         .else
               add     ecx, CtrlsCStyles
         .endif
            mov     CStyles, ecx
      .else
         .if CtrlType == 7501
               lea     ecx, Dlg.CStyles
         .else
               lea     ecx, Ctrls.CStyles
         .endif
            mov     CStyles, ecx
      .endif

      INVOKE     SendMessage, hListB, LB_GETTEXT, 2, addr szBuff1
      .if dword ptr szBuff1+2 == '_XE_' || dword ptr szBuff1+3 == '_XE_'
            mov     ExtOn, 1
      .endif

;---------- [Clear the structure styles] ----------
;      .if !NoLoad
            xor     eax, eax
            mov     edx, CStyles
         .if ExtOn
               mov     ecx, 4
         .else
               mov     ecx, 12
               add     edx, 16
         .endif
         .while (ecx)
               mov     dword ptr[edx], eax
               add     edx, 4
               dec     ecx
         .endw
;      .endif

      INVOKE     SendMessage, hListB, LB_GETSELCOUNT, 0, 0
      .if !eax && !ExtOn
         .if CtrlType > 7501
            INVOKE     SendMessage, hListB, LB_SETSEL, 1, 2
         .endif
         .if CtrlType == 7501
            INVOKE     SendMessage, hListB, LB_SETSEL, 1, 5
               mov     eax, 1
         .else
            INVOKE     SendMessage, hListB, LB_SETSEL, 1, 3
               mov     eax, 2
         .endif
      .endif
         mov     ecx, eax
      INVOKE     SendMessage, hListB, LB_GETSELITEMS, ecx, addr szArray
         and     sEXStyle, 0
         and     sStyle, 0
         and     Index, 0
      .if !ExtOn
            add     CStyles, 16
      .endif
         mov     Cnt, eax
      .while (Cnt)
            mov     ecx, Index
         .if CtrlType != 7501 && dword ptr szArray[ecx*4] == 1 && !ExtOn ||\
             CtrlType == 7501 && dword ptr szArray[ecx*4] == 2 && !ExtOn ||\
             CtrlType == 7501 && dword ptr szArray[ecx*4] == 22 && !ExtOn
               mov     PopupWnd, 1
         .elseif CtrlType == 7501 && dword ptr szArray[ecx*4] == 11 && !ExtOn ||\ ; Border
                 CtrlType > 7506 && dword ptr szArray[ecx*4] == 7 && !ExtOn
               mov     Border, 1
         .elseif CtrlType == 7501 && dword ptr szArray[ecx*4] == 13 && !ExtOn ||\ ; VScroll
                 CtrlType > 7506 && dword ptr szArray[ecx*4] == 8 && !ExtOn
               mov     VScroll, 1
         .elseif CtrlType == 7501 && dword ptr szArray[ecx*4] == 14 && !ExtOn ||\ ; HScroll
                 CtrlType > 7506 && dword ptr szArray[ecx*4] == 9 && !ExtOn
               mov     HScroll, 1
         .endif

;---------- [Update the control styles in the structure] ----------
;         .if !NoLoad
               mov     eax, dword ptr szArray[ecx*4]
               mov     edx, CStyles
               mov     dword ptr[edx], eax
;         .endif

         INVOKE     SendMessage, hListB, LB_GETTEXT, dword ptr szArray[ecx*4], addr szBuff1

         .if byte ptr szBuff1 != ' ' && byte ptr szBuff1 != '*'
               mov     ecx, Index
            .if dword ptr szBuff1+2 == '_XE_' || dword ptr szBuff1+3 == '_XE_'
               INVOKE     SendMessage, hListB, LB_GETITEMDATA, dword ptr szArray[ecx*4], 0
                   or     sEXStyle, eax

            .else
               INVOKE     SendMessage, hListB, LB_GETITEMDATA, dword ptr szArray[ecx*4], 0
                   or     sStyle, eax
            .endif
         .endif
            inc     Index
            add     CStyles, 4
            dec     Cnt
      .endw

      .if !PopupWnd && !(sStyle & WS_CHILD) && CtrlType > 7501 && !ExtOn
         INVOKE     SendMessage, hListB, LB_SETSEL, 1, 2
             or     sStyle, WS_CHILD
      .endif
      .if !(sStyle & WS_VISIBLE) && !ExtOn
         .if CtrlType == 7501
            INVOKE     SendMessage, hListB, LB_SETSEL, 1, 5
         .else
            INVOKE     SendMessage, hListB, LB_SETSEL, 1, 3
         .endif
             or     sStyle, WS_VISIBLE
      .endif

      .if !NoLoad
            mov     eax, SavOff
            mov     ebx, SavOff
         .if CtrlType == 7501
               add     eax, DlgCode
               add     ebx, DlgBorder
         .else
               add     eax, CtrlsCode
               add     ebx, CtrlsBorder
         .endif
      .else
         .if CtrlType == 7501
               lea     eax, Dlg.Code
               lea     ebx, Dlg.Border
         .else
               lea     eax, Ctrls.Code
               lea     ebx, Ctrls.Border
         .endif
      .endif

;---------- [Scroll codes] ----------
;      .if CtrlType == 7501
            mov     word ptr[eax+20], '00'
         .if VScroll
               mov     byte ptr[eax+20], '1'
         .endif
         .if HScroll
               mov     byte ptr[eax+21], '1'
         .endif
;      .endif

;---------- [Popup window code] ----------
         mov     byte ptr[eax+31], '0'
      .if PopupWnd
            mov     byte ptr[eax+31], '1'
      .endif
         and     PopupWnd, 0

;---------- [Border code] ----------
         mov     dword ptr[ebx], 0
      .if Border
            mov     dword ptr[ebx], 1
      .endif

;DSPValue hWnd, sEXStyle, 1, 'm'
;DSPValue hWnd, sStyle, 1, 'm'

         ret
GetStyles ENDP

;=====================================================
; Set styles PROCEDURE
;=====================================================
SetStyles PROC
LOCAL    szBuff1[64]:BYTE

      INVOKE     GetOffset, 0
         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx

         mov     eax, ecx
      .if CtrlType == 7501
            add     eax, DlgCode
      .else
            add     eax, CtrlsCode
      .endif
         and     PopupWnd, 0
      .if byte ptr[eax+31] == '1'
            mov     PopupWnd, 1
      .endif

         mov     eax, dis.itemID
      .if byte ptr Code[eax] == 'x'
          MOVmd     dword ptr[ecx+edx*4], sEXStyle
         INVOKE     BaseAscii, sEXStyle, addr szBuff1, 8, 16, 1, 1, 1
         INVOKE     SetWindowLong, hCtrl, GWL_EXSTYLE, sEXStyle
      .else
          MOVmd     dword ptr[ecx+edx*4], sStyle
         INVOKE     BaseAscii, sStyle, addr szBuff1, 8, 16, 1, 1, 1
         INVOKE     SetWindowLong, hCtrl, GWL_STYLE, sStyle
      .endif
      INVOKE     SendMessage, hREditP, WM_SETTEXT, 0, addr szBuff1

      .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     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
            ret
      .endif

        push     PopupWnd
      INVOKE     RealTimeCtrl, 1
         mov     sw1, 1
         pop     PopupWnd

      .if CtrlType == 7501 && PopupWnd
            mov     eax, SizeB
            sub     Srect.left, eax
            mov     eax, SizeT
            sub     Srect.top, eax
      .endif

      .if CtrlType == 7523 || CtrlType == 7524
         .if CtrlType == 7523
            INVOKE     SendMessage, hCtrl, STM_SETIMAGE, IMAGE_BITMAP, hBmpR
         .else
            INVOKE     SendMessage, hCtrl, STM_SETIMAGE, IMAGE_ICON, hIcoR
         .endif
      .endif

         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
      .if CtrlType == 7513   ; Toolbar
         INVOKE     RedrawWindow, hCtrl, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW
      .endif
      .if CtrlType == 7502   ; Static
         INVOKE     RedrawWindow, hForm, 0, 0,\
                    RDW_ERASE or RDW_INVALIDATE or RDW_UPDATENOW
      .endif
      .if CtrlType == 7501
         INVOKE     GetSizes, hCtrl
         INVOKE     GetClientRect, hCtrl, addr Srect
         INVOKE     MoveGrabbers, 2, 1
      .endif
         and     sw1, 0
         and     PopupWnd, 0

         ret
SetStyles ENDP

;=====================================================
; Extract code PROCEDURE
;=====================================================
Extract PROC uses ebx esi edi
LOCAL    xPos:DWORD, yPos, Wth, Hgt, xPosM, yPosM, WthM, HgtM, CtlID, MainOn
LOCAL    Cnt1:DWORD, Cnt2, Cnt3, Cnt4, CntT, Len1, Index, DoneOne, Selection
LOCAL    szWork[64]:BYTE, szWork1[512]:BYTE, szBuff0[256]:BYTE, szBuff1[64]:BYTE, szBuff2[20]:BYTE
LOCAL    szPosSize[64]:BYTE, szStyles[512]:BYTE, szArray[256]:BYTE, szEXStyles[256]:BYTE
LOCAL    szClassT[32]:BYTE, szTextT[32]:BYTE, szHandT[32]:BYTE, szDup[32]:BYTE, szWork2[356]:BYTE

      INVOKE     lstrcpy, Classes, addr szNULL
      INVOKE     lstrcpy, Handles, addr szNULL
      INVOKE     lstrcpy, Text, addr szNULL
      INVOKE     lstrcpy, ControlsB, addr szNULL
      INVOKE     lstrcpy, hOutput, addr szNULL
      INVOKE     FillBuffer, addr szDup, sizeof szDup, ' ', 1
         and     MainOn, 0
         and     DoneOne, 0
         and     Selection, 0

      INVOKE     lstrcpy, addr szBuff0, addr RootPath
      INVOKE     lstrcat, addr szBuff0, addr szTemplatesC
      INVOKE     lstrcpy, addr szWork2, addr szBuff0

      INVOKE     FillBuffer, addr szSupCode, sizeof szSupCode, ' ', 1
      INVOKE     IsDlgButtonChecked, hDlg1, 606
      .if eax == BST_CHECKED
         INVOKE     SendMessage, h608, LB_GETSELCOUNT, 0, 0
            mov     Selection, eax 
         .if eax
               mov     ecx, eax
            INVOKE     SendMessage, h608, LB_GETSELITEMS, ecx, addr szArray

               and     Index, 0
               mov     Cnt1, eax
            .while (Cnt1)
                  mov     ecx, Index
               INVOKE     SendMessage, h608, LB_GETITEMDATA, dword ptr szArray[ecx*4], 0
                  mov     ecx, eax
                  sub     eax, 7501
                  mov     byte ptr szSupCode[eax], '1'
               .if ecx > 7502 && ecx < 7507
                     mov     dword ptr szSupCode+2, '1111'
               .endif

                  inc     Index
                  dec     Cnt1
            .endw

         .endif
      .endif
;INVOKE     MessageBox, NULL, addr szSupCode, addr AppName, MB_OK

;---------- [Build the output] ----------
         and     CntT, 0
         and     Len1, 0
       MOVmd     Cnt1, ArrayCnt ;2048 ;1024 ;512 ;64
         inc     Cnt1

GetMore:
      .while (Cnt1)                           ; Find valid control handles in the array
            mov     eax, Len1
         .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
               mov     hCtrl, edx
               inc     Len1
               dec     Cnt1
            .break
         .endif
            inc     Len1
            dec     Cnt1
      .endw

      .if CtrlType != 7501
            inc     CntT
      .endif

;---------- [Run out] ----------
      .if Cnt1
         INVOKE     GetOffset, 1
            mov     ebx, CtrlNum
            mov     StrSize, eax
           imul     ebx, StrSize
            add     ecx, ebx
            mov     SavOff, ecx

;---------- [Build the Control ID] ----------
            mov     byte ptr szPosSize, 0
         .if CtrlType == 7501
               mov     MainOn, 1
               lea     eax, Dlg.ID
               sub     eax, DlgStart
         .else
               lea     eax, Ctrls.ID
               sub     eax, CtrlsStart
         .endif
            mov     ecx, SavOff
            add     ecx, eax
          MOVmd     CtlID, dword ptr [ecx]            ; ID

;---------- [Build Position and Size] ----------
            mov     byte ptr szPosSize, 0
         .if CtrlType == 7501
               lea     eax, Dlg.Left
               sub     eax, DlgStart
         .else
               lea     eax, Ctrls.Left
               sub     eax, CtrlsStart
         .endif
            mov     ecx, SavOff
            add     ecx, eax
            xor     edx, edx
          MOVmd     xPos, dword ptr [ecx+edx*4]       ; Left
          MOVmd     yPos, dword ptr [ecx+edx*4+4]     ; Top
          MOVmd     Wth, dword ptr [ecx+edx*4+8]      ; Width
          MOVmd     Hgt, dword ptr [ecx+edx*4+12]     ; Height
         .if CtrlType == 7501
             MOVmd     xPosM, dword ptr [ecx+edx*4]   ; Left
             MOVmd     yPosM, dword ptr [ecx+edx*4+4] ; Top
             MOVmd     WthM, dword ptr [ecx+edx*4+8]  ; Width
             MOVmd     HgtM, dword ptr [ecx+edx*4+12] ; Height
         .endif
         INVOKE     wsprintf, addr szBuff2, addr fmat1, xPos
         .if CtrlType == 7501
            INVOKE     lstrcpy, addr szBuff2, addr szECX
         .endif
         INVOKE     lstrcat, addr szPosSize, addr szBuff2
         INVOKE     lstrcat, addr szPosSize, addr szComma
         INVOKE     lstrcat, addr szPosSize, addr szSpace
         INVOKE     wsprintf, addr szBuff2, addr fmat1, yPos
         .if CtrlType == 7501
            INVOKE     lstrcpy, addr szBuff2, addr szEDX
         .endif
         INVOKE     lstrcat, addr szPosSize, addr szBuff2
         INVOKE     lstrcat, addr szPosSize, addr szComma
         INVOKE     lstrcat, addr szPosSize, addr szSpace
         INVOKE     wsprintf, addr szBuff2, addr fmat1, Wth
         INVOKE     lstrcat, addr szPosSize, addr szBuff2
         INVOKE     lstrcat, addr szPosSize, addr szComma
         INVOKE     lstrcat, addr szPosSize, addr szSpace
         INVOKE     wsprintf, addr szBuff2, addr fmat1, Hgt
         INVOKE     lstrcat, addr szPosSize, addr szBuff2

;---------- [Build handles] ----------
         .if CtrlType == 7501
               lea     eax, Dlg.lpHandle
               sub     eax, DlgStart
         .else
               lea     eax, Ctrls.lpHandle
               sub     eax, CtrlsStart
         .endif
            mov     ecx, SavOff
            add     ecx, eax
         INVOKE     lstrcpy, addr szWork, ecx
         INVOKE     lstrcat, Handles, addr szWork
         INVOKE     lstrcpy, addr szHandT, addr szWork
         INVOKE     lstrlen, addr szWork
         .if eax < 16
               mov     ecx, 15
         .else
               mov     ecx, eax
         .endif
            sub     ecx, eax
         INVOKE     lstrcpyn, addr szWork, addr szFill, ecx
         INVOKE     lstrcat, Handles, addr szWork
         INVOKE     lstrcat, Handles, addr szdd
         INVOKE     lstrcat, Handles, addr szCRLF

;---------- [Build classes] ----------
            mov     ecx, CtrlType
            sub     ecx, 7501
         INVOKE     lstrcpy, addr szWork, szClassArray[ecx*4]
         INVOKE     lstrcpy, addr szClassT, addr szWork
            mov     eax, CtrlType
            sub     eax, 7501
         .if byte ptr szDup[eax] == ' '
               mov     byte ptr szDup[eax], '1'
            .if CtrlType > 7502 && CtrlType < 7507
                  mov     dword ptr szDup+2, '1111'
            .endif
         .else
               jmp     BuildText
         .endif
         INVOKE     lstrcat, Classes, addr szWork
         INVOKE     lstrlen, addr szWork
         .if eax < 16
               mov     ecx, 15
         .else
               mov     ecx, eax
         .endif
            sub     ecx, eax
         INVOKE     lstrcpyn, addr szWork, addr szFill, ecx
         INVOKE     lstrcat, Classes, addr szWork
         INVOKE     lstrcat, Classes, addr szdb
         .if CtrlType == 7501
               lea     eax, Dlg.lpClass
               sub     eax, DlgStart
         .else
               lea     eax, Ctrls.lpClass
               sub     eax, CtrlsStart
         .endif
            mov     ecx, SavOff
            add     ecx, eax
         INVOKE     lstrcat, Classes, ecx
         INVOKE     lstrcat, Classes, addr szdbEnd
         INVOKE     lstrcat, Classes, addr szCRLF

BuildText:
;---------- [Build text] ----------
         .if CtrlType == 7501
            INVOKE     lstrcpy, addr szWork, addr szAppName
               lea     eax, Dlg.lpCaption
               sub     eax, DlgStart
         .else
            INVOKE     lstrcpy, addr szWork, addr szTextC
            INVOKE     wsprintf, addr szBuff2, addr fmat2, CntT
            INVOKE     lstrcat, addr szWork, addr szBuff2
               lea     eax, Ctrls.lpCaption
               sub     eax, CtrlsStart
         .endif
            mov     ecx, SavOff
            add     ecx, eax
         INVOKE     lstrcpy, addr szWork1, ecx
         INVOKE     lstrlen, addr szWork1
         .if !eax
            INVOKE     lstrcpy, addr szTextT, addr szCreate3N
               jmp     NoText
         .endif
         INVOKE     lstrcat, Text, addr szWork
         INVOKE     lstrcpy, addr szTextT, addr szWork

         INVOKE     lstrlen, addr szWork
         .if eax < 16
               mov     ecx, 15
         .else
               mov     ecx, eax
         .endif
            sub     ecx, eax
         INVOKE     lstrcpyn, addr szWork, addr szFill, ecx
         INVOKE     lstrcat, Text, addr szWork
         INVOKE     lstrcat, Text, addr szdb
         INVOKE     lstrcat, Text, addr szWork1
         INVOKE     lstrcat, Text, addr szdbEnd
         INVOKE     lstrcat, Text, addr szCRLF

NoText:
;---------- [Extract the Extended, Window, and Control styles] ----------
         INVOKE     SendMessage, hWndList, LB_FINDSTRINGEXACT, 0, addr szExStyle
            mov     dis.itemID, eax
         .if CtrlType == 7501
               mov     dis.itemID, 6
         .else
               mov     dis.itemID, 4
         .endif

            mov     byte ptr szEXStyles, 0
            mov     byte ptr szStyles, 0
            mov     Cnt2, 2
         .while (Cnt2)
              call     LoadSet
            INVOKE     SendMessage, hWndListS, LB_GETSELCOUNT, 0, 0

            .if !eax && Cnt2 == 1
               .if CtrlType == 7501
                  INVOKE     SendMessage, hWndListS, LB_SETSEL, 1, 5
                  INVOKE     SendMessage, hWndListS, LB_SETSEL, 1, 21
               .else
                  INVOKE     SendMessage, hWndListS, LB_SETSEL, 1, 2
                  INVOKE     SendMessage, hWndListS, LB_SETSEL, 1, 3
               .endif
                  mov     eax, 2
            .endif
               mov     ecx, eax
            INVOKE     SendMessage, hWndListS, LB_GETSELITEMS, ecx, addr szArray
               and     Index, 0
               and     Cnt4, 0
               mov     Cnt3, eax

            .while (Cnt3)
                  mov     ecx, Index
               INVOKE     SendMessage, hWndListS, LB_GETTEXT, dword ptr szArray[ecx*4], addr szBuff1
               .if dword ptr szBuff1 == 'C_SW' && dword ptr szBuff1+7 == 'LBIS'
                     mov     byte ptr szBuff1, ' '
               .endif
               .if byte ptr szBuff1 != ' '
                     mov     ecx, Index
                  .if dword ptr szBuff1+2 == '_XE_' || dword ptr szBuff1+3 == '_XE_'
                     .if byte ptr szEXStyles != 0
                        INVOKE     lstrcat, addr szEXStyles, addr szOR
                     .endif
                     INVOKE     lstrcat, addr szEXStyles, addr szBuff1

                  .else
                     .if Cnt4 != 0
                        INVOKE     lstrcat, addr szStyles, addr szOR
                        .if Cnt4 == 4 || Cnt4 == 8 || Cnt4 == 12
                           INVOKE     lstrcat, addr szStyles, addr szSlashB
                           INVOKE     lstrcat, addr szStyles, addr szCRLF
                           .if CtrlType == 7501
                              INVOKE     lstrcat, addr szStyles, addr szClearM
                           .else
                              INVOKE     lstrcat, addr szStyles, addr szClear
                           .endif
                        .endif
                     .endif
                     INVOKE     lstrcat, addr szStyles, addr szBuff1
                        inc     Cnt4
                  .endif
               .endif
                  inc     Index
                  dec     Cnt3
            .endw
               inc     dis.itemID
               dec     Cnt2
         .endw

         .if byte ptr szEXStyles == 0
            INVOKE     lstrcat, addr szEXStyles, addr szNULLText
         .endif
         INVOKE     lstrcat, addr szStyles, addr szComma
         INVOKE     lstrcat, addr szStyles, addr szSlashB
         INVOKE     lstrcat, addr szStyles, addr szCRLF
         .if CtrlType == 7501
            INVOKE     lstrcat, ControlsB, addr szCreate0M
         .endif
         .if CtrlType == 7501 && byte ptr szSupCode == '1'
               mov     ecx, CtrlType
            INVOKE     wsprintf, addr szBuff2, addr fmat1, ecx
            INVOKE     lstrcat, addr szBuff2, addr szC
            INVOKE     lstrcat, ControlsB, addr szBuff2
            INVOKE     lstrcat, ControlsB, addr szCRLF
         .endif

         .if CtrlType == 7501
            INVOKE     lstrcat, ControlsB, addr szCreate1M
         .else
            INVOKE     IsDlgButtonChecked, hDlg1, 606
            .if eax == BST_CHECKED && !DoneOne && Selection
                  mov     DoneOne, 1
               INVOKE     lstrcpy, addr szBuff0, addr szWork2
               INVOKE     lstrcat, addr szBuff0, addr szCreateFont
               INVOKE     ReadInput, addr szBuff0, 1
               .if eax != -1
                  INVOKE     lstrcat, ControlsB, hBuff
                  INVOKE     lstrcat, ControlsB, addr szCRLF
               .endif
            .endif
            INVOKE     lstrcat, ControlsB, addr szCreate1
         .endif
         INVOKE     lstrcat, ControlsB, addr szEXStyles
         INVOKE     lstrcat, ControlsB, addr szCreate2
         INVOKE     lstrcat, ControlsB, addr szClassT
         .if byte ptr szTextT != ',' && byte ptr szTextT+2 != 'N'
            INVOKE     lstrcat, ControlsB, addr szCreate3
         .endif
         INVOKE     lstrcat, ControlsB, addr szTextT
         .if CtrlType == 7501
            INVOKE     lstrcat, ControlsB, addr szCreate4M
         .else
            INVOKE     lstrcat, ControlsB, addr szCreate4
         .endif
         INVOKE     lstrcat, ControlsB, addr szStyles
         .if CtrlType == 7501
            INVOKE     lstrcat, ControlsB, addr szClearM
         .else
            INVOKE     lstrcat, ControlsB, addr szClear
         .endif
         INVOKE     lstrcat, ControlsB, addr szPosSize
         INVOKE     lstrcat, ControlsB, addr szComma
         INVOKE     lstrcat, ControlsB, addr szSpace
         .if CtrlType == 7501
            INVOKE     lstrcat, ControlsB, addr szNULLText
         .else
            INVOKE     lstrcat, ControlsB, addr szParent
         .endif
         INVOKE     lstrcat, ControlsB, addr szComma
         INVOKE     lstrcat, ControlsB, addr szSpace
         INVOKE     wsprintf, addr szBuff2, addr fmat1, CtlID
         .if CtrlType == 7501
            INVOKE     lstrcat, ControlsB, addr szNULLText
         .else
            INVOKE     lstrcat, ControlsB, addr szBuff2
         .endif
         INVOKE     lstrcat, ControlsB, addr szCreate5
         .if CtrlType == 7501
            INVOKE     lstrcat, ControlsB, addr szCreate6M
         .else
            INVOKE     lstrcat, ControlsB, addr szCreate6
         .endif
         INVOKE     lstrcat, ControlsB, addr szHandT
         INVOKE     lstrcat, ControlsB, addr szCreate7
            mov     eax, CtrlType
            sub     eax, 7501
         .if byte ptr szSupCode[eax] == '1'
               mov     ecx, CtrlType
            INVOKE     wsprintf, addr szBuff2, addr fmat1, ecx
            INVOKE     lstrcat, ControlsB, addr szBuff2
            INVOKE     lstrcat, ControlsB, addr szCRLF
            INVOKE     lstrcat, ControlsB, addr szCRLF
         .endif

            jmp      GetMore
      .endif

      INVOKE     lstrcat, Classes, addr szCRLF
      INVOKE     lstrcat, Handles, addr szCRLF
      INVOKE     lstrcat, Text, addr szCRLF
      INVOKE     IsDlgButtonChecked, hDlg1, 606
      .if eax == BST_CHECKED && Selection
         INVOKE     lstrcat, Classes, addr szSupportA01
         .if byte ptr szSupCode+10 == '1'
            INVOKE     lstrcat, Classes, addr szSupportT01
         .endif
         .if byte ptr szSupCode+11 == '1'
            INVOKE     lstrcat, Classes, addr szSupportL01
         .endif
         .if byte ptr szSupCode+08 == '1' || byte ptr szSupCode+09 == '1' ||\
             byte ptr szSupCode+11 == '1'
            INVOKE     lstrcat, Classes, addr szSupportF01
         .endif
         INVOKE     lstrcat, Classes, addr szCRLF

         INVOKE     lstrcat, Handles, addr szSupportA02
         .if byte ptr szSupCode+07 == '1'
            INVOKE     lstrcat, Handles, addr szSupportE01
         .endif
         .if byte ptr szSupCode+10 == '1'
            INVOKE     lstrcat, Handles, addr szSupportT02
         .endif
         .if byte ptr szSupCode+08 == '1' || byte ptr szSupCode+09 == '1' ||\
             byte ptr szSupCode+11 == '1'
            INVOKE     lstrcat, Handles, addr szSupportF02
         .endif
         .if byte ptr szSupCode+11 == '1'
            INVOKE     lstrcat, Handles, addr szSupportL02
         .endif
         .if byte ptr szSupCode+08 == '1' || byte ptr szSupCode+09 == '1' ||\
             byte ptr szSupCode+11 == '1'
            INVOKE     lstrcat, Handles, addr szSupportF03
         .endif
         INVOKE     lstrcat, Handles, addr szCRLF

         INVOKE     lstrcat, Handles, addr szSupportA03
         .if byte ptr szSupCode+08 == '1' || byte ptr szSupCode+09 == '1' ||\
             byte ptr szSupCode+11 == '1'
            INVOKE     lstrcat, Handles, addr szSupportF04
         .endif
         .if byte ptr szSupCode+10 == '1'
            INVOKE     lstrcat, Handles, addr szSupportT03
         .endif
         .if byte ptr szSupCode+11 == '1'
            INVOKE     lstrcat, Handles, addr szSupportL03
         .endif
         INVOKE     lstrcat, Handles, addr szCRLF
      .endif
      .if byte ptr szSupCode+07 == '1'
         INVOKE     lstrcat, hOutput, addr szRichEditProc
      .endif
      INVOKE     lstrcat, hOutput, Classes
      INVOKE     lstrcat, hOutput, Text
      INVOKE     lstrcat, hOutput, Handles
      INVOKE     lstrcat, hOutput, ControlsB

      .if byte ptr szSupCode+07 == '1'
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szREditProc
         INVOKE     ReadInput, addr szBuff0, 1
         INVOKE     lstrcat, hOutput, hBuff
      .endif

      INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, 0
      INVOKE     SendMessage, hREdit, WM_SETTEXT, 0, hOutput

      .if byte ptr szSupCode == '1'
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szWinCenter
         INVOKE     ReadInput, addr szBuff0, 1
           test     eax, eax
             js     NoGo
         INVOKE     FindRep, addr sz7501C, hBuff, 0
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szWinShow
         INVOKE     ReadInput, addr szBuff0, 1
           test     eax, eax
             js     NoGo
         INVOKE     FindRep, addr sz7501, hBuff, 0

      .endif

NoGo:
      .if MainOn
         INVOKE     wsprintf, addr szWork, addr fmat1, xPosM
         INVOKE     FindRep, addr szXXMM, addr szWork, 0
         INVOKE     wsprintf, addr szWork, addr fmat1, yPosM
         INVOKE     FindRep, addr szYYMM, addr szWork, 0
         INVOKE     wsprintf, addr szWork, addr fmat1, WthM
         INVOKE     FindRep, addr szXWth, addr szWork, 0
         INVOKE     wsprintf, addr szWork, addr fmat1, HgtM
         INVOKE     FindRep, addr szYHth, addr szWork, 0
      .endif

      .if byte ptr szSupCode+07 == '1'
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szEditSubClass
         INVOKE     ReadInput, addr szBuff0, 1
         .if eax != -1
            INVOKE     FindRep, addr sz7508, hBuff, 0
         .endif
      .endif

      .if byte ptr szSupCode+08 == '1'
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szCombobox1
         INVOKE     ReadInput, addr szBuff0, 1
         .if eax != -1
            INVOKE     FindRep, addr sz7509, hBuff, 0
         .endif
      .endif

      .if byte ptr szSupCode+09 == '1'
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szListbox1
         INVOKE     ReadInput, addr szBuff0, 1
         .if eax != -1
            INVOKE     FindRep, addr sz7510, hBuff, 0
         .endif
      .endif

      .if byte ptr szSupCode+10 == '1'
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szTreeview1
         INVOKE     ReadInput, addr szBuff0, 1
         .if eax != -1
            INVOKE     FindRep, addr sz7511, hBuff, 0
         .endif
      .endif

      .if byte ptr szSupCode+11 == '1'
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szListview1
         INVOKE     ReadInput, addr szBuff0, 1
         .if eax != -1
            INVOKE     FindRep, addr sz7512, hBuff, 0
         .endif
      .endif

      .if byte ptr szSupCode+16 == '1'
         INVOKE     lstrcpy, addr szBuff0, addr szWork2
         INVOKE     lstrcat, addr szBuff0, addr szProgress1
         INVOKE     ReadInput, addr szBuff0, 1
         .if eax != -1
            INVOKE     FindRep, addr sz7517, hBuff, 0
         .endif
      .endif

      INVOKE     FindRep, 0, 0, 8                ; Highlight

         ret

Extract ENDP

;=====================================================
; Load and Set Listbox styles PROCEDURE
;=====================================================
LoadSet PROC uses ebx
LOCAL    TypeC:DWORD

      INVOKE     SendMessage, hWndListS, LB_RESETCONTENT, 0, 0
         mov     eax, dis.itemID
         mov     ecx, 1
;      .if byte ptr Code[eax] == 's'
      .if CtrlType == 7501 && byte ptr Dlg.Code[eax] == 's' ||\
          CtrlType != 7501 && byte ptr Ctrls.Code[eax] == 's'
            mov     ecx, 2
      .endif
        push     ecx
      INVOKE     LoadListS, hWndListS, hLoadStyles, CtrlType, ecx

;---------- [Set default styles] ----------
      INVOKE     GetOffset, 0

         mov     StrSize, eax
        imul     ebx, StrSize
         add     ecx, ebx
      .if CtrlType == 7501
            add     ecx, DlgCStyles
      .else
            add     ecx, CtrlsCStyles
      .endif

         mov     TypeC, ecx
         pop     edx
      .if edx == 1            ; Extended styles
            mov     Cnt, 4
      .else                   ; Window and Control styles
            mov     Cnt, 12
            add     TypeC, 16
      .endif

      .while (Cnt)
            mov     ecx, TypeC
            mov     eax, [ecx]
         .if eax
            INVOKE     SendMessage, hWndListS, LB_SETSEL, 1, [ecx]
         .endif
            add     TypeC, 4
            dec     Cnt
      .endw

         ret
LoadSet ENDP

;===================================================
; LoadList/Combo procedure
;===================================================
LoadListCombo PROC
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    hFind:DWORD
LOCAL    szBuff0[256]:BYTE

;---------- [Get the current dir and load the Listbox with its files] ----------
         INVOKE     GetCurrentDirectory, lengthof szBuff0, addr szBuff0
         INVOKE     lstrcat, addr szBuff0, addr szSlashB
         INVOKE     lstrcat, addr szBuff0, addr szEndP
         INVOKE     FindFirstFile, addr szBuff0, addr FindData
           test     eax, eax
             js     NoFile
            mov     hFind, eax
            jmp     Addem

Getem:
         INVOKE     FindNextFile, hFind, addr FindData
           test     eax, eax
             jz     AllDone

Addem:
         .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||\
             (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ||\
             (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
               jmp     Getem
         .endif
         .if CtrlType == 7509
            INVOKE     SendMessage, hReal, CB_ADDSTRING, 0, addr FindData.cFileName
         .else
            INVOKE     SendMessage, hReal, LB_ADDSTRING, 0, addr FindData.cFileName
         .endif
            jmp     Getem

AllDone:
         INVOKE     FindClose, hFind
         .if CtrlType == 7509
            INVOKE     SendMessage, hReal, CB_SETCURSEL, 0, 0
         .endif

NoFile:
         ret
LoadListCombo ENDP

;===================================================
; LoadTreeview procedure
;===================================================
LoadTreeview PROC

         INVOKE     SendMessage, hReal, TVM_SETIMAGELIST, 0, hImageList
         INVOKE     SendMessage, hReal, TVM_DELETEITEM, 0, TVI_ROOT
            mov     tvis.hParent, NULL   
            mov     tvis.hInsertAfter, TVI_ROOT
            mov     tvis.item.imask, TVIF_TEXT or TVIF_IMAGE or TVIF_SELECTEDIMAGE
            mov     tvis.item.pszText, offset Parent1
            mov     tvis.item.iImage, 0
            mov     tvis.item.iSelectedImage, 1
         INVOKE     SendMessage, hReal, TVM_INSERTITEM, 0, addr tvis
;            mov     hParent, eax

            mov     tvis.hParent, eax
            mov     tvis.hInsertAfter, TVI_LAST
            mov     tvis.item.pszText, offset Child1
         INVOKE     SendMessage, hReal, TVM_INSERTITEM, 0, addr tvis
;            mov     hChild1, eax

            mov     tvis.item.pszText, offset Child2
         INVOKE     SendMessage, hReal, TVM_INSERTITEM, 0, addr tvis
;            mov     hChild2, eax

            mov     tvis.item.pszText, offset Child3
         INVOKE     SendMessage, hReal, TVM_INSERTITEM, 0, addr tvis
;            mov     hChild3, eax

         ret
LoadTreeview ENDP

;===================================================
; LoadListview procedure
;===================================================
LoadListview PROC
LOCAL    lvc:LV_COLUMN
LOCAL    lvi:LV_ITEM
LOCAL    FindData:WIN32_FIND_DATA
LOCAL    hFind:DWORD, Row
LOCAL    szBuff0[256]:BYTE

         mov     lvc.imask, LVCF_TEXT or LVCF_WIDTH
         mov     lvc.pszText, offset szColName
         mov     lvc.lx, 129
      INVOKE     SendMessage, hReal, LVM_INSERTCOLUMN, 0, addr lvc

;---------- [Get the current dir and load the Listbox with its files] ----------
      INVOKE     GetCurrentDirectory, lengthof szBuff0, addr szBuff0
      INVOKE     lstrcat, addr szBuff0, addr szSlashB
      INVOKE     lstrcat, addr szBuff0, addr szEndP
      INVOKE     FindFirstFile, addr szBuff0, addr FindData
        test     eax, eax
          js     NoFile
         mov     hFind, eax
         and     Row, 0
         jmp     Addem

Getem:
      INVOKE     FindNextFile, hFind, addr FindData
        test     eax, eax
          jz     AllDone

Addem:
      .if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||\
          (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ||\
          (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
            jmp     Getem
      .endif

         mov     lvi.imask, LVIF_TEXT or LVIF_IMAGE or LVIF_PARAM
        push     Row
         pop     lvi.iItem
        push     Row
         pop     lvi.lParam
         mov     lvi.iSubItem, 0
         lea     eax, FindData.cFileName
         mov     lvi.pszText, eax
         mov     lvi.iImage, 0
      INVOKE     SendMessage, hReal, LVM_INSERTITEM, 0, addr lvi
         inc     Row
         jmp     Getem

AllDone:
      INVOKE     FindClose, hFind

NoFile:
         ret
LoadListview 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

End DllEntry
