flat assembler
Message board for the users of flat assembler.

Index > Windows > why i cannot code iczeliion tutorial 19 into shape?

Author
Thread Post new topic Reply to topic
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
tutorial 19 is kinda weird, i really wonder how it could be assembled in masm ?

Code:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comctl32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
.const
IDB_TREE        equ 4006
.data
ClassName       db "TreeViewWinClass",0
AppName                 db "Tree View Demo",0
TreeViewClass   db "SysTreeView32",0
Parent          db "Parent Item",0
Child1          db "child1",0
Child2          db "child2",0
DragMode                dd FALSE

.data?
hInstance               HINSTANCE ?
hwndTreeView    dd ?
hParent         dd ?
hImageList      dd ?
hDragImageList          dd ?

.code
start:
        invoke GetModuleHandle, NULL
        mov    hInstance,eax
        invoke WinMain, hInstance,NULL,NULL, SW_SHOWDEFAULT
        invoke ExitProcess,eax
        invoke InitCommonControls

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
        LOCAL wc:WNDCLASSEX
        LOCAL msg:MSG
        LOCAL hwnd:HWND
        mov   wc.cbSize,SIZEOF WNDCLASSEX
        mov   wc.style, CS_HREDRAW or CS_VREDRAW
        mov   wc.lpfnWndProc, OFFSET WndProc
        mov   wc.cbClsExtra,NULL
        mov   wc.cbWndExtra,NULL
        push  hInst
        pop   wc.hInstance
        mov   wc.hbrBackground,COLOR_APPWORKSPACE
        mov   wc.lpszMenuName,NULL
        mov   wc.lpszClassName,OFFSET ClassName
        invoke LoadIcon,NULL,IDI_APPLICATION
        mov   wc.hIcon,eax
        mov   wc.hIconSm,eax
        invoke LoadCursor,NULL,IDC_ARROW
        mov   wc.hCursor,eax
        invoke RegisterClassEx, addr wc
        invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,CW_USEDEFAULT,\
           CW_USEDEFAULT,200,400,NULL,NULL,\
           hInst,NULL
        mov   hwnd,eax
        .while TRUE
                invoke GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                invoke TranslateMessage, ADDR msg
                invoke DispatchMessage, ADDR msg
        .endw
        mov eax,msg.wParam
        ret
WinMain endp

WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
        LOCAL tvinsert:TV_INSERTSTRUCT
        LOCAL hBitmap:DWORD
        LOCAL tvhit:TV_HITTESTINFO
        .if uMsg==WM_CREATE
                invoke CreateWindowEx,NULL,ADDR TreeViewClass,NULL,\
              WS_CHILD+WS_VISIBLE+TVS_HASLINES+TVS_HASBUTTONS+TVS_LINESATROOT,0,\
                 0,200,400,hWnd,NULL,\
                   hInstance,NULL
                mov hwndTreeView,eax
                invoke ImageList_Create,16,16,ILC_COLOR16,2,10
                mov hImageList,eax
                invoke LoadBitmap,hInstance,IDB_TREE
                mov hBitmap,eax
                invoke ImageList_Add,hImageList,hBitmap,NULL
                invoke DeleteObject,hBitmap
                invoke SendMessage,hwndTreeView,TVM_SETIMAGELIST,0,hImageList
                mov tvinsert.hParent,NULL
                mov tvinsert.hInsertAfter,TVI_ROOT
                mov tvinsert.item.imask,TVIF_TEXT+TVIF_IMAGE+TVIF_SELECTEDIMAGE
                mov tvinsert.item.pszText,offset Parent
                mov tvinsert.item.iImage,0
                mov tvinsert.item.iSelectedImage,1
                invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
                mov hParent,eax
                mov tvinsert.hParent,eax
                mov tvinsert.hInsertAfter,TVI_LAST
                mov tvinsert.item.pszText,offset Child1
                invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
                mov tvinsert.item.pszText,offset Child2
                invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
        .elseif uMsg==WM_MOUSEMOVE
                .if DragMode==TRUE
                        mov eax,lParam
                        and eax,0ffffh
                        mov ecx,lParam
                        shr ecx,16
                        mov tvhit.pt.x,eax      ; eax is the horizontal position of the drag image
                        mov tvhit.pt.y,ecx      ; ecx is the vertical position                  
                        invoke ImageList_DragMove,eax,ecx
                        invoke ImageList_DragShowNolock,FALSE
                        invoke SendMessage,hwndTreeView,TVM_HITTEST,NULL,addr tvhit     ; check if an item is hit
                        .if eax!=NULL
                                invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_DROPHILITE,eax
                        .endif
                        invoke ImageList_DragShowNolock,TRUE
                .endif
        .elseif uMsg==WM_LBUTTONUP
                .if DragMode==TRUE
                        invoke ImageList_DragLeave,hwndTreeView
                        invoke ImageList_EndDrag
                        invoke ImageList_Destroy,hDragImageList
                        invoke SendMessage,hwndTreeView,TVM_GETNEXTITEM,TVGN_DROPHILITE,0       ; Get the currently hilited item
                        invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_CARET,eax
                        invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_DROPHILITE,0
                        invoke ReleaseCapture
                        mov DragMode,FALSE
                .endif
        .elseif uMsg==WM_NOTIFY
                mov edi,lParam
                assume edi:ptr NM_TREEVIEW
                .if [edi].hdr.code==TVN_BEGINDRAG
                        invoke SendMessage,hwndTreeView,TVM_CREATEDRAGIMAGE,0,[edi].itemNew.hItem
                        mov hDragImageList,eax
                        invoke ImageList_BeginDrag,hDragImageList,0,0,0
                        invoke ImageList_DragEnter,hwndTreeView,[edi].ptDrag.x,[edi].ptDrag.y
                        invoke SetCapture,hWnd
                        mov DragMode,TRUE
                .endif
                assume edi:nothing
        .elseif uMsg==WM_DESTROY
                invoke PostQuitMessage,NULL
        .else
                invoke DefWindowProc,hWnd,uMsg,wParam,lParam            
                ret
        .endif
        xor eax,eax
        ret
WndProc endp

end start
    


the translation below won't work :(

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable
        wndH            dd ?
        insH            dd ?
        wndClsName      db 'TUT_19',0
        wndTitle        db 'Tutorial 19',0

        wndCls  WNDCLASS
        wndMsg  MSG
        
        ctlClsNameTv    db 'SysTreeView32',0

        tv1             equ 400
        tv1H            dd ?
        tv1Insert       TVINSERTSTRUCT
        tv1Txt1         db 'Asia',0
        tv1Txt2         db 'Malaysia',0
        tv1Txt3         db 'Singapore',0
        tv1Txt4         db 'Johor',0
        tv1ParentH      dd ?
        tv1HitInfo      TVHITTESTINFO
        
        imgl1H          dd ?
        imgl1Drag       dd FALSE
        imgl1DragH      dd ?                    ;handle for drag image list
        
        bmp1H           dd ?                    ;handle for bitmap image

section '.code' code readable executable
   start:
        invoke  GetModuleHandle,NULL
                mov  [insH],eax
                mov  [wndCls.hInstance],eax
                mov  [wndCls.style],CS_HREDRAW or CS_VREDRAW
                mov  [wndCls.lpfnWndProc],window_procedure
                mov  [wndCls.lpszClassName],wndClsName
                mov  [wndCls.hbrBackground],COLOR_BTNFACE+1
        invoke  LoadIcon,NULL,IDI_APPLICATION
                mov  [wndCls.hIcon],eax
        invoke  LoadCursor,NULL,IDC_ARROW
                mov  [wndCls.hCursor],eax
        invoke  RegisterClass,wndCls

        invoke  CreateWindowEx,WS_EX_CLIENTEDGE,\
                wndClsName,wndTitle,\
                WS_OVERLAPPED + WS_SYSMENU + WS_VISIBLE,\
                CW_USEDEFAULT,CW_USEDEFAULT,\
                220,420,\
                NULL,NULL,[insH],NULL
                mov  [wndH],eax
        
        invoke  InitCommonControls

   ;+---------------------------+
   ;| entering the message loop |
   ;+---------------------------+
   window_message_loop_start:
        invoke  GetMessage,wndMsg,NULL,0,0
                or    eax,eax
                je    window_message_loop_end
        invoke  TranslateMessage,wndMsg
        invoke  DispatchMessage,wndMsg
                jmp     window_message_loop_start

   window_message_loop_end:
        invoke  ExitProcess,0

   ;+----------------------+
   ;| the window procedure |
   ;+----------------------+
   proc window_procedure,hWnd,uMsg,wParam,lParam
                push ebx esi edi
                cmp  [uMsg],WM_CREATE
                je   wmCREATE
                cmp  [uMsg],WM_NOTIFY
                je   wmNOTIFY
                cmp  [uMsg],WM_LBUTTONUP
                je   wmLBUTTONUP
                cmp  [uMsg],WM_MOUSEMOVE
                je   wmMOUSEMOVE
                cmp  [uMsg],WM_DESTROY
                je   wmDESTROY
        
        wmDEFAULT:
                invoke  DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
                        jmp  wmBYE
        wmLBUTTONUP:
                        cmp  [imgl1Drag],TRUE
                        jne  wmBYE
                invoke  ImageList_DragLeave,[tv1H]
                invoke  ImageList_EndDrag
                invoke  ImageList_Destroy,[imgl1H]
                invoke  SendMessage,[tv1H],TVM_GETNEXTITEM,TVGN_DROPHILITE,0
                invoke  SendMessage,[tv1H],TVM_SELECTITEM,TVGN_CARET,eax
                invoke  SendMessage,[tv1H],TVM_SELECTITEM,TVGN_DROPHILITE,0
                invoke  ReleaseCapture
                        mov  [imgl1Drag],FALSE
                        jmp  wmBYE
        wmMOUSEMOVE:
                        cmp  [imgl1Drag],TRUE
                        jne  wmDEFAULT
                        mov  eax,[lParam]
                        add  eax,0xFFFF
                        mov  ecx,[lParam]
                        shr  ecx,16
                        mov  [tv1HitInfo.pt.x],eax
                        mov  [tv1HitInfo.pt.y],ecx
                invoke  ImageList_DragMove,eax,ecx
                invoke  ImageList_DragShowNolock,FALSE
                invoke  SendMessage,[tv1H],TVM_HITTEST,NULL,tv1HitInfo
                        cmp  eax,NULL
                        je   @f
                invoke  SendMessage,[tv1H],TVM_SELECTITEM,TVGN_DROPHILITE,eax
                @@:
                invoke  ImageList_DragShowNolock,TRUE
                        jmp  wmBYE
        wmNOTIFY:
                        mov  edx,[lParam]
                        cmp  [edx + NMTREEVIEW.hdr.idFrom],tv1
                        jne  wmDEFAULT
                        cmp  [edx + NMTREEVIEW.hdr.code],TVN_BEGINDRAG
                        jne  wmDEFAULT
                invoke  SendMessage,[tv1H],TVM_CREATEDRAGIMAGE,0,[edx + NMTREEVIEW.itemNew.hItem]
                        mov  [imgl1DragH],eax
                invoke  ImageList_BeginDrag,eax,0,0,0
                invoke  ImageList_DragEnter,[tv1H],[edx + NMTREEVIEW.ptDrag.x],[edx + NMTREEVIEW.ptDrag.y]
                invoke  SetCapture,[hWnd]
                        mov  [imgl1Drag],TRUE
                        jmp  wmBYE
        wmCREATE:
                invoke  CreateWindowEx,NULL,ctlClsNameTv,NULL,\
                        WS_CHILD + WS_VISIBLE + WS_BORDER + TVS_HASLINES + TVS_HASBUTTONS + TVS_LINESATROOT,\
                        5,5,200,380,[hWnd],tv1,[insH],NULL
                        mov  [tv1H],eax
                invoke  ImageList_Create,16,16,ILC_COLOR16,2,10
                        mov  [imgl1H],eax
                invoke  LoadBitmap,[insH],31
                        mov  [bmp1H],eax
                invoke  ImageList_Add,[imgl1H],[bmp1H],NULL
                invoke  DeleteObject,[bmp1H]
                invoke  SendMessage,[tv1H],TVM_SETIMAGELIST,0,[imgl1H]
                        mov  [tv1Insert.hParent],NULL
                        mov  [tv1Insert.hInsertAfter],TVI_ROOT
                        mov  [tv1Insert.item.mask],TVIF_TEXT + TVIF_IMAGE + TVIF_SELECTEDIMAGE
                        mov  [tv1Insert.item.pszText],tv1Txt1           ;asia
                        mov  [tv1Insert.item.iImage],0
                        mov  [tv1Insert.item.iSelectedImage],1
                invoke  SendMessage,[tv1H],TVM_INSERTITEM,0,tv1Insert
                        mov  [tv1Insert.hParent],eax
                        mov  [tv1Insert.hInsertAfter],TVI_LAST
                        mov  [tv1Insert.item.pszText],tv1Txt2           ;malaysia
                invoke  SendMessage,[tv1H],TVM_INSERTITEM,0,tv1Insert
                        push eax
                        mov  [tv1Insert.item.pszText],tv1Txt3           ;singapore
                invoke  SendMessage,[tv1H],TVM_INSERTITEM,0,tv1Insert
                        pop  [tv1Insert.hParent]
                        mov  [tv1Insert.item.pszText],tv1Txt4           ;johor
                invoke  SendMessage,[tv1H],TVM_INSERTITEM,0,tv1Insert
                        jmp  wmBYE
        wmDESTROY:
                invoke  PostQuitMessage,0

        wmBYE:
                pop edi esi ebx
                return
   endp

section '.idata' import data readable
    library     KERNEL32, 'KERNEL32.DLL',\
                USER32,   'USER32.DLL',\
                GDI32,    'GDI32.DLL',\
                COMCTL32, 'COMCTL32.DLL'
    
    import      KERNEL32,\
                GetModuleHandle,        'GetModuleHandleA',\
                ExitProcess,            'ExitProcess'
    import      USER32,\
                RegisterClass,          'RegisterClassA',\
                CreateWindowEx,         'CreateWindowExA',\
                DefWindowProc,          'DefWindowProcA',\
                LoadCursor,             'LoadCursorA',\
                LoadIcon,               'LoadIconA',\
                LoadBitmap,             'LoadBitmapA',\
                SendMessage,            'SendMessageA',\
                GetMessage,             'GetMessageA',\
                MessageBox,             'MessageBoxA',\
                SetCapture,             'SetCapture',\
                ReleaseCapture,         'ReleaseCapture',\
                DestroyWindow,          'DestroyWindow',\
                TranslateMessage,       'TranslateMessage',\
                DispatchMessage,        'DispatchMessageA',\
                PostQuitMessage,        'PostQuitMessage'
    import      GDI32,\
                DeleteObject,           'DeleteObject'
    import      COMCTL32,\
                InitCommonControls,     'InitCommonControls',\
                ImageList_Create,       'ImageList_Create',\
                ImageList_BeginDrag,    'ImageList_BeginDrag',\
                ImageList_DragEnter,    'ImageList_DragEnter',\
                ImageList_DragLeave,    'ImageList_DragLeave',\
                ImageList_DragMove,     'ImageList_DragMove',\
                ImageList_DragShowNolock,'ImageList_DragShowNolock',\
                ImageList_EndDrag,      'ImageList_EndDrag',\
                ImageList_Destroy,      'ImageList_Destroy',\
                ImageList_AddMasked,    'ImageList_AddMasked',\
                ImageList_Add,          'ImageList_Add'

section '.rsrc' resource data readable
        directory       RT_BITMAP, appBmp
        
        resource        appBmp,\
                        31,LANG_NEUTRAL,bmpA
        
        bitmap          bmpA, 'ico1.bmp'
    
Post 29 Sep 2004, 16:54
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
it didn't work as expected, the problem mainly is
drag and drop, after drag and drop, the image list just didn't want to show the folder. Sad and blank
Post 29 Sep 2004, 16:56
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
the weird thing in the masm code is
Code:
.if [edi].hdr.code==TVN_BEGINDRAG 
...
.endif
    


so, how does the application do the other event notification? coz it didn't send to default proc ?
Post 29 Sep 2004, 16:59
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
ok, finally, i be able to shape it Smile
i am reffering PSDK treeview document when doing this tutorial + iczelion tutorial 19...

following code is treeview control plus masked icon example.

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable
        wndH            dd ?
        insH            dd ?
        wndClsName      db 'TUT_19',0
        wndTitle        db 'Tutorial 19',0

        wndCls  WNDCLASS
        wndMsg  MSG
        
        ctlClsNameTv    db 'SysTreeView32',0
        
        tv1H            dd ?
        tv1Insert       TVINSERTSTRUCT
        tv1HitInfo      TVHITTESTINFO
        tv1Txt1         db 'Node - Parent',0
        tv1Txt2         db 'Node - Child 1',0
        tv1Txt3         db 'Node - Child 2',0
        
        imgl1H          dd ?
        imgl1DragH      dd ?
        imgl1Drag       dd FALSE
        imgl1ItemRect   RECT
        
        bmp1H           dd ?
        
section '.code' code readable executable
   start:
        invoke  GetModuleHandle,0
                mov  [insH],eax
                mov  [wndCls.hInstance],eax
                mov  [wndCls.style],CS_HREDRAW or CS_VREDRAW
                mov  [wndCls.lpfnWndProc],window_procedure
                mov  [wndCls.lpszClassName],wndClsName
                mov  [wndCls.hbrBackground],COLOR_BTNFACE+1
        invoke  LoadIcon,NULL,IDI_APPLICATION
                mov  [wndCls.hIcon],eax
        invoke  LoadCursor,NULL,IDC_ARROW
                mov  [wndCls.hCursor],eax
        invoke  RegisterClass,wndCls

        invoke  CreateWindowEx,WS_EX_CLIENTEDGE,\
                wndClsName,wndTitle,\
                WS_OVERLAPPEDWINDOW + WS_VISIBLE,\
                CW_USEDEFAULT,CW_USEDEFAULT,\
                230,300,\
                NULL,NULL,[insH],NULL
                mov  [wndH],eax
        
        invoke  InitCommonControls

   ;+---------------------------+
   ;| entering the message loop |
   ;+---------------------------+
   window_message_loop_start:
        invoke  GetMessage,wndMsg,NULL,0,0
                or    eax,eax
                je    window_message_loop_end
        invoke  TranslateMessage,wndMsg
        invoke  DispatchMessage,wndMsg
                jmp     window_message_loop_start

   window_message_loop_end:
        invoke  ExitProcess,0

   ;+----------------------+
   ;| the window procedure |
   ;+----------------------+
   proc window_procedure,hWnd,uMsg,wParam,lParam
                push ebx esi edi
                cmp  [uMsg],WM_CREATE
                je   wmCREATE
                cmp  [uMsg],WM_NOTIFY
                je   wmNOTIFY
                cmp  [uMsg],WM_MOUSEMOVE
                je   wmMOUSEMOVE
                cmp  [uMsg],WM_LBUTTONUP
                je   wmLBUTTONUP
                cmp  [uMsg],WM_DESTROY
                je   wmDESTROY
        wmDEFAULT:
                invoke  DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
                        jmp  wmBYE
        wmLBUTTONUP:
                invoke  ImageList_DragLeave,[tv1H]
                invoke  ImageList_EndDrag
                invoke  SendMessage,[tv1H],TVM_GETNEXTITEM,TVGN_DROPHILITE,0
                invoke  SendMessage,[tv1H],TVM_SELECTITEM,TVGN_CARET,eax
                invoke  SendMessage,[tv1H],TVM_SELECTITEM,TVGN_DROPHILITE,NULL
                invoke  ReleaseCapture
                        mov  [imgl1Drag],FALSE
                        jmp  wmBYE
        wmMOUSEMOVE:
                        cmp  [imgl1Drag],TRUE
                        jne  wmDEFAULT
                        mov  eax,[lParam]
                        and  eax,0xFFFF
                        mov  ecx,[lParam]
                        shr  ecx,16
                        mov  [tv1HitInfo.pt.x],eax
                        mov  [tv1HitInfo.pt.y],ecx
                invoke  ImageList_DragMove,eax,ecx
                invoke  ImageList_DragShowNolock,FALSE
                invoke  SendMessage,[tv1H],TVM_HITTEST,0,tv1HitInfo
                        cmp  eax,NULL
                        je   @f
                invoke  SendMessage,[tv1H],TVM_SELECTITEM,TVGN_DROPHILITE,eax
                @@:
                invoke  ImageList_DragShowNolock,TRUE
                        jmp  wmBYE
        wmNOTIFY:
                        mov  edx,[lParam]
                        cmp  [edx + NMTREEVIEW.hdr.code],TVN_BEGINDRAG
                        jne  wmDEFAULT
                invoke  SendMessage,[tv1H],TVM_CREATEDRAGIMAGE,0,[edx + NMTREEVIEW.itemNew.hItem]
                        mov  [imgl1DragH],eax
                invoke  SendMessage,[tv1H],TVM_GETITEMRECT,TRUE,imgl1ItemRect
                invoke  ImageList_BeginDrag,[imgl1DragH],0,0,0
                invoke  ImageList_DragEnter,[tv1H],[edx + NMTREEVIEW.ptDrag.x],[edx + NMTREEVIEW.ptDrag.y]
                invoke  GetParent,[tv1H]
                invoke  SetCapture,eax
                        mov  [imgl1Drag],TRUE
                        jmp  wmBYE
        wmCREATE:
                invoke  CreateWindowEx,NULL,ctlClsNameTv,NULL,\
                        WS_VISIBLE + WS_CHILD + WS_BORDER + TVS_HASBUTTONS + TVS_LINESATROOT + TVS_HASLINES,\
                        10,10,200,250,\
                        [hWnd],NULL,[insH],NULL
                        mov  [tv1H],eax
                ;invoke ImageList_Create,16,16,FALSE,2,10                       ;without mask
                invoke  ImageList_Create,16,16,ILC_COLOR16 + ILC_MASK,2,10      ;with mask
                        mov  [imgl1H],eax
                invoke  LoadBitmap,[insH],31
                        mov  [bmp1H],eax
                ;invoke ImageList_Add,[imgl1H],[bmp1H],NULL                     ;without mask
                invoke  ImageList_AddMasked,[imgl1H],[bmp1H],0x0000FF00         ;with mask
                invoke  DeleteObject,[bmp1H]
                invoke  SendMessage,[tv1H],TVM_SETIMAGELIST,TVSIL_NORMAL,[imgl1H]
                        mov  [tv1Insert.hParent],NULL
                        mov  [tv1Insert.hInsertAfter],TVI_ROOT
                        mov  [tv1Insert.item.mask],TVIF_TEXT+TVIF_IMAGE+TVIF_SELECTEDIMAGE
                        mov  [tv1Insert.item.pszText],tv1Txt1
                        mov  [tv1Insert.item.iImage],0
                        mov  [tv1Insert.item.iSelectedImage],1
                invoke  SendMessage,[tv1H],TVM_INSERTITEM,0,tv1Insert
                        mov  [tv1Insert.hParent],eax
                        mov  [tv1Insert.hInsertAfter],TVI_LAST
                        mov  [tv1Insert.item.pszText],tv1Txt2
                invoke  SendMessage,[tv1H],TVM_INSERTITEM,0,tv1Insert
                        mov  [tv1Insert.item.pszText],tv1Txt3
                invoke  SendMessage,[tv1H],TVM_INSERTITEM,0,tv1Insert
                        jmp  wmBYE
        wmDESTROY:
                invoke  PostQuitMessage,0
        wmBYE:
                pop edi esi ebx
                return
   endp

section '.idata' import data readable
    library     KERNEL32, 'KERNEL32.DLL',\
                USER32,   'USER32.DLL',\
                GDI32,    'GDI32.DLL',\
                COMCTL32, 'COMCTL32.DLL'
    
    import      KERNEL32,\
                GetModuleHandle,        'GetModuleHandleA',\
                ExitProcess,            'ExitProcess'
    import      USER32,\
                RegisterClass,          'RegisterClassA',\
                CreateWindowEx,         'CreateWindowExA',\
                DefWindowProc,          'DefWindowProcA',\
                LoadCursor,             'LoadCursorA',\
                LoadIcon,               'LoadIconA',\
                LoadBitmap,             'LoadBitmapA',\
                SendMessage,            'SendMessageA',\
                GetMessage,             'GetMessageA',\
                MessageBox,             'MessageBoxA',\
                SetCapture,             'SetCapture',\
                ReleaseCapture,         'ReleaseCapture',\
                GetParent,              'GetParent',\
                DestroyWindow,          'DestroyWindow',\
                TranslateMessage,       'TranslateMessage',\
                DispatchMessage,        'DispatchMessageA',\
                PostQuitMessage,        'PostQuitMessage'
    import      GDI32,\
                DeleteObject,           'DeleteObject'
    import      COMCTL32,\
                InitCommonControls,     'InitCommonControls',\
                ImageList_Create,       'ImageList_Create',\
                ImageList_Add,          'ImageList_Add',\
                ImageList_AddMasked,    'ImageList_AddMasked',\
                ImageList_GetImageCount,'ImageList_GetImageCount',\
                ImageList_BeginDrag,    'ImageList_BeginDrag',\
                ImageList_EndDrag,      'ImageList_EndDrag',\
                ImageList_DragEnter,    'ImageList_DragEnter',\
                ImageList_DragMove,     'ImageList_DragMove',\
                ImageList_DragLeave,    'ImageList_DragLeave',\
                ImageList_DragShowNolock,'ImageList_DragShowNolock'
                

section '.rsrc' resource data readable
        directory       RT_BITMAP, appBmp
        
        resource        appBmp,\
                        31,LANG_NEUTRAL,bmpA
        
        bitmap          bmpA, 'ico1.bmp'
    
Post 30 Sep 2004, 09:46
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
vbVeryBeginner, you don't need to convert local variables to global ones. It is a very good practice to use local variables to encapsulate procedures, avoiding external dependencies. (imho even the hwndTreeView shouldn't be global, but Iczelion chosen that way)
Code:
;Masm:
invoke SendMessage,hwndTreeView,TVM_HITTEST,NULL,addr tvhit

;Fasm:
lea eax,[.tvhit]
invoke SendMessage,hwndTreeView,TVM_HITTEST,NULL,eax
    


That's exactly the same thing Masm does when assembling, but Fasm lets you decide how to do it and when.
Post 30 Sep 2004, 12:51
View user's profile Send private message Yahoo Messenger Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
pelaillo wrote:

you don't need to convert local variables to global ones


hi pelaillo, what do you mean by "local variable?"
does ya mean to have variable in my '.code' section?
or using the .variable (dot) or something else?
Post 30 Sep 2004, 13:04
View user's profile Send private message Visit poster's website Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
local variables are variable that are only accessable by the proc and the data is cleared or might be cleared while the code leaves the proc as local variables are part of the stack...
Post 30 Sep 2004, 13:27
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
Before calling a procedure, you push the arguments' values into the stack in order to have them available. Values will be at stack pointer plus a certain offset:
Code:
05504244:  1074317760  RETURN <<ebp
05504248:  0000000168  hwnd    <<[ebp+4]
05504252:  0000000015  msg
05504256:  0000000000  wparam
05504260:  0000000000  lparam
    


The same mechanism is used for local variables, but using negative offsets, i.e. [ebp-4] depending on the size of each variable. i.e. as TV_HITTESTINFO size is 48 bytes, you will access it at [ebp-48]

However, the best part is that you don't need to worry about it. It is all managed by Fasm through the proc macro.

This is the Masm source
Code:
WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM 
        LOCAL tvinsert:TV_INSERTSTRUCT 
        LOCAL hBitmap:DWORD 
        LOCAL tvhit:TV_HITTESTINFO 
        .if uMsg==WM_CREATE 
    


Translated to Fasm:
Code:
   proc window_procedure,hWnd,uMsg,wParam,lParam 
         .tvinsert TV_INSERTSTRUCT
         .hBitmap dd ?
         .tvhit TV_HITTESTINFO
       enter
                push ebx esi edi 
                cmp  [uMsg],WM_CREATE 
                je   wmCREATE 
    
Post 30 Sep 2004, 18:19
View user's profile Send private message Yahoo Messenger Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
thanks pelaillo, i will use such approach in the future tutorial Smile thanks

sincerely,
vbVeryBeginner d(^<>^)b
Post 01 Oct 2004, 04:46
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.