Tutorial 19: Tree View Control
In this Tutorial, We Well Learn How to Use Tree View Control. Moreover, WE Will Also Learn How to Do Drag and Drop Under Tree View Control and how to use an image list with it.
Download the Example
Here.
Theory: A tree view control is a special kind of window that represents objects in hierarchical order An example of it is the left pane of Windows Explorer You can use this control to show relationships between objects...
You can create a tree view control by calling CreateWindowEx, passing "SysTreeView32" as the class name or you can incorporate it into a dialog box. Do not forget to put InitCommonControls call in your code.
There Are Several Styles Specific to The Tree View Control. These Three Are The One ones Mostly Used.
TVS_HASBUTTONS == Displays plus ( ) and minus (-) buttons next to parent items The user clicks the buttons to expand or collapse a parent item's list of child items To include buttons with items at the root of the tree view, TVS_LINESATROOT.. Must also be specified.
Tvs_haslines == Uses Lines to show the hierarchy of items.
Tvs_LinesTroot == Uses Lines to link items at the root of the tree-view control. This value is ignored if tvs_haslines is not also specified.
The tree view control, like other common controls, communicates with the parent window via messages. The parent window can send various messages to it and the tree view control can send "notification" messages to its parent window. In this regard, the tree view Control Is Not Different That ANY WINDOW.
When Something Interesting Occurs to It, IT Sends A
WM_Notify Message to the Parent Window with Accompany Information.
WM_NOTIFY
WPARAM == Control ID, this value is not guaranteed to be unique so we don't use it.instead, we use hwndfrom or idfrom member of the nmhdr structure
Pointed to by lparam
LPARAM == Pointer to NMHDR Structure. Some Controls May Pass A Pointer To Larger
Structure But IT Must Have A NMHDR Structure As ITS First Member.
That Is, When you have lparam, you can be sure that it points to a
NMHDR Structure At Least.
Next We will Examine NmHDR Structure.
NMHDR Struct DWORD
HWNDFROM DWORD?
IDFROM DWORD?
Code DWORD?
NMHDR ENDS
HWndfrom is The window dending handle of the control tria sends this
WM_NOTIFY Message.
Idfrom is the control id of the control trus sends this wm_notify message.
Code Is The Actual Message The Control Wants To Send To The Parent Window.
Tree View Notifications Are Those with TVn_ at The Beginning of The Name. Tree View Messages Are Those with TVM_, Like
Tvm_createdragimage. The Tree View Control Sends TVN_xxxx in The Code Member of NMHDR. The Parent Window CAN Send TVM_XXXX TO Control IT.
Adding items to a tree view controlafter you create a tree view control, you can do it, you can do this by sending
TVM_INSERTITEM TO IT.
TVM_INSERTITEM
WPARAM = 0;
LPARAM = POINTER TO A TV_INSERTSTRUCT;
You Should Know Some Terminology at this Point About The Relationship Between Items in The Tree View Control.
An Item Can Be Parent, Child, or Both At the Same Time. A Parent Item Is The Item That Has Some Other Subitem (s) associated with it. At the Same Time, The Parent Item May Be a child of some. An Item WITHOUT ITET IS CALED A ROOT ITEM. There Can Be Many Root Items in A Tree View Control. Now We Examine
TV_INSERTSTRUCT STRUCTUCTV_INSERTSTRUCT STRUCT DWORD
HParent DWORD?
HinsetAfter DWORD?
ItemType <>
TV_INSERTSTRUCT ENDS
HParent = handle to the parent item. if this member is the
TVi_Root Value or Null, The item is inserated at the root of the tree-view control.
Hinsertafter = Handle to the item for which the new item is to be inserted or one of the folly value:
Tvi_first ==> Inserts The item at the beginning of the list. TVi_last ==> Inserts the item at the end of the list. TVi_sort ==> Inserts the item Into the list in alphabetical order.
ItemType Union
ItemEX TViteMex <>
Item TVItem <>
ItemType Ends
We will use only TVItem.
TV_Item Struct DWORD
IMASK DWORD?
HITEM DWORD?
State DWord?
STATEMASK DWORD?
PSZTEXT DWORD?
CCHTEXTMAX DWORD?
IIMAGE DWORD?
ISELECTEDIMAGE DWORD?
CCHildren DWORD?
LPARAM DWORD?
TV_Item Ends
THIS STRUCTURE IS USED TO Send and Receive Info About a Tree View Item, Depending On Messages. For Example, with
TVM_INSERTITEM, IT IS Used to Specify The Attribute of The Item To BE Inserted Into The Tree View Control. With
TVM_Getitem, It'll Be Filled With Information About The SELECTED TREE VIEW ITEM.
iMask is buy to specify which member (s) of the
TV_Item structure is (all) valid. For example, if The value in iMask is
TVIF_Text, IT Means Only The Psztext Member IS Valid. You CAN Combine Several Flags Together.
hItem is the handle to the tree view item. Each item has its own handle, like a window handle. If you want to do something with an item, you must select it by its handle.pszText is the pointer to a null-terminated string That is the lael of the tree view item.
cchTextMax is used only when you want to retrieve the label of the tree view item. Because you will supply the pointer to the buffer in pszText, Windows has to know the size of the provided buffer. You have to give the size of the buffer in This MEMBER.
IIMAGE AND
iSelectedImage refers to the index into an image list that contains the images to be shown when the item is not selected and when it's selected. If you recall Windows Explorer left pane, the folder images are specified by these two members.
In ORDER TO INSERT An Item Into The Tree View Control, You Must At Least Fill In The Hparent, Hinsertafter and You Should Fill iMask and Psztext Members as Well.
Adding images to the tree view controlIf you want to put an image to the left of the tree view item's label, you have to create an image list and associate it with the tree view control. You can create an image list by calling
Imagelist_create.
ImageList_create Proto CX: DWORD, CY: DWORD, FLAGS: DWORD, /
Cinitial: DWORD, CGROW: DWORD
This function returns the handle to an empty image list if successful.
Cx == Width of Each In this Image List, in Pixels.
cy == height of each image in this image list, in pixels. Every image in an image list must be equal to each other in size. If you specify a large bitmap, Windows will use cx and cy to * cut * it into several ..................
flags == specify the type of images in this image list whether they are color or monochrome and their color depth. Consult your win32 api reference for more detailcInitial == The number of images that this image list will initially contain. Windows will use this info TO Allocate Memory for the images.
cGrow == Amount of images by which the image list can grow when the system needs to resize the list to make room for new images. This parameter represents the number of new images that the resized image list can contain.
An Image List is not a window! It's only an image depositphotos us. Other windows.
After An Image List is created, you can add images to it by calling
ImageList_add
ImageList_add Proto HiMl: DWORD, HBMIMAGE: DWORD, HBMMASK: DWORD
This function returns -1 if unsuccessful.
HiML == The Handle of the Image List You Want To Add Images to. It is the value returned by a successful caver
ImageList_create
HBMIMAGE == The Handle to the bitmap to be added to the image list. You Usually Store The Bitmap in The Resource and Load IT with
Loadbitmap Call. Note That You don't have to specify the number of images information is inferred from cx and cy parameters passed to
ImageList_create call.
Hbmmask == handle to the bitmap what contains the mask. if no mask is buyid with the image list, this parameter is ignored.
Normally, We Well Add Only Two Images to the Image List for Use with the tree view control: one this used deslected, and the Other ghen the item is self.
When the Image List is Ready, you associate it with the tree view control by sending
TVM_SetImagelist to the tree view control.tvm_setimagelist
WPARAM = Type of Image List to set. There is the are two choices:
TVSIL_NORMAL Set the normal image list, which contains the selected and unselected images for the tree-view item. TVSIL_STATE Set the state image list, which contains the images for tree-view items that are in a user-defined state.
LParam = Handle to the Image List
Retrieve The Info About Tree View ItemYou Can Retrieve The Information About a Tree View Item by Sending
TVM_GetItem Message.
TVM_GetItem
WPARAM = 0
LParam = Pointer to the TV_Item Structure to Be Filled with the information
Before you send this message, you must fill imask message with the flag (s) That specifies which member (s) of
TV_ITEM you want Windows to fill And most importantly, you must fill hItem with the handle to the item you want to get information from And this poses a problem:.. How can you know the handle of the item you want to retrieve info from? Will You Have to Store All Tree View Handles?
The answer is quite simple: you don't have to. You can send
TVM_GETNEXTITEM message to the tree view control to retrieve the handle to the tree view item that has the attribute (s) you specified. For example, you can query the handle of the first child item, the root item, the selected item, and so ON.
TVM_GetNextItem
WPARAM = Flag
LPARAM = Handle to a tree view item (ONLY Necessary for Some Flag Values)
The value in wparam is Very Important SO i Present All The Flags Below:
TVGN_CARET Retrieves the currently selected item. TVGN_CHILD Retrieves the first child item of the item specified by the hitem parameter TVGN_DROPHILITE Retrieves the item that is the target of a drag-and-drop operation. TVGN_FIRSTVISIBLE Retrieves the first visible item. TVGN_NEXT Retrieves the next sibling item. TVGN_NEXTVISIBLE Retrieves the next visible item that follows the specified item. The specified item must be visible. Use the TVM_GETITEMRECT message to determine whether an item is visible. TVGN_PARENT Retrieves the parent of the specified item. TVGN_PREVIOUS Retrieves the previous sibling item. TVGN_PREVIOUSVISIBLE Retrieves the first visible item that precedes the specified item. The specified item must be visible. Use the TVM_GETITEMRECT message to determine whether an item is visible. TVGN_ROOT Retrieves the topmost or very first item of the tree-view control.You can see that, You Can Retrieve The Handle to The Tree View Item You Are Interested In from this message.
SendMessage Returns The Handle To The Tree View Item IFE Successful. You Can Then Fill The Returned Handle Into Hitem Member of
TV_Item to Be buy with
TVM_GetItem Message.
Drag and Drop Operation in tree view controlThis part is the reason I decided to write this tutorial. When I tried to follow the example in win32 api reference (the win32.hlp from InPrise), I was very frustrated because the vital information is lacking. From Trial and Error, I Finally Figure, Tree View Control and i don't want, control and walk the same path as myself.
BELOW Is The Steps in IMPLEMENTING DRAG & DROP OPERATION IN A TREE View Control.
When the user tries to drag an item, the tree view control sends TVN_BEGINDRAG notification to the parent window. You can use this opportunity to create a drag image which is the image that will be used to represent the item while it's being dragged. You can send TVM_CREATEDRAGIMAGE to the tree view control to tell it to create a default drag image from the image that is currently used by the item that will be dragged. The tree view control will create an image list with just one drag image and return the handle to That Image List to you. after the drag image is created, you specify the hotspot of the Drag Image by calling imagelist_begindrag.imagelist_begindrag proto himltrack: dword, /
Itrack: DWORD, /
Dxhotspot: DWORD, /
DYHOTSPOT: DWORD
HiMLTRACK is The Handle to The Image List That Contains The Drag Image.
Itrack Is The Index Into The Image List That Specifier The Drag Image
dxHotspot specifies the relative distance of the hotspot in horizontal plance in the drag image since this image will be used in place of the mouse cursor, so we need to specify which part of the image is the hotspot.
DYHOTSPOT Specifies The Relative Distance of The Hotspot in The Vertical Plane.
Normally, Itrack Would Be 0 if you tell the tree for you. And dxhotspot and Dyhotspot Can Be 0 if You Want the Left Upper Corner of the Drag Image to Be The Hotspot.
.
ImageList_Dragenter Proto Hwndlock: DWORD, X: DWORD, Y: DWORD
.
x and y are the x-and y-coordinate of the place where the drag image should be initially displayed. Note that these values are relative to the left upper corner of the window, not the client area.Now that the drag image is displayed on the window, you will have to support the drag operation in the tree view control. However, there is a little problem here. We have to monitor the drag path with WM_MOUSEMOVE and the drop location with WM_LBUTTONUP messages. However, if the drag image is over some other child windows, the parent window will never receive any mouse message. The solution is to capture the mouse input with SetCapture. Using the call, the mouse messages will be directed to the specified window regardless of where the mouse cursor is. Within WM_MOUSEMOVE handler, you will update the drag path with ImageList_DragMove call. This function moves the image that is being dragged during a drag-and-drop operation. Furthermore, if you so desire, you can hilite the item that the drag im age is over by sending TVM_HITTEST to check if the drag image is over some item. If it is, you can send TVM_SELECTITEM with TVGN_DROPHILITE flag to hilite that item. Note that before sending TVM_SELECTITEM message, you must hide the drag image first else your drag image will leave ugly traces. you can hide the drag image by calling ImageList_DragShowNolock and, after the hilite operation is finished, call ImageList_DragShowNolock again to show the drag image. When the user releases the left mouse button, you must do several things. If you Hilite An ITEM, You Must Un-Hilite It by Sending TV_SelectItem with TVGN_Drophilite Flag Again, But this Time, LPARAM MUST BE ZERO. IF YOU DON '
t un-hilite the item, you will get a strange effect:. when you select some other item, that item will be enclosed by a rectangle but the hilite will still be on the last hilited item Next, you must call ImageList_DragLeave followed by ImageList_EndDrag . you must release the mouse by calling ReleaseCapture. If you create an image list, you must destroy it by calling ImageList_Destroy. After that, you can go on with what your program wants to do when the drag & drop operation is completed.Code sample :
.386
.Model flat, stdcall
Option CaseMAP: NONE
INCLUDE /MASM32/INCLUDE/Windows.inc
INCLUDE /MASM32/INCLUDE/USER32.INC
INCLUDE /MASM32/INCLUDE / WANEL32.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; ID of the bitmap resource .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; A Flag To Dermine IF WE Are IN Drag Mode
? .Data hInstance HINSTANCE hwndTreeView dd;?? Handle of the tree view control hParent dd;? Handle of the root tree view item hImageList dd;? Handle of the image list used in the tree view control hDragImageList dd;? Handle of the image List buy to store the Drag Image
.code start: invoke GetModuleHandle, NULL mov hInstance, eax invoke WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT invoke ExitProcess, eax invoke InitCommonControlsWinMain 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_MAXIMIMIZEBOX 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; Create the tree view control mov hwndTreeView, eax invoke ImageList_Create, 16,16, ILC_COLOR16,2,10; create the associated image list mov hImageList, eax invoke LoadBitmap, hInstance, IDB_TREE; load the bitmap from the resource mov hBitmap, eax invoke ImageList_Add, hImageList, hBitmap, NULL; Add the bitmap into the image list invoke DeleteObject, hBitmap; always delete the bitmap resource invoke SendMessage, hwndTreeView , TVM_setimagelist, 0, Himagelist Mov Tvinsert.hparent, Null Mov Tvinsert.hinsertafter, TV I_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 mov tvhit.pt.y, ecx invoke ImageList_DragMove, eax, ecx invoke ImageList_DragShowNolock, FALSE invoke SendMessage, hwndTreeView, TVM_HITTEST, NULL, addr tvhit .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 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 startAnalysis: Within WM_CREATE handler, you create the tree view control
Invoke CreateWindowex, Null, AddR TreeViewClass, NULL, /
WS_CHILD WS_VISIBLE TVS_HASLINES TVS_HASBUTTONS TVS_LINESTROOT, 0, /
0,200,400, hwnd, null, /
Hinstance, NULL
Note The Styles. TVs_xxxx are the tree view specific style.
Invoke imagelist_create, 16, 16, ilc_color16, 2, 10
Mov HimageList, EAX
Invoke loadingbitmap, hinstance, idb_tree
Mov Hbitmap, EAX
Invoke imagelist_add, himagelist, hbitmap, null
Invoke deleteObject, hbitmap
Invoke SendMessage, HwndtreeView, TVM_setimagelist, 0, HimageList
Next, you create an empty image list with will accept images of 16x16 pixels in size, 16-bit color and initially, it will contain 2 images but can be expanded to 10 if need arises. We then load the bitmap from the resource and add it to the image list just created. After that, we delete the handle to the bitmap since it will not be used anymore. When the image list is all set, we associate it with the tree view control by sending TVM_SETIMAGELIST to the tree view control .
Mov tvinsert.hparent, null
Mov tvinsert.hinsertafter, TVi_root
Mov tvinsert.u.Item.imask, TVif_text TVif_image TVif_selectedImage
Mov tvinsert.u.Item.psztext, offset parent
Mov tvinsert.u.Item.iimage, 0
Mov tvinsert.u.item.iselectedImage, 1
Invoke SendMessage, HWndtreeView, TVM_INSERTITEM, 0, AddR TVinsert
We insert items into the tree view control, beginning from the root item. Since it will be root item, hParent member is NULL and hInsertAfter is TVI_ROOT. Imask member specifies that pszText, iImage and iSelectedImage members of the TV_ITEM structure is valid. We fill those three members with appropriate value. pszText contains the label of the root item, iImage is the index into the image in the image list that will be displayed to the left of the unselected item, and iSelectedImage is the index into the image in the image List this will be displayed gen all appropriate Members Are Filled in, WE Send TVM_INSERTITEM Message To The Tree View Control To Add The root item to it.mov HParent, EAX
Mov Tvinsert.hparent, EAX
Mov tvinsert.hinsertafter, TVi_last
Mov tvinsert.u.Item.psztext, offset child1
Invoke SendMessage, HWndtreeView, TVM_INSERTITEM, 0, AddR TVinsert
Mov tvinsert.u.Item.psztext, offset child2
Invoke SendMessage, HWndtreeView, TVM_INSERTITEM, 0, AddR TVinsert
After the root item is added, we can attach the child items to it. HParent member is now filled with the handle of the parent item. And we will use identical images in the image list so we do not change iImage and iSelectedImage member.
.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
Now when the user tries to drag an item, the tree view control sends WM_NOTIFY message with TVN_BEGINDRAG as the code. LParam is the pointer to an NM_TREEVIEW structure which contains several pieces of information we need so we put its value into edi and use edi as the pointer to NM_TREEVIEW structure assume edi:. ptr NM_TREEVIEW is a way to tell MASM to treat edi as the pointer to NM_TREEVIEW structure We then create a drag image by sending TVM_CREATEDRAGIMAGE to the tree view control It returns the handle to the newly created.. image list with a drag image inside. We call ImageList_BeginDrag to set the hotspot in the drag image. Then we enter the drag operation by calling ImageList_DragEnter. This function displays the drag image at the specified location in the specified window. We use ptDrag structure that Is A Member of NM_TreeView Structure As The Point Where The Drag Image Should Be Initially Displayed.After That, We Capture The Mouse Input and Set The Flag To Indicate That We No w enter Drag mode..lseif umsg == wm_mousemove
.IF DragMode == True
Mov Eax, LPARAM
And Eax, 0FFFFH
MOV ECX, LPARAM
SHR ECX, 16
Mov TVhit.pt.x, EAX
Mov tvhit.pt.y, ECX
Invoke imagelist_dragmove, Eax, ECX
Invoke ImageList_DragShownolock, False
Invoke SendMessage, HwndtreeView, TVM_Hittest, Null, Addr TVHit
.IF EAX! = NULL
Invoke SendMessage, HWndTreeView, TVM_SELECTITEM, TVGN_DROPHILITE, EAX
.endif
Invoke imagelist_dragshownolock, True
.endif
Now we concentrate on WM_MOUSEMOVE. When the user drags the drag image along, our parent window receives WM_MOUSEMOVE messages. In response to these messages, we update the drag image position with ImageList_DragMove. After that, we check if the drag image is over some item . We do that by sending TVM_HITTEST message to the tree view control with a point for it to check. If the drag image is over some item, we hilite that item by sending TVM_SELECTITEM message with TVGN_DROPHILITE flag to the tree view control. During the hilite Operation, We Hide the Drag Image So That IT WILL NOT LEAVE UNSIGHTLY BLOTS on The Tree View Control..lseif 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
Invoke SendMessage, HWndtreeView, TVM_SelectItem, TVGN_Caret, EAX
Invoke SendMessage, HwndtreeView, TVM_SELECTITEM, TVGN_DROPHILITE, 0
Invoke ReleaseCapture
Mov Dragmode, False
.endif
When the user releases the left mouse button, the drag operation is at the end. We leave the drag mode by calling ImageList_DragLeave, followed by ImageList_EndDrag and ImageList_Destroy. To make the tree view items look good, we also check the last hilited item, and SELECT It. we must also un-hilite it else the other items will not get hilited when ity is used, we release the mouse capture.