📄 tut19.html
字号:
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>
iSelectedImage DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>
cChildren DWORD
?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>
lParam
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TV_ITEM
ENDS</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>This structure
is used to send and receive info about a tree view item, depending on messages.
For example, with <b>TVM_INSERTITEM</b>, it is used to specify the attribute
of the item to be inserted into the tree view control. With <b>TVM_GETITEM</b>,
it'll be filled with information about the selected tree view item.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>imask
</b>is
used to specify which member(s) of the <b>TV_ITEM</b> structure is (are)
valid. For example, if the value in imask is <b>TVIF_TEXT</b>, it means
only the pszText member is valid. You can combine several flags together.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>hItem
</b>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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>pszText</b>
is the pointer to a null-terminated string that is the label of the tree
view item.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>cchTextMax</b>
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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>iImage
</b>and
<b>iSelectedImage</b>
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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>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.</font></font></font>
<h4>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Adding
images to the tree view control</font></font></font></h4>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>If 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 <b>ImageList_Create</b>.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>ImageList_Create
PROTO cx:DWORD, cy:DWORD, flags:DWORD, \</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>
cInitial:DWORD, cGrow:DWORD</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>This function
returns the handle to an empty image list if successful.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>cx
</b>==
width of each image in this image list, in pixels.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>cy</b>
== 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 pieces. So
you should prepare your own image as a strip of pictures with identical
dimensions.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>flags</b>
== 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 detail</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>cInitial</b>
== The number of images that this image list will initially contain. Windows
will use this info to allocate memory for the images.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>cGrow</b>
== 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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>An
image list is not a window! It's only an image deposit for use by other
windows.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>After
an image list is created, you can add images to it by calling <b>ImageList_Add</b></font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>ImageList_Add
PROTO himl:DWORD, hbmImage:DWORD, hbmMask:DWORD</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>This function
returns -1 if unsuccessful.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>himl
</b>==
the handle of the image list you want to add images to. It is the value
returned by a successful call to <b>ImageList_Create</b></font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>hbmImage</b>
== the handle to the bitmap to be added to the image list. You usually
store the bitmap in the resource and load it with <b>LoadBitmap</b> call.
Note that you don't have to specify the number of images contained in this
bitmap because this information is inferred from cx and cy parameters passed
to <b>ImageList_Create </b>call.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>hbmMask</b>
== Handle to the bitmap that contains the mask. If no mask is used with
the image list, this parameter is ignored.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Normally,
we will add only two images to the image list for use with the tree view
control: one that is used when the tree view item is not selected, and
the other when the item is selected.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>When
the image list is ready, you associate it with the tree view control by
sending <b>TVM_SETIMAGELIST
</b>to the tree view control.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVM_SETIMAGELIST</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>wParam
= type of image list to set. There are two choices:</font></font></font></b>
<ul>
<li>
<b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVSIL_NORMAL
Set the normal image list, which contains the selected and unselected images
for the tree-view item.</font></font></font></b></li>
<li>
<b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVSIL_STATE
Set the state image list, which contains the images for tree-view items
that are in a user-defined state.</font></font></font></b></li>
</ul>
<b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>lParam
= Handle to the image list</font></font></font></b></ul>
<h4>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Retrieve
the info about tree view item</font></font></font></h4>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>You can
retrieve the information about a tree view item by sending <b>TVM_GETITEM</b>
message.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVM_GETITEM</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>wParam
= 0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>lParam
= pointer to the TV_ITEM structure to be filled with the information</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Before
you send this message, you must fill imask member with the flag(s) that
specifies which member(s) of <b>TV_ITEM</b> 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?</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>The
answer is quite simple: you don't have to. You can send <b>TVM_GETNEXTITEM</b>
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.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVM_GETNEXTITEM</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>wParam
= flag</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>lParam
= handle to a tree view item (only necessary for some flag values)</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>The value
in wParam is very important so I present all the flags below:</font></font></font>
<ul>
<ul>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_CARET</b>
Retrieves the currently selected item.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_CHILD</b>
Retrieves the first child item of the item specified by the hitem parameter</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_DROPHILITE</b>
Retrieves the item that is the target of a drag-and-drop operation.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_FIRSTVISIBLE</b>
Retrieves the first visible item.</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>TVGN_NEXT
</b>Retrieves
the next sibling item.</font></font></font></li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -