📄 tut19.html
字号:
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_NEXTVISIBLE</b>
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.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_PARENT</b>
Retrieves the parent of the specified item.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_PREVIOUS</b>
Retrieves the previous sibling item.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_PREVIOUSVISIBLE</b>
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.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_ROOT</b>
Retrieves the topmost or very first item of the tree-view control.</font></font></font></li>
</ul>
</ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>You can
see that, you can retrieve the handle to the tree view item you are interested
in from this message. <b>SendMessage</b> returns the handle to the tree
view item if successful. You can then fill the returned handle into hItem
member of <b>TV_ITEM
</b>to be used with <b>TVM_GETITEM</b> message.</font></font></font>
<h4>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Drag and
Drop Operation in tree view control</font></font></font></h4>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>This 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 figured out how to implement drag & drop in a tree
view control and I don't want anyone to walk the same path as myself.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Below
is the steps in implementing drag & drop operation in a tree view control.</font></font></font>
<ol>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>When the
user tries to drag an item, the tree view control sends <b>TVN_BEGINDRAG</b>
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 <b>TVM_CREATEDRAGIMAGE</b> 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.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>After
the drag image is created, you specify the hotspot of the drag image by
calling <b>ImageList_BeginDrag.</b></font></font></font></li>
<ol><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>ImageList_BeginDrag
PROTO himlTrack:DWORD, \</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>
iTrack:DWORD , \</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>
dxHotspot:DWORD, \</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>
dyHotspot:DWORD</font></font></font></b>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>himlTrack</b>
is the handle to the image list that contains the drag image.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>iTrack</b>
is the index into the image list that specifies the drag image</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>dxHotspot</b>
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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>dyHotspot</b>
specifies the relative distance of the hotspot in the vertical plane.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Normally,
iTrack would be 0 if you tell the tree view control to create the drag
image for you. and dxHotspot and dyHotspot can be 0 if you want the left
upper corner of the drag image to be the hotspot.</font></font></font></ol>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>When the
drag image is ready to be displayed, we call <b>ImageList_DragEnter</b>
to display the drag image in the window.</font></font></font></li>
<ol><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>ImageList_DragEnter
PROTO hwndLock:DWORD, x:DWORD, y:DWORD</font></font></font></b>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>hwndLock</b>
is the handle of the window that owns the drag image. The drag image will
not be able to move outside that window.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>x
and y</b> 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.</font></font></font></ol>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>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 <b>WM_MOUSEMOVE</b> and the
drop location with <b>WM_LBUTTONUP</b> 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 <b>SetCapture</b>.
Using the call, the mouse messages will be directed to the specified window
regardless of where the mouse cursor is.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Within
<b>WM_MOUSEMOVE</b>
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 image
is over by sending <b>TVM_HITTEST</b> to check if the drag image is over
some item. If it is, you can send <b>TVM_SELECTITEM</b> with
<b>TVGN_DROPHILITE</b>
flag to hilite that item. Note that before sending
<b>TVM_SELECTITEM
</b>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.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>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 <b>TVM_SELECTITEM</b>
with <b>TVGN_DROPHILITE </b>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 <b>ImageList_DragLeave</b>
followed by <b>ImageList_EndDrag</b>. You must release the mouse by calling
<b>ReleaseCapture</b>.
If you create an image list, you must destroy it by calling <b>ImageList_Destroy</b>.
After that, you can go on with what your program wants to do when the drag
& drop operation is completed.</font></font></font></li>
</ol>
<h3>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Code sample:</font></font></font></h3>
<b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>.386</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>.model
flat,stdcall</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>option
casemap:none</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>include
\masm32\include\windows.inc</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>include
\masm32\include\user32.inc</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>include
\masm32\include\kernel32.inc</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>include
\masm32\include\comctl32.inc</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>include
\masm32\include\gdi32.inc</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>includelib
\masm32\lib\gdi32.lib</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>includelib
\masm32\lib\comctl32.lib</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>includelib
\masm32\lib\user32.lib</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>includelib
\masm32\lib\kernel32.lib</font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>WinMain
PROTO :DWORD,:DWORD,:DWORD,:DWORD</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>.const</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>IDB_TREE
equ 4006
; ID of the bitmap resource</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>.data</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>ClassName
db "TreeViewWinClass",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>AppName
db "Tree View Demo",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TreeViewClass
db "SysTreeView32",0</font></font></font></b>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -