鱼C论坛

 找回密码
 立即注册
查看: 2670|回复: 5

[争议讨论] 整段代码,能看懂的站内联系,交流学习

[复制链接]
发表于 2012-3-11 21:34:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. .386
  2. .model flat,stdcall
  3. option casemap:none
  4. include \masm32\include\windows.inc
  5. include \masm32\include\user32.inc
  6. include \masm32\include\kernel32.inc
  7. include \masm32\include\comctl32.inc
  8. include \masm32\include\gdi32.inc
  9. includelib \masm32\lib\gdi32.lib
  10. includelib \masm32\lib\comctl32.lib
  11. includelib \masm32\lib\user32.lib
  12. includelib \masm32\lib\kernel32.lib
  13. WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
  14. .const
  15. IDB_TREE equ 4006                ; ID of the bitmap resource
  16. .data
  17. ClassName  db "TreeViewWinClass",0
  18. AppName    db "Tree View Demo",0
  19. TreeViewClass  db "SysTreeView32",0
  20. Parent  db "Parent Item",0
  21. Child1  db "child1",0
  22. Child2  db "child2",0
  23. DragMode  dd FALSE                ; a flag to determine if we are in drag mode

  24. .data?
  25. hInstance  HINSTANCE ?
  26. hwndTreeView dd ?            ; handle of the tree view control
  27. hParent  dd ?                        ; handle of the root tree view item
  28. hImageList dd ?                    ; handle of the image list used in the tree view control
  29. hDragImageList  dd ?        ; handle of the image list used to store the drag image

  30. .code
  31. start:
  32.     invoke GetModuleHandle, NULL
  33.     mov    hInstance,eax
  34.     invoke WinMain, hInstance,NULL,NULL, SW_SHOWDEFAULT
  35.     invoke ExitProcess,eax
  36.     invoke InitCommonControls

  37. WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
  38.     LOCAL wc:WNDCLASSEX
  39.     LOCAL msg:MSG
  40.     LOCAL hwnd:HWND
  41.     mov   wc.cbSize,SIZEOF WNDCLASSEX
  42.     mov   wc.style, CS_HREDRAW or CS_VREDRAW
  43.     mov   wc.lpfnWndProc, OFFSET WndProc
  44.     mov   wc.cbClsExtra,NULL
  45.     mov   wc.cbWndExtra,NULL
  46.     push  hInst
  47.     pop   wc.hInstance
  48.     mov   wc.hbrBackground,COLOR_APPWORKSPACE
  49.     mov   wc.lpszMenuName,NULL
  50.     mov   wc.lpszClassName,OFFSET ClassName
  51.     invoke LoadIcon,NULL,IDI_APPLICATION
  52.     mov   wc.hIcon,eax
  53.     mov   wc.hIconSm,eax
  54.     invoke LoadCursor,NULL,IDC_ARROW
  55.     mov   wc.hCursor,eax
  56.     invoke RegisterClassEx, addr wc
  57.     invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName,ADDR AppName,\           WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,CW_USEDEFAULT,\
  58.            CW_USEDEFAULT,200,400,NULL,NULL,\
  59.            hInst,NULL
  60.     mov   hwnd,eax
  61.     .while TRUE
  62.         invoke GetMessage, ADDR msg,NULL,0,0
  63.         .BREAK .IF (!eax)
  64.         invoke TranslateMessage, ADDR msg
  65.         invoke DispatchMessage, ADDR msg
  66.     .endw
  67.     mov eax,msg.wParam
  68.     ret
  69. WinMain endp

  70. WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
  71.     LOCAL tvinsert:TV_INSERTSTRUCT
  72.     LOCAL hBitmap:DWORD
  73.     LOCAL tvhit:TV_HITTESTINFO
  74.     .if uMsg==WM_CREATE
  75.         invoke CreateWindowEx,NULL,ADDR TreeViewClass,NULL,\
  76.             WS_CHILD+WS_VISIBLE+TVS_HASLINES+TVS_HASBUTTONS+TVS_LINESATROOT,0,\
  77.             0,200,400,hWnd,NULL,\
  78.             hInstance,NULL            ; Create the tree view control
  79.         mov hwndTreeView,eax
  80.         invoke ImageList_Create,16,16,ILC_COLOR16,2,10    ; create the associated image list
  81.         mov hImageList,eax
  82.         invoke LoadBitmap,hInstance,IDB_TREE        ; load the bitmap from the resource
  83.         mov hBitmap,eax
  84.         invoke ImageList_Add,hImageList,hBitmap,NULL    ; Add the bitmap into the image list
  85.         invoke DeleteObject,hBitmap    ; always delete the bitmap resource
  86.         invoke SendMessage,hwndTreeView,TVM_SETIMAGELIST,0,hImageList
  87.         mov tvinsert.hParent,NULL
  88.         mov tvinsert.hInsertAfter,TVI_ROOT
  89.         mov tvinsert.item.imask,TVIF_TEXT+TVIF_IMAGE+TVIF_SELECTEDIMAGE
  90.         mov tvinsert.item.pszText,offset Parent
  91.         mov tvinsert.item.iImage,0
  92.         mov tvinsert.item.iSelectedImage,1
  93.         invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
  94.         mov hParent,eax
  95.         mov tvinsert.hParent,eax
  96.         mov tvinsert.hInsertAfter,TVI_LAST
  97.         mov tvinsert.item.pszText,offset Child1
  98.         invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
  99.         mov tvinsert.item.pszText,offset Child2
  100.         invoke SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert
  101.     .elseif uMsg==WM_MOUSEMOVE
  102.         .if DragMode==TRUE
  103.             mov eax,lParam
  104.             and eax,0ffffh
  105.             mov ecx,lParam
  106.             shr ecx,16
  107.             mov tvhit.pt.x,eax
  108.             mov tvhit.pt.y,ecx
  109.             invoke ImageList_DragMove,eax,ecx
  110.             invoke ImageList_DragShowNolock,FALSE
  111.             invoke SendMessage,hwndTreeView,TVM_HITTEST,NULL,addr tvhit
  112.             .if eax!=NULL
  113.                 invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_DROPHILITE,eax
  114.             .endif
  115.             invoke ImageList_DragShowNolock,TRUE
  116.         .endif
  117.     .elseif uMsg==WM_LBUTTONUP
  118.         .if DragMode==TRUE
  119.             invoke ImageList_DragLeave,hwndTreeView
  120.             invoke ImageList_EndDrag
  121.             invoke ImageList_Destroy,hDragImageList
  122.             invoke SendMessage,hwndTreeView,TVM_GETNEXTITEM,TVGN_DROPHILITE,0
  123.             invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_CARET,eax
  124.             invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_DROPHILITE,0
  125.             invoke ReleaseCapture
  126.             mov DragMode,FALSE
  127.         .endif
  128.     .elseif uMsg==WM_NOTIFY
  129.         mov edi,lParam
  130.         assume edi:ptr NM_TREEVIEW
  131.         .if [edi].hdr.code==TVN_BEGINDRAG
  132.             invoke SendMessage,hwndTreeView,TVM_CREATEDRAGIMAGE,0,[edi].itemNew.hItem
  133.             mov hDragImageList,eax
  134.             invoke ImageList_BeginDrag,hDragImageList,0,0,0
  135.             invoke ImageList_DragEnter,hwndTreeView,[edi].ptDrag.x,[edi].ptDrag.y
  136.             invoke SetCapture,hWnd
  137.             mov DragMode,TRUE
  138.         .endif
  139.         assume edi:nothing
  140.     .elseif uMsg==WM_DESTROY
  141.         invoke PostQuitMessage,NULL
  142.     .else
  143.         invoke DefWindowProc,hWnd,uMsg,wParam,lParam
  144.         ret
  145.     .endif
  146.     xor eax,eax
  147.     ret
  148. WndProc endp
  149. end start
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-3-13 06:06:10 | 显示全部楼层
居然学神语…
佩服…
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-3-13 08:19:45 | 显示全部楼层
之认识几个单词:D
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-3-13 21:32:16 | 显示全部楼层
求教这个是什么:dizzy:
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-3-13 22:31:18 | 显示全部楼层
windows下的汇编刚熟悉,暂时还看不懂。。。
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-12-18 19:51:48 | 显示全部楼层
是一个教你做下拉框的 代码例程
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-7 11:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表