?? lion-tut-c19.htm
字號:
<H3><FONT color=#ff0000>例子代碼:</FONT></H3><B>.386</B> <BR><B>.model
flat,stdcall</B> <BR><B>option casemap:none</B> <BR><B>include
\masm32\include\windows.inc</B> <BR><B>include \masm32\include\user32.inc</B>
<BR><B>include \masm32\include\kernel32.inc</B> <BR><B>include
\masm32\include\comctl32.inc</B> <BR><B>include \masm32\include\gdi32.inc</B>
<BR><B>includelib \masm32\lib\gdi32.lib</B> <BR><B>includelib
\masm32\lib\comctl32.lib</B> <BR><B>includelib \masm32\lib\user32.lib</B>
<BR><B>includelib \masm32\lib\kernel32.lib</B>
<P><B>WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD</B> <BR><B>.const</B>
<BR><B>IDB_TREE equ
4006
; ID of the bitmap resource</B> <BR><B>.data</B> <BR><B>ClassName db
"TreeViewWinClass",0</B> <BR><B>AppName db "Tree View
Demo",0</B> <BR><B>TreeViewClass db "SysTreeView32",0</B>
<BR><B>Parent db "Parent Item",0</B> <BR><B>Child1 db "child1",0</B>
<BR><B>Child2 db "child2",0</B> <BR><B>DragMode dd
FALSE
; a flag to determine if we are in drag mode</B>
<P><B>.data?</B> <BR><B>hInstance HINSTANCE ?</B> <BR><B>hwndTreeView dd
? ; handle of
the tree view control</B> <BR><B>hParent dd
?
; handle of the root tree view item</B> <BR><B>hImageList dd
?
; handle of the image list used in the tree view control</B>
<BR><B>hDragImageList dd ? ;
handle of the image list used to store the drag image</B>
<P><B>.code</B> <BR><B>start:</B> <BR><B> invoke
GetModuleHandle, NULL</B> <BR><B> mov
hInstance,eax</B> <BR><B> invoke WinMain, hInstance,NULL,NULL,
SW_SHOWDEFAULT</B> <BR><B> invoke ExitProcess,eax</B>
<BR><B> invoke InitCommonControls</B>
<P><B>WinMain proc
hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD</B>
<BR><B> LOCAL wc:WNDCLASSEX</B> <BR><B>
LOCAL msg:MSG</B> <BR><B> LOCAL hwnd:HWND</B>
<BR><B> mov wc.cbSize,SIZEOF WNDCLASSEX</B>
<BR><B> mov wc.style, CS_HREDRAW or CS_VREDRAW</B>
<BR><B> mov wc.lpfnWndProc, OFFSET WndProc</B>
<BR><B> mov wc.cbClsExtra,NULL</B>
<BR><B> mov wc.cbWndExtra,NULL</B>
<BR><B> push hInst</B> <BR><B>
pop wc.hInstance</B> <BR><B> mov
wc.hbrBackground,COLOR_APPWORKSPACE</B> <BR><B>
mov wc.lpszMenuName,NULL</B> <BR><B>
mov wc.lpszClassName,OFFSET ClassName</B> <BR><B>
invoke LoadIcon,NULL,IDI_APPLICATION</B> <BR><B>
mov wc.hIcon,eax</B> <BR><B> mov
wc.hIconSm,eax</B> <BR><B> invoke
LoadCursor,NULL,IDC_ARROW</B> <BR><B> mov
wc.hCursor,eax</B> <BR><B> invoke RegisterClassEx, addr wc</B>
<BR><B> invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR
ClassName,ADDR
AppName,\
WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,CW_USEDEFAULT,\</B>
<BR><B>
CW_USEDEFAULT,200,400,NULL,NULL,\</B>
<BR><B>
hInst,NULL</B> <BR><B> mov hwnd,eax</B>
<BR><B> .while TRUE</B>
<BR><B> invoke GetMessage, ADDR
msg,NULL,0,0</B> <BR><B> .BREAK .IF
(!eax)</B> <BR><B> invoke
TranslateMessage, ADDR msg</B> <BR><B>
invoke DispatchMessage, ADDR msg</B> <BR><B> .endw</B>
<BR><B> mov eax,msg.wParam</B> <BR><B>
ret</B> <BR><B>WinMain endp</B>
<P><B>WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM,
lParam:LPARAM</B> <BR><B> LOCAL tvinsert:TV_INSERTSTRUCT</B>
<BR><B> LOCAL hBitmap:DWORD</B> <BR><B>
LOCAL tvhit:TV_HITTESTINFO</B> <BR><B> .if uMsg==WM_CREATE</B>
<BR><B> invoke
CreateWindowEx,NULL,ADDR TreeViewClass,NULL,\</B>
<BR><B>
WS_CHILD+WS_VISIBLE+TVS_HASLINES+TVS_HASBUTTONS+TVS_LINESATROOT,0,\</B>
<BR><B>
0,200,400,hWnd,NULL,\</B>
<BR><B>
hInstance,NULL
; Create the tree view control</B>
<BR><B> mov hwndTreeView,eax</B>
<BR><B> invoke
ImageList_Create,16,16,ILC_COLOR16,2,10 ; create the
associated image list</B> <BR><B> mov
hImageList,eax</B> <BR><B> invoke
LoadBitmap,hInstance,IDB_TREE ; load
the bitmap from the resource</B>
<BR><B> mov hBitmap,eax</B>
<BR><B> invoke
ImageList_Add,hImageList,hBitmap,NULL ; Add the bitmap into
the image list</B> <BR><B> invoke
DeleteObject,hBitmap ; always delete the bitmap resource</B>
<BR><B> invoke
SendMessage,hwndTreeView,TVM_SETIMAGELIST,0,hImageList</B>
<BR><B> mov tvinsert.hParent,NULL</B>
<BR><B> mov
tvinsert.hInsertAfter,TVI_ROOT</B>
<BR><B> mov
tvinsert.item.imask,TVIF_TEXT+TVIF_IMAGE+TVIF_SELECTEDIMAGE</B>
<BR><B> mov
tvinsert.item.pszText,offset Parent</B>
<BR><B> mov tvinsert.item.iImage,0</B>
<BR><B> mov
tvinsert.item.iSelectedImage,1</B>
<BR><B> invoke
SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert</B>
<BR><B> mov hParent,eax</B>
<BR><B> mov tvinsert.hParent,eax</B>
<BR><B> mov
tvinsert.hInsertAfter,TVI_LAST</B>
<BR><B> mov
tvinsert.item.pszText,offset Child1</B>
<BR><B> invoke
SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert</B>
<BR><B> mov
tvinsert.item.pszText,offset Child2</B>
<BR><B> invoke
SendMessage,hwndTreeView,TVM_INSERTITEM,0,addr tvinsert</B>
<BR><B> .elseif uMsg==WM_MOUSEMOVE</B>
<BR><B> .if DragMode==TRUE</B>
<BR><B> mov
eax,lParam</B>
<BR><B> and
eax,0ffffh</B>
<BR><B> mov
ecx,lParam</B>
<BR><B> shr
ecx,16</B>
<BR><B> mov
tvhit.pt.x,eax</B>
<BR><B> mov
tvhit.pt.y,ecx</B>
<BR><B> invoke
ImageList_DragMove,eax,ecx</B>
<BR><B> invoke
ImageList_DragShowNolock,FALSE</B>
<BR><B> invoke
SendMessage,hwndTreeView,TVM_HITTEST,NULL,addr tvhit</B>
<BR><B> .if
eax!=NULL</B>
<BR><B>
invoke SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_DROPHILITE,eax</B>
<BR><B>
.endif</B>
<BR><B> invoke
ImageList_DragShowNolock,TRUE</B>
<BR><B> .endif</B>
<BR><B> .elseif uMsg==WM_LBUTTONUP</B>
<BR><B> .if DragMode==TRUE</B>
<BR><B> invoke
ImageList_DragLeave,hwndTreeView</B>
<BR><B> invoke
ImageList_EndDrag</B>
<BR><B> invoke
ImageList_Destroy,hDragImageList</B>
<BR><B> invoke
SendMessage,hwndTreeView,TVM_GETNEXTITEM,TVGN_DROPHILITE,0</B>
<BR><B> invoke
SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_CARET,eax</B>
<BR><B> invoke
SendMessage,hwndTreeView,TVM_SELECTITEM,TVGN_DROPHILITE,0</B>
<BR><B> invoke
ReleaseCapture</B>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -