format    PE GUI
include 'c:\fasmw17316\include\Win32a.inc'
include 'fasmAPI\madmat32.txt'
entry     Start
maxTxtLenn  = 94
textNameLen = 64  ;names\info txt in struct
rep_Options     equ 0
rep_Params      equ 0
daNotify        equ 0

outPipTxtSize    = 1024*400
getTreeListNames = GetStructNamesok ;0

macro IfBtn num,fun,notcount=0 { local .1
mov eax, BN_CLICKED
shl eax, 16
add eax, num
cmp eax, [wParam]
jnz .1
;mov esi,[hwnddlg]
call fun
if notcount = 0
call inc_Val
end if
.1:
}
macro SaveFileNotClose chName,chDat,chSizeByts {
      invoke CreateFile,chName,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
      mov    [fhand],eax
      invoke WriteFile,[fhand],chDat,chSizeByts,rbait,0
      ;invoke CreateFile,chName,0,GENERIC_WRITE,1,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0
      ;SaveFileNotClose  SaveNames,OBJMeshData+5000000-8,dword [TmpLenFile]
      }
macro comboGetTxt id { invoke GetDlgItem,esi,id
        invoke SendMessage,eax,WM_GETTEXT,126,comboTxt
}
macro Msg txt { local .1
cmp [SaveFlg],1
jnz .1
call SaveStructName
.1:
;invoke MessageBox,0,txt,0,0
}
macro Msg_ txt { invoke MessageBox,0,txt,0,0 }
section '.code' code  writeable executable
        fhand        dd 0
        rbait        dd 0,0
rept 1 { we1          dd 0,0,0,0
         we2          dd 0,0,0,0
         we3          dd 0,0,0,0   }
macro vecAdd v1=we1,v2=we2 { movups xmm0,dqword [v1]
                             movups xmm1,dqword [v2]
                             addps  xmm0,xmm1 
;include 'macro\test.txt'  ;error unknow v1
}

Start:  ;Msg tv1Txt2
        vecAdd
        vecAdd we3
        invoke GetModuleHandle, 0
        invoke DialogBoxParam, eax, 0, HWND_DESKTOP, DialogProc, 0
        invoke ExitProcess, 0

proc    DialogProc hwnddlg, msg, wParam, lParam
        xor     eax, eax
;cmp byte [comboListFull],7
cmp     [msg], WM_INITDIALOG
jnz @f

invoke GetDlgItem,[hwnddlg],203
mov ebx,eax
;invoke SendMessage,ebx,dword WM_SETTEXT,dword 0,lltxt1
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt1
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt1b
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt1c
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt1d
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt1e
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt1f
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt2
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt3
invoke SendMessage,ebx,dword CB_ADDSTRING,dword 0,lltxt4
invoke SendMessage,ebx,dword CB_SETCURSEL,dword 0,0
;Msg_ 'ok'
jmp @f
lltxt1  db '1    ',0
lltxt1b db '4    ',0
lltxt1c db '8    ',0
lltxt1d db '16   ',0
lltxt1e db '32   ',0
lltxt1f db '64   ',0
lltxt2  db '128  ',0
lltxt3  db '512  ',0
lltxt4  db '1024 ',0

@@:
rept daNotify {
        cmp     [msg], WM_NOTIFY
        je      NOTIFYDialog
        }
        cmp     [msg], WM_CLOSE
        je      FreeDialog
        cmp     [msg], WM_COMMAND
        jne     ExitProc
        mov esi,[hwnddlg]
;show hiden treeView
        invoke GetDlgItem,esi,1
        invoke ShowWindow,eax,SW_NORMAL  ;nado create treeView bez WS_VISIBLE

        IfBtn 2,addTree,1
        IfBtn 3,addTreeDW,1
        IfBtn 4,addTreeDB,1
        IfBtn 5,addTreeString
        IfBtn 6,addTreePtr
        IfBtn 10,addTreeFunction
        IfBtn 19,procfileToPtr
        IfBtn 20,addTreeOps
        IfBtn 30,addTreeOps2
        IfBtn 35,addTreeptrLabel
        IfBtn 36,addTreeptrCall
        IfBtn 300,procfixCount
        IfBtn 2000,getTreeListNames
        IfBtn 2001,delTreeSelectedItem
        IfBtn 2002,reNameTreeSelectedItem
        IfBtn 2003,insertNameTreeSelectedItem

        xor     eax, eax
        ret

FreeDialog:
invoke  EndDialog, [hwnddlg], 0

ExitProc:
xor     eax, eax
ret

rept daNotify {
NOTIFYDialog: cinvoke sprintf,notifyTxt,'%d',TVN_ITEMEXPANDINGA ;[lParam] ;TVN_ENDLABELEDITA ;[lParam]
              invoke GetDlgItem,[hwnddlg],200
              invoke SendMessage,eax,WM_SETTEXT,0,notifyTxt
              mov eax, TVN_ITEMEXPANDINGA ;TVN_ENDLABELEDITA
              ;shl eax,16
              cmp eax, [lWaram]   ;not work delaem po button rename. v lParam ptrStruct
              jnz @f
              Msg 'TVN_ENDLABELEDIT'
@@:
xor     eax, eax
ret
notifyTxt db 'notify000000',0
}
endp

inc_Val:  cmp byte [fixCountVal],1
          jz  .1
          test ecx,ecx
          jz  .1
.2:       inc byte [ecx]
          cmp byte [ecx],'9'
          jbe .1
          mov byte [ecx],'0'
          inc byte [ecx-1]
;new+
	cmp byte [ecx-1],'A'
	jae .1
	cmp byte [ecx-1],'9'
	jbe .1
	mov byte [ecx-1],'A'
.1:
ret

procfileToPtr: xor byte [flg_fileToPtr],1
invoke GetDlgItem,esi,19
movzx ecx,[flg_fileToPtr]
invoke SendMessage,eax,WM_SETTEXT,0,[ppfilePtrTxt+ecx*4]
xor ecx,ecx
ret
ppfilePtrTxt dd tttTxt2,tttTxt1
tttTxt1 db 'no file to ptr',0
tttTxt2 db ' file to ptr',0
flg_fileToPtr db 0

savefileToPtr: cmp byte [flg_fileToPtr],1
                jz .1
        invoke WriteFile,[pipWrite],ttPtrInclude,ttPtrIncludeSz,rbait,0
.1:     invoke WriteFile,[pipWrite],ttEnterTxt,4,rbait,0
        ret
ttPtrInclude db 'include "procs\.txt" '
ttPtrIncludeSz = $-ttPtrInclude
ttEnterTxt db 13,10,13,10

procfixCount:  xor byte [fixCountVal],1
;pusha
;invoke MessageBeep,0
;popa
invoke GetDlgItem,esi,300
movzx ecx,[fixCountVal]
invoke SendMessage,eax,WM_SETTEXT,0,[ppfixCntTxt+ecx*4]
xor ecx,ecx
ret
ppfixCntTxt dd fixCntTxt2,fixCntTxt1
fixCntTxt1 db 'unfix count',0
fixCntTxt2 db ' fix count',0
fixCountVal db 0

newComboName2:
comboGetTxt 200
mov byte [comboTxt+eax],':'
;Msg  comboTxt
mov     ecx,[tvins.item.pszText]
lea edx,[comboTxt+eax]
.up:
mov al,[ecx]
inc edx
mov [edx],al
inc ecx
test al,al
jnz .up
mov byte [edx],'$'
inc edx
push edx
invoke GetDlgItem,esi,203
pop edx
invoke SendMessage,eax,WM_GETTEXT,126,edx
;Msg  comboTxt
mov     [tvins.item.pszText],comboTxt
ret

newComboName:
comboGetTxt 200
mov byte [comboTxt+eax],':'
;Msg  comboTxt
mov     ecx,[tvins.item.pszText]
lea edx,[comboTxt+eax]
.up:
mov al,[ecx]
inc edx
mov [edx],al
inc ecx
test al,al
jnz .up
;Msg  comboTxt
mov     [tvins.item.pszText],comboTxt
ret

PasteFromFile:  mov [tmpFileName_],eax
                invoke CreateFile,eax,GENERIC_READ,3,0,OPEN_EXISTING,FILE_ATTRIBUTE_READONLY,0 ;NORMAL,0
                mov    [fhand2],eax
test eax,eax
jnz .1
Msg_ [tmpFileName_]
.1:
                invoke GetFileSizeEx,[fhand2],flen

                ;invoke ReadFile,[fhand2],[pipRead],[flen],rbait,0
                invoke ReadFile,[fhand2],tmpFile,[flen],rbait,0
;Msg_ tmpFile
invoke WriteFile,[pipWrite],tmpFile,[flen],rbait,0
                invoke CloseHandle,[fhand2]
ret
fhand2 dd 0
flen   dd 0,0
tmpFileName_ dd 0

include "procs\addTreePtr.txt"
include "procs\addTree.txt"          ;valDD
include "procs\addTreeValDW.txt"     ;valDW
include "procs\addTreeValDB.txt"     ;valDB
include "procs\addTreeOps.txt"
include "procs\addTreeFunction.txt"
include "procs\GetTxtTree.txt"
include "procs\addTreeString.txt"
include 'procs\saveStruct.txt'
include 'procs\addTreeptrLabel.txt'

section '.data' data readable writeable
tvi             TV_ITEM ;LV_ITEM  TV_ITEM
tvins           TV_INSERTSTRUCT
_valD           db      'valD00',0
_valS           db      'valS00',0
_valB           db      'valB00',0
_func           db      'func00',0

_String         db      'text00',0
                dd 0,0
comboTxt        db 128 dup(0)
section 'import' import readable

  library kernel,         'kernel32.dll',\
          msvcrt,         'MSVCRT.DLL',\
          user,           'user32.dll'

  import msvcrt,\
         sprintf,'sprintf'

  import kernel,\
      CreatePipe,         'CreatePipe',\
      GetFileSizeEx,      'GetFileSizeEx',\
      CreateFile,         'CreateFileA',\
      ReadFile,           'ReadFile',\
      WriteFile,          'WriteFile',\
      CloseHandle,        'CloseHandle',\
      GetModuleHandle,    'GetModuleHandleA',\
      ExitProcess,        'ExitProcess'


  import user,\
      CreateWindowEx,     'CreateWindowExA',\
      MessageBeep,        'MessageBeep',\
      DialogBoxParam,     'DialogBoxParamA',\
      ShowWindow,         'ShowWindow',\
      UpdateWindow,       'UpdateWindow',\
      EndDialog,          'EndDialog',\
      SetDlgItemText,     'SetDlgItemTextA',\
      SendDlgItemMessage, 'SendDlgItemMessageA',\
      SendMessage, 'SendMessageA',\
      MessageBox,         'MessageBoxA',\
      LoadMenu,           'LoadMenuA',\
      SetMenu,            'SetMenu',\
      GetDlgItem,         'GetDlgItem'      ;GetItemText,        'GetItemText',\

section '.rsrc' resource readable
WC_TREEVIEW     equ   "SysTreeView32"
btnY equ        480
btnSzX equ      36
directory       RT_DIALOG, dialogs

resource        dialogs, 0, LANG_NEUTRAL, MainWindow
;+TVS_CHECKBOXES
dialog          MainWindow, 'MainDLG', 700, 100, 400, 530, WS_VISIBLE+WS_CAPTION+WS_SYSMENU
dialogitem      WC_TREEVIEW, '', 1, 10, 10, 170*2, 108*4, WS_CHILD+WS_BORDER+TVS_LINESATROOT+TVS_SHOWSELALWAYS+TVS_HASLINES+TVS_EDITLABELS+TVS_HASBUTTONS
dialogitem      'button', 'getStruct',      2000, 10*8-3,           btnY+32, btnSzX+4, 15, WS_VISIBLE
dialogitem      'button', 'delet sel',      2001, 10*4-10,           btnY+17, btnSzX+8, 15, WS_VISIBLE
dialogitem      'button', 'renameSel',      2002, 10*8-3,           btnY+17, btnSzX+4, 15, WS_VISIBLE
dialogitem      'button', 'insert',      2003, 3,           btnY+17, btnSzX-9, 15, WS_VISIBLE
;combobox
dialogitem      'combobox', '',      200, 3,           btnY-37, btnSzX*6-10, 12, WS_VISIBLE
;dialogitem      'combobox', '',      201, 3+210,           btnY-37, btnSzX*4-7, 12, WS_VISIBLE ;rename element
dialogitem      'combobox', '',      201, 3+116,           btnY+19, btnSzX*4-7, 12, WS_VISIBLE
dialogitem      'combobox', '',      202, 3+116,           btnY+34, btnSzX*4-7, 12, WS_VISIBLE
;ops connection struct
dialogitem      'button', 'add opInt4',     20, 3,           btnY-17, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add opVc4',      30, 10*4,        btnY-17, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add ptrLb',      35, 10*8-3,        btnY-17, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add ptrFun',     36, 10*12-6,        btnY-17, btnSzX+2, 15, WS_VISIBLE
;simple values
dialogitem      'button', 'add dd',      2, 3,           btnY, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add dw',      3, 10*4,        btnY, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add db',      4, 10*8-3,      btnY, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add string',  5, 10*12-3*2,   btnY, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add ptrv',    6, 10*16-3*3,   btnY, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add vec2',    7, 10*20-3*4,   btnY, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add vec3',    8, 10*24-3*5,   btnY, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add vec4',    9, 10*28-3*6,   btnY, btnSzX, 15, WS_VISIBLE
dialogitem      'button', 'add fun',     10, 10*32-3*7,  btnY, btnSzX, 15, WS_VISIBLE

dialogitem      'button', ' file to ptr',    19, 10*28-3*6,   btnY+32, btnSzX+9, 15, WS_VISIBLE

dialogitem      'button', 'fix count',      300, 210,           btnY-38, btnSzX+6, 15, WS_VISIBLE
;static size for string,array,ptrv
dialogitem      'static', 'size:',      7770, 273,           btnY-35, btnSzX, 15, WS_VISIBLE
dialogitem      'combobox', '',      203, 289,           btnY-37, btnSzX*2-11, 120, CBS_AUTOHSCROLL+CBS_DROPDOWN+WS_VSCROLL+WS_VISIBLE+CBS_HASSTRINGS
enddialog

section '.bss' readable writeable
               Status           rb      512*2000
               tmpBufr          rb      1024
               pipBufer         rb      outPipTxtSize
               pEqulistString   rb 1024*80
               tmpFile          rb 1024*80