⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tut19.html

📁 WINDOWS程序员使用指南--汇编基础
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="Author" content="Iczelion">
   <meta name="GENERATOR" content="Mozilla/4.51 [en] (Win95; I) [Netscape]">
   <title>Iczelion's Win32 Assembly Tutorial 19: Tree View Control</title>
</head>
<body text="#FFFFFF" bgcolor="#000080" link="#FFFF00" vlink="#8080FF" alink="#FF00FF">

<center>
<h1>
<font face="Arial,Helvetica"><font color="#FFFF99">Tutorial 19: Tree View
Control</font></font></h1></center>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>In this
tutorial, we will 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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Download
the example<a href="files/tut19.zip"> here</a>.</font></font></font>
<h3>
<font face="Arial,Helvetica"><font color="#009900"><font size=+0>Theory:</font></font></font></h3>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>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. Don't forget
to put InitCommonControls call in your code.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>There
are several styles specific to the tree view control. These three are the
ones mostly used.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>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.</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVS_HASLINES
== Uses lines to show the hierarchy of items.</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVS_LINESATROOT
== Uses lines to link items at the root of the tree-view control. This
value is ignored if TVS_HASLINES is not also specified.</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>When
something interesting occurs to it, it sends a <b>WM_NOTIFY
</b>message
to the parent window with accompanying information.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>WM_NOTIFY</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>wParam
== Control ID, this value is not guaranteed to be unique so we don't use
it.</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Instead, we use hwndFrom or IDFrom member of the NMHDR structure</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pointed to by lParam</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>lParam
== Pointer to NMHDR structure. Some controls may pass a pointer to larger</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
structure but it must have a NMHDR structure as its first member.</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
That is, when you have lParam, you can be sure that it points to a</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
NMHDR structure at least.</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Next we
will examine NMHDR structure.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>NMHDR
struct DWORD</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;
hwndFrom&nbsp;&nbsp;&nbsp; DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;
idFrom&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;
code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>NMHDR
ends</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>hwndFrom
is the window handle of the control that sends this <b>WM_NOTIFY</b> message.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>idFrom
is the control ID of the control that sends this WM_NOTIFY message.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>code
is the actual message the control wants to send to the parent window.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Tree
view notifications are those with TVN_ at the beginning of the name. Tree
view messages are those with TVM_, like
<b>TVM_CREATEDRAGIMAGE</b>. The
tree view control sends TVN_xxxx in the code member of NMHDR. The parent
window can send TVM_xxxx to control it.</font></font></font>
<h4>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>Adding
items to a tree view control</font></font></font></h4>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>After
you create a tree view control, you can add items to it. You can do this
by sending <b>TVM_INSERTITEM
</b>to it.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVM_INSERTITEM</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 a TV_INSERTSTRUCT;</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>You should
know some terminology at this point about the relationship between items
in the tree view control.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>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 other item. An item without a parent
is called a root item. There can be many root items in a tree view control.
Now we examine<b> TV_INSERTSTRUCT</b> structure</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TV_INSERTSTRUCT
STRUCT DWORD</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
hParent&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DWORD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
hInsertAfter&nbsp; DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ITEMTYPE &lt;></font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TV_INSERTSTRUCT
ENDS</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>hParent</b>
= Handle to the parent item. If this member is the <b>TVI_ROOT</b> value
or NULL, the item is inserted at the root of the tree-view control.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1><b>hInsertAfter</b>
= Handle to the item after which the new item is to be inserted or one
of the following values:</font></font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVI_FIRST
==> Inserts the item at the beginning of the list.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVI_LAST
==> Inserts the item at the end of the list.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TVI_SORT
==> Inserts the item into the list in alphabetical order.</font></font></font></li>
</ul>

<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>ITEMTYPE
UNION</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
itemex TVITEMEX &lt;></font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
item TVITEM &lt;></font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>ITEMTYPE
ENDS</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>We will
use only TVITEM here.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>TV_ITEM
STRUCT DWORD</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
imask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DWORD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
hItem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DWORD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
state&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DWORD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
stateMask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DWORD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
pszText&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DWORD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
cchTextMax&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DWORD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#FFFFFF"><font size=-1>&nbsp;
iImage&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -