flat assembler
Message board for the users of flat assembler.
Index
> Windows > why i cannot code iczeliion tutorial 19 into shape? |
Author |
|
vbVeryBeginner 29 Sep 2004, 16:56
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. and blank |
|||
29 Sep 2004, 16:56 |
|
vbVeryBeginner 29 Sep 2004, 16:59
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 ? |
|||
29 Sep 2004, 16:59 |
|
vbVeryBeginner 30 Sep 2004, 09:46
ok, finally, i be able to shape it
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' |
|||
30 Sep 2004, 09:46 |
|
pelaillo 30 Sep 2004, 12:51
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. |
|||
30 Sep 2004, 12:51 |
|
vbVeryBeginner 30 Sep 2004, 13:04
pelaillo wrote:
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? |
|||
30 Sep 2004, 13:04 |
|
roticv 30 Sep 2004, 13:27
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...
|
|||
30 Sep 2004, 13:27 |
|
pelaillo 30 Sep 2004, 18:19
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 |
|||
30 Sep 2004, 18:19 |
|
vbVeryBeginner 01 Oct 2004, 04:46
thanks pelaillo, i will use such approach in the future tutorial thanks
sincerely, vbVeryBeginner d(^<>^)b |
|||
01 Oct 2004, 04:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.