|
Beginning the Tree-View Drag Operation
A tree-view control sends the parent window a TVN_BEGINDRAG (or TVN_BEGINRDRAG) notification message whenever the user starts to drag an item. The parent
window receives the notification in the form of a WM_NOTIFY message whose lParam parameter is the address of an NM_TREEVIEW structure. The members of this structure include the screen coordinates of
the mouse cursor and a TV_ITEM structure that contains information about the item to be dragged.
The following example shows how to process the WM_NOTIFY message to obtain
TVN_BEGINDRAG.
case WM_NOTIFY:
switch (((LPNMHDR) lParam)->code) {
case TVN_BEGINDRAG:
Main_OnBeginDrag(hwndTV, // application-defined function
(NM_TREEVIEW *) lParam);
break;
.
. // Handle other notifications here.
.
}
break;
Beginning the drag operation involves using the ImageList_BeginDrag function. The function's parameters include the handle of the image list
containing the image to use during the drag operation and the index of the image.
You can either provide your own image list and image, or you can have the
tree-view control create them for you by using the TVM_CREATEDRAGIMAGE message.
Because the drag image replaces the mouse cursor for the duration of the drag
operation, ImageList_BeginDrag requires you to specify a hot spot within the image. The coordinates of the
hot spot are relative to the upper left corner of the image. ImageList_BeginDrag also requires you to specify the initial location of the drag image. An
application typically sets the initial location so that the hot spot of the drag
image corresponds to that of the mouse cursor at the time the user began the drag
operation.
The following function demonstrates how to begin dragging a tree-view item. It
uses the drag image provided by the tree-view control and obtains the bounding
rectangle of the item to determine the appropriate point for the hot spot.
(The dimensions of the bounding rectangle are the same as those of the image.)
Note that the bounding rectangle does not account for the indentation of child
items. For this reason, the function adds the amount of indentation to the
x-coordinate of the hot spot.
The function captures mouse input, causing mouse messages to be sent to the
parent window. The parent window needs the subsequent WM_MOUSEMOVE messages to determine where to drag the image and the WM_LBUTTONUP message to determine when to end the drag operation.
// Main_OnBeginDrag - begins dragging an item in a tree-view control.
// hwndTV - handle of the image list
// lpnmtv - address of information about the item being dragged
- oid Main_OnBeginDrag(HWND hwndTV, NM_TREEVIEW *lpnmtv)
{
HIMAGELIST himl; // handle of image list
RECT rcItem; // bounding rectangle of item
DWORD dwLevel; // heading level of item
DWORD dwIndent; // amount that child items are indented
// Tell the tree-view control to create an image to use
// for dragging.
himl = TreeView_CreateDragImage(hwndTV, lpnmtv->itemNew.hItem);
// Get the bounding rectangle of the item being dragged.
TreeView_GetItemRect(hwndTV, lpnmtv->itemNew.hItem, &rcItem, TRUE);
// Get the heading level and the amount that the child items are
// indented.
dwLevel = lpnmtv->itemNew.lParam;
dwIndent = (DWORD) SendMessage(hwndTV, TVM_GETINDENT, 0, 0);
// Start the drag operation.
ImageList_BeginDrag(himl, 0, 0, 0);
// Hide the mouse cursor, and direct mouse input to the
// parent window.
ShowCursor(FALSE);
SetCapture(GetParent(hwndTV));
g_fDragging = TRUE;
return;
}
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|