HeaderCtrl

1. Header Control Messages  
 HDM_CLEARFILTER
 Clears the filter for a given header control.
 You can send this message explicitly or use the Header_ClearFilter macro.

 HDM_CREATEDRAGIMAGE
 Creates a semi-transparent version of an item's image for use as a dragging image.
 You can send this message explicitly or use the Header_CreateDragImage macro.

 HDM_DELETEITEM
 Deletes an item from a header control.
 You can send this message explicitly or use the Header_DeleteItem macro.

 HDM_EDITFILTER
 Starts editing the specified filter.

 HDM_GETBITMAPMARGIN
 Retrieves the width of the bitmap margin for a header control.
 You can send this message explicitly or use the Header_GetBitmapMargin macro.

 HDM_GETIMAGELIST
 Retrieves the handle to the image list that has been set for an existing header control.
 You can send this message explicitly or use the Header_GetImageList macro.

 HDM_GETITEM
 Retrieves information about an item in a header control.
 You can send this message explicitly or use the Header_GetItem macro.

 HDM_GETITEMCOUNT
 Retrieves a count of the items in a header control.
 You can send this message explicitly or use the Header_GetItemCount macro.

 HDM_GETITEMRECT
 Retrieves the bounding rectangle for a given item in a header control.
 You can send this message explicitly or use the Header_GetItemRect macro.

 HDM_GETORDERARRAY
 Retrieves the current left-to-right order of items in a header control.
 You can send this message explicitly or use the Header_GetOrderArray macro.

 HDM_GETUNICODEFORMAT
 Retrieves the Unicode character format flag for the control.
 You can send this message explicitly or use the Header_GetUnicodeFormat macro.

 HDM_HITTEST
 Tests a point to determine which header item, if any, is at the specified point.

 HDM_INSERTITEM
 Inserts a new item into a header control. You can send this message explicitly or use the Header_InsertItem macro.

 HDM_LAYOUT
 Retrieves the correct size and position of a header control within the parent window. You can send this message explicitly or use the Header_Layout macro.

 HDM_ORDERTOINDEX
 Retrieves an index value for an item based on its order in the header control. You can send this message explicitly or use the Header_OrderToIndex macro.

 HDM_SETBITMAPMARGIN
 Sets the width of the margin, specified in pixels, of a bitmap in an existing header control. You can send this message explicitly or use the Header_SetBitmapMargin macro.

 HDM_SETFILTERCHANGETIMEOUT
 Sets the timeout interval between the time a change takes place in the filter attributes and the posting of an HDN_FILTERCHANGE notification. You can send this message explicitly or use the Header_SetFilterChangeTimeout macro.

 HDM_SETHOTDIVIDER
 Changes the color of a divider between header items to indicate the destination of an external drag-and-drop operation. You can send this message explicitly or use the Header_SetHotDivider macro.

 HDM_SETIMAGELIST
 Assigns an image list to an existing header control. You can send this message explicitly or use the Header_SetImageList macro.

 HDM_SETITEM
 Sets the attributes of the specified item in a header control. You can send this message explicitly or use the Header_SetItem macro.

 HDM_SETORDERARRAY
 Sets the left-to-right order of header items. You can send this message explicitly or use the Header_SetOrderArray macro.

 HDM_SETUNICODEFORMAT
 Sets the UNICODE character format flag for the control. This message allows you to change the character set used by the control at run time rather than having to re-create the control. You can send this message explicitly or use the Header_SetUnicodeFormat macro.

 

 

2. Header Control Notification Messages  

 HDN_BEGINDRAG
 Sent by a header control when a drag operation has begun on one of its items.
 This notification message is sent only by header controls that are set to the HDS_DRAGDROP style.
 This notification is sent in the form of a WM_NOTIFY message.

 HDN_BEGINTRACK
 Notifies a header control's parent window that the user has begun dragging a divider in the control (that is, the user has pressed the left mouse button while the mouse cursor is on a divider in the header control). This notification message is sent in the form of a WM_NOTIFY message.

 HDN_DIVIDERDBLCLICK
 Notifies a header control's parent window that the user double-clicked the divider area of the control.
 This notification message is sent in the form of a WM_NOTIFY message.

 HDN_ENDDRAG
 Sent by a header control when a drag operation has ended on one of its items. This notification is sent as a WM_NOTIFY message. Only header controls that are set to the HDS_DRAGDROP style send this notification.

 HDN_ENDTRACK
 Notifies a header control's parent window that the user has finished dragging a divider. This notification message sent in the form of a WM_NOTIFY message.

 HDN_FILTERBTNCLICK
 Notifies the header control's parent window when the filter button is clicked or in response to an HDM_SETITEM message.

 HDN_FILTERCHANGE
 Notifies the header control's parent window that the attributes of a header control filter are being changed or edited.

 HDN_GETDISPINFO
 Sent to the owner of a header control when the control needs information about a callback header item. This notification is sent as a WM_NOTIFY message.

 HDN_ITEMCHANGED
 Notifies a header control's parent window that the attributes of a header item have changed. This notification message is sent in the form of a WM_NOTIFY message.

 HDN_ITEMCHANGING
 Notifies a header control's parent window that the attributes of a header item are about to change. This notification message is sent in the form of a WM_NOTIFY message.

 HDN_ITEMCLICK
 Notifies a header control's parent window that the user clicked the control. This notification message is sent in the form of a WM_NOTIFY message.

 HDN_ITEMDBLCLICK
 Notifies a header control's parent window that the user double-clicked the control. This notification message is sent in the form of a WM_NOTIFY message. Only header controls that are set to the HDS_BUTTONS style send this notification.

 HDN_TRACK
 Notifies a header control's parent window that the user is dragging a divider in the header control. This notification message is sent in the form of a WM_NOTIFY message.

 NM_CUSTOMDRAW (header)
 Sent by a header control to notify its parent window about drawing operations. This notification is sent in the form of a WM_NOTIFY message.

 NM_RCLICK (header)
 Notifies a tree-view control's parent window that the user has clicked the right mouse button within the control. This notification is sent in the form of a WM_NOTIFY message.

 NM_RELEASEDCAPTURE (header)
 Notifies a header control's parent window that the control is releasing mouse capture. This notification is sent in the form of a WM_NOTIFY message.

 

 


3. Header Control Styles

 HDS_BUTTONS
 Each item in the control looks and behaves like a push button. This style is useful if an application carries out a task when the user clicks an item in the header control. For example, an application could sort information in the columns differently depending on which item the user clicks.

 HDS_DRAGDROP
 Version 4.70. Allows drag-and-drop reordering of header items.

 HDS_FILTERBAR
 Version 5.80. Include a filter bar as part of the standard header control. This bar allows users to conveniently apply a filter to the display. Calls to HDM_LAYOUT will yield a new size for the control and cause the list view to update.

 HDS_FLAT
 Version 6.0. Causes the header control to be drawn flat when Microsoft Windows XP is running in classic mode.
 Note  Comctl32.dll version 6 is not redistributable but it is included in Windows XP or later. To use Comctl32.dll version 6, specify it in a manifest. For more information on manifests, see Using Windows XP Visual Styles.

 HDS_FULLDRAG
 Version 4.70. Causes the header control to display column contents even while the user resizes a column.

 HDS_HIDDEN
 Indicates a header control that is intended to be hidden. This style does not hide the control. Instead, when you send the HDM_LAYOUT message to a header control with the HDS_HIDDEN style, the control returns zero in the cy member of the WINDOWPOS structure. You would then hide the control by setting its height to zero. This can be useful when you want to use the control as an information container instead of a visual control.

 HDS_HORZ
 Creates a header control with a horizontal orientation.

 HDS_HOTTRACK
 Version 4.70. Enables hot tracking.


 
 


VC常用控件用法之表头控制Header Control

表头控制(CHeaderCtrl)通常应用在窗口中的文本或数据的列表之上。
一般为数据列的标题,可以包括多个部分,用户可以拖动每个部分并可以控制每列的宽度。
表头控制类提供了普通表头控制的基本方法,只有在 WINDOWS95 以后版本系统中才提供,其方法包含在 afxcmn.h 文件中,
一般与标签控制(CTabCtrl)和列表控制(CListCtrl)组合使用。

1.1 表头控制的对象结构

1.1.1 表头控制对象的建立方法

CHeaderCtrl &cheaderCtrl  建立表头控制对象

Create  建立表头并绑定对象

CHeaderCtrl::Create 的格式如下:BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );

其返回值非零时初始化成功,否则失败。

参数 dwStyle 用来确定表头控制类型;
rect 用来确定表头控制的大小和位置;
ParentWnd 用来确定表头控制的父窗口;nID 用来表示表头控制的标志。

表头控制风格包括:

HDS_BUTTONS  表示表头控制外观类似按钮;

HDS_HORZ  表示表头控制为水平排列;

HDS_VERT  表示表头控制为垂直排列;

HDS_HIDDEN  表示表头控制为隐藏模式。

它也可以使用普通类控制风格,包括:

CCS_BOTTOM  设置控制位置在父窗口的底部并与父窗口同样宽度;

CCS_NODIVIDER  在控制顶部形成两个像素的高亮区;

CCS_NOHILITE  在控制顶部形成一个像素的高亮区;

CCS_NOMOVEY  在响应 WM_SIZE 消息时重置大小并水平排列;

CCS_NOPARENTALIGN  使控制自动靠近父窗口的顶部或底部;

CCS_NORESIZE  设置初始大小或新值时使控制使用默认宽度和高度;

CCS_TOP  设置在父窗口客户区域的顶部并与父窗口同样宽度;

同样表头控制也可以使用窗口控制风格,包括:

WS_CHILD  建立一个子窗口,不能用于 WS_POPUP 窗口类型;

WS_VISIBLE  建立一个初始时不可见的窗口;

WS_DISABLED  建立一个初始时无效的窗口;

WS_GROUP  确定可用光标移动的控制群组;

WS_TABSTOP  确定可用 TAB 控制移动站点;

表头控制一般分为两个步骤,首先确定表头控制的数据结构,然后建立表头控制并绑定对象。

1.1.2 表头控制的属性

表头控制的属性包括取得表头控制中项目的数量 GetItemCount、取得表头控制中某一项目的内容 GetItem 和设置表头控制中某一项目的内容 SetItem。

1.1.3 表头控制的操作方法

表头控制的操作方法包括向表头控制中插入一个新项目 InsertItem、从表头控制中删除一个项目 DeleteItem 和绘制表头中给定的项目 DrawItem 等。

1.2 表头控制的数据结构

在使用表头控制时,首先必须建立一个数据结构 HD_ITEM,其结构定义如下:

typedef struct _HD_ITEM
{
 UINT mask;    // 结构成员有效控制位
 int cxy;    // 表头项目的宽度
 LPSTR pszText;   // 表头项目内容
 HBITMAP hbm;   // 表头项目的位置句柄
 int cchTextMax;  // 表头内容字符串长度
 int fmt;    // 表头项目的格式
 LPARAM lParam;   // 应用程序定义的32位数据
} HD_ITEM;

屏蔽控制位说明了数据结构成员中包含的有效数据,可以是下面标志的组合:

HDI_BITMAP hbm 成员有效
HDI_FORMAT fmt  成员有效
HDI_LPARAM lParam 成员有效
HDI_TEXT pszText  和 cchTextMax  成员有效
HDI_WIDTH cxy  成员有效并确定项目宽度值


格式标志位 fmt 可以是以下标志的组合:

HDF_CENTER  表头项目居中
HDF_LEFT  表头项目左对齐
HDF_RIGHT  表头项目右对齐
HDF_BITMAP  表头显示一个位图
HDF_OWNERDRAW  由主窗口自绘表头项目   // 注意..~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
HDF_STRING  表头项目为一个字符串


1.3 表头控制的应用技巧

由于表头控制无法单独使用,其主要是配合列表控制和标签控制,并多以文字表头应用多见,
InsertItem、SetItem 和 GetItem 是常用的方法,
如在列表控制时利用 InsertColumn 属性就可以增加一个表列的文本标题,具体用法和技巧见列表控制和标签控制。
下面以在列表控制中的增加表列的方法来具体说明:

lvcol.pszText=品 名;//设置第一列名

lvcol.iSubItem=i; //表列宽

m_ListCtrl.InsertColumn(i++,&lvcol);//插入一列

lvcol.pszText=数 量;//第二列名

lvcol.iSubItem=i;

lvcol.cx=70;

m_ListCtrl.InsertColumn(i++,&lvcol);//插入一列

......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值