Crazy_Challenger

导航

 

List Control 控件(MSDN 链接)

两个重要结构:

LVCOLUMN(MSDN 链接)

作用:  这个结构体记录了列的相关信息

结构体定义:

View Code
typedef struct _LVCOLUMN {
UINT mask; // Variable specifying which members contain valid information
int fmt; // Alignment of the column header and the subitem text in the column
int cx; // Width of the column, in pixels
LPTSTR pszText; // contains the column header text.
int cchTextMax; // Size in TCHARs of the buffer pointed to by the pszText member
int iSubItem; // Index of subitem associated with the column.

if (_WIN32_IE >= 0x0300)

int iImage; // Zero-based index of an image within the image list. The specified image will appear within the column.
int iOrder; // Zero-based column offset. Column offset is in left-to-right order. For example, zero indicates the leftmost column.

endif

if (_WIN32_WINNT >= 0x0600)

int cxMin; // Minimum width of the column in pixels.
int cxDefault; // Application-defined value typically used to store the default width of the column. This member is ignored by the list-view control.
int cxIdeal; // Read-only. The ideal width of the column in pixels, as the column may currently be autosized to a lesser width.

endif

} LVCOLUMN, *LPLVCOLUMN;
LVITEM(MSDN 链接)

作用:  这个结构体记录了行的相关信息

结构体定义:

View Code
typedef struct {
UINT mask; // Set of flags that specify which members of this structure contain data to be set or which members are being requested
int iItem; // Zero-based index of the item to which this structure refers
int iSubItem; // One-based index of the subitem to which this structure refers, or zero if this structure refers to an item rather than a subitem
UINT state; // Indicates the item's state, state image, and overlay image
UINT stateMask; // Value specifying which bits of the state member will be retrieved or modified
LPTSTR pszText; // containing the item text
int cchTextMax; // Number of TCHARs in the buffer pointed to by pszText, including the terminating NULL.
int iImage; // Index of the item's icon in the control's image list.
LPARAM lParam; // Value specific to the item. If you use the LVM_SORTITEMS message, the list-view control passes this value to the application-defined comparison function.

if (_WIN32_IE >= 0x0300)

int iIndent; // Number of image widths to indent the item. A single indentation equals the width of an item image

endif

if (_WIN32_WINNT >= 0x0501)

int iGroupId; // Identifier of the group that the item belongs to, or one of the following values.
UINT cColumns; // Number of data columns (subitems) to display for this item in tile view.
UINT puColumns; // A pointer to an array of column indices, specifying which columns are displayed for this item, and the order of those columns.

endif

if (_WIN32_WINNT >= 0x0600)

int piColFmt; // A pointer to an array of the following flags (alone or in combination), specifying the format of each subitem in extended tile view.
int iGroup; // Group index of the item.

endif

} LVITEM, *LPLVITEM;
CListCtrl 常用函数(单击函数链接至MSDN):

插入 / 删除列:  InsertColumn /DeleteItem
插入 / 删除行:  InsertItem /DeleteColumn
删除所有行:  DeleteAllItems
获得 / 设置行图标:  GetImageList /SetImageList
获得 / 更改行位置:  GetItemPosition /SetItemPosition
获得 / 设置行文本:  GetItemText /SetItemText
获得 / 设置列宽度:  GetColumnWidth /SetColumnWidth
获得 / 设置控件扩展风格:  GetExtendedStyle /SetExtendedStyle
获得 / 设置列属性:  GetColumn /SetColumn
获得 / 设置控件背景图片:   GetBkImage / SetBkImage
获得 / 设置控件背景颜色:  GetBkColor /SetBkColor
获得 / 设置文本颜色:  GetTextColor /SetTextColor
获得 / 设置文本背景色:  GetTextBkColor /SetTextBkColor
获得字符串宽度:  GetStringWidth
获得 / 设置行属性:  GetItem /SetItem
获得某行矩形区域:  GetItemRect
获得 / 设置行状态:  GetItemState /SetItemState (在 SetItemState 中的两个参数取值说明 nState , nMask )
获得控件行总数:  GetItemCount
获得选中行索引(当时索引不是基于 0 而是基于 1):  GetFirstSelectedItemPosition

Tree Control 控件(MSDN 链接)

说明:

树形控件是用于构造树形的结构,其中有一个根接点(Root)然后下面有许多子结点,而每个子结点上有允许有一个或多个或没有子结点.在树形控件中每一个结点都有一个句柄(HTREEITEM),同时添加结点时必须提供该结点的父结点句柄(其中根Root结点只有一个,既不可以添加也不可以删除), MFC 中使用 CTreeCtrl 类来封装树形控件的各种操作.树形控件的消息映射使用 ON_NOTIFY 宏.

三个重要结构:

TVINSERTSTRUCT(MSDN 链接)

作用:  这个结构体包含了在树形图控件添加子节点时需要的相关信息

结构体定义:

View Code
typedef struct _TV_INSERTSTRUCT {
HTREEITEM hParent; // Handle to the parent item
HTREEITEM hInsertAfter; // Handle to the item after which the new item is to be inserted
TV_ITEM item; // TV_ITEM structure that contains information about the item to add
} TV_INSERTSTRUCT, FAR *LPTV_INSERTSTRUCT;
TVITEM(MSDN 链接)

作用:  记录着被添加的数的节点的信息

结构体定义:

View Code
typedef struct _TV_ITEM { //tvi
UINT mask; // ndicates which of the other structure members contain valid data
HTREEITEM hItem; // Handle to the item to which this structure refers
UINT state; // Set of bit flags and image list indexes that indicate the item's state
UINT stateMask; // Bits of the state member that are valid
LPSTR pszText; // Pointer to a null-terminated string that contains the item text
int cchTextMax; // Size of the buffer pointed to by the pszText member
int iImage; // Index in the tree view control's image list of the icon image to use when the item is in the nonselected state
int iSelectedImage; //Index in the tree view control's image list of the icon image to use when the item is in the selected state.
int cChildren; // Indicates whether the item has associated child items
LPARAM lParam; // Specifies a 32-bit value to associate with the item.
}TV_ITEM, FAR *LPTV_ITEM;
NMTREEVIEW(MSDN 链接)

作用:  包含关于树形视通知消息的信息

结构体定义:

View Code
typedef struct _NM_TREEVIEW {
NMHDR hdr; // NMHDR structure that contains information about this message
UINT action; // Notification-specific action flag
TV_ITEM itemOld; // TV_ITEM structure that contains information about the old item state
TV_ITEM itemNew; // TV_ITEM structure that contains information about the new item state.
POINT ptDrag; // POINTstructure that contains the client coordinates of the mouse at the time the event occurred that caused the message to be sent
} NM_TREEVIEW;
typedef NM_TREEVIEW FAR* LPNM_TREEVIEW;
CTreeCtrl 常用函数(单击函数链接至MSDN):

创建树形结构控件窗口:  Create
在 Create 中 dwStyle 中可以使用以下一些树形控件的专用风格:

TVS_HASLINES   在父/子结点之间绘制连线
TVS_LINESATROOT   在根/子结点之间绘制连线
TVS_HASBUTTONS   在每一个结点前添加一个按钮,用于表示当前结点是否已被展开
TVS_EDITLABELS   结点的显示字符可以被编辑
TVS_SHOWSELALWAYS   在失去焦点时也显示当前选中的结点
TVS_DISABLEDRAGDROP   不允许Drag/Drop
TVS_NOTOOLTIPS   不使用ToolTip显示结点的显示字符

插入字节点:  InsertItem
获得 / 设置节点图标:  GetImageList /SetImageList
获得 / 设置选中结点:  GetSelectedItem /SelectItem
获得 / 修改索引结点图标:   GetItemImage / SetItemImage
获得 / 修改结点的显示字符:  GetItemText /SetItemText
删除结点:  DeleteItem
将删除所有结点:  DeleteAllItems
获得根结点:  GetRootItem
获得节点父 / 子结点:  GetParentItem /GetChildItem
获得结点的上 / 下一个兄弟结点:  GetPrevSiblingItem /GetNextSiblingItem 
获得 / 设置控件背景色:  GetBkColor /SetBkColor
获得 / 设置节点属性:  GetItem /SetItem
获得 / 设置控件字体颜色:  GetTextColor /SetTextColor
获得节点矩形区:  GetItemRect

posted on 2019-08-30 17:51  Crazy_Challenger  阅读(258)  评论(0)    收藏  举报