listview control messages

CTreeCtrl是在OnNMCustomdraw中自绘的,不要设定其他属性  
CListCtrl是在DrawItem中自绘的,要设定属性LVS_OWNERDRAWFIXED|LVS_REPORT  
 CButton是在DrawItem中自绘的,要设定属性BS_OWNERDRAW  
 CMenu是在DrawItem中自绘的,要把每一项都设定属性MF_OWNERDRAW,用到递归方法  
单选按钮是基于CButton在DrawItem中自绘的,要重写Create设定属性为  
dwStyle &= ~(0xF);  
 dwStyle |= BS_AUTORADIOBUTTON;  
dwStyle |= BS_OWNERDRAW  
 CListBox是在DrawItem中自绘的,必须加上属性LBS_OWNERDRAWFIXED |LBS_HASSTRINGS  

 

1. List View Control Messages
   
  LVM_APPROXIMATEVIEWRECT    // 计算需要显示的项目数的近似宽度和高度。你可以明确的发送这个消息,或者使用宏ListView_ApproximateViewRect。
 LVM_ARRANGE       // 排列
 LVM_CREATEDRAGIMAGE    // 创建拖动图像
 LVM_DELETEALLITEMS    // 删除所有项
 LVM_DELETECOLUMN    // 删除列
 LVM_DELETEITEM     // 删除项    
  LVM_EDITLABEL     // 编辑标签
 LVM_ENSUREVISIBLE    // 确保可见
 LVM_FINDITEM     // 查找项

 LVM_GETBKCOLOR     // 获取背景颜色
 LVM_GETBKIMAGE     // 获取背景图像
 LVM_GETCALLBACKMASK    // 返回列表视图控件的回调掩码。你可以明确的发送这个消息,或者使用ListView_GetCallbackMask宏。
 LVM_GETCOLUMN     // 取得列表视图控件的列的属性 
 LVM_GETCOLUMNORDERARRAY    // 以自左向右的顺序取得列表视图控件当前的列。
 LVM_GETCOLUMNWIDTH    // 取得列的宽度
 LVM_GETCOUNTPERPAGE    // 当列表视图控件使用列表视图或者报告视图时,计算显示区域能垂直显示的项的数目。只有能完全显示的项才会被计数。
 LVM_GETEDITCONTROL    // 取得编辑列表视图项文本的编辑控件的句柄。
 LVM_GETEXTENDEDLISTVIEWSTYLE   // 取得列表视图控件现在正在使用的扩展风格
 LVM_GETHEADER     // 取得列表视图控件使用的标头控件的句柄
 LVM_GETHOTCURSOR    // 获取在焦点项上的鼠标值
 LVM_GETHOTITEM     // 获取焦点项索引
 LVM_GETHOVERTIME    // 
  LVM_GETIMAGELIST    // 获取image List
  LVM_GETISEARCHSTRING    // 
  LVM_GETITEM      // 获取项
 LVM_GETITEMCOUNT    // 获取项数目
 LVM_GETITEMPOSITION    // 获取项位置
 LVM_GETITEMRECT     // 获取项RECT
  LVM_GETITEMSPACING    // 获取项与项的间距
 LVM_GETITEMSTATE    // 获取项的状态
 LVM_GETITEMTEXT     // 获取项的文本
 LVM_GETNEXTITEM     // 获取下一个项
 LVM_GETNUMBEROFWORKAREAS   // 在列表视图控件检索一些领域的工作
 LVM_GETORIGIN     // 检索为列表视图控件的当前视图的起源
 LVM_GETSELECTEDCOUNT    // 获取所选项的数目
 LVM_GETSELECTIONMARK    // 获取选中项的Mark 
  LVM_GETSTRINGWIDTH    // 获取当前ListView字体的宽度
 LVM_GETSUBITEMRECT    // 获取子项的RECT
  LVM_GETTEXTBKCOLOR    // 获取文本背景颜色
 LVM_GETTEXTCOLOR    // 获取文本颜色
 LVM_GETTOOLTIPS     // 获取提示字符
 LVM_GETTOPINDEX     // 获取顶端项索引   
  LVM_GETUNICODEFORMAT    // 获取宽字符格式
 LVM_GETVIEWRECT     // 获取View RECT
  LVM_GETWORKAREAS    // 获取工作区域

 LVM_HITTEST     // 获取鼠标点击的详细信息
 LVM_INSERTCOLUMN    // 插入列
 LVM_INSERTITEM     // 插入项
 LVM_REDRAWITEMS     // 设置一个开始项和结束项, 重绘这个些项   
  LVM_SCROLL     // 滚动的列表视图控件的内容

 LVM_SETBKCOLOR     // 设置背景颜色
 LVM_SETBKIMAGE     // 设置背景image
  LVM_SETCALLBACKMASK    // 设置列表视图控件的回调掩码
 LVM_SETCOLUMN     // 设置列
 LVM_SETCOLUMNORDERARRAY
  LVM_SETCOLUMNWIDTH    // 设置列的宽度
 LVM_SETEXTENDEDLISTVIEWSTYLE
  LVM_SETHOTCURSOR    // 设置鼠标焦点到该项
 LVM_SETHOTITEM     // 设置焦点项
 LVM_SETHOVERTIME
  LVM_SETICONSPACING
  LVM_SETIMAGELIST
  LVM_SETITEM
  LVM_SETITEMCOUNT
  LVM_SETITEMPOSITION
  LVM_SETITEMPOSITION32
  LVM_SETITEMSTATE    // 设置项状态
 LVM_SETITEMTEXT     // 设置行文本
 LVM_SETSELECTIONMARK    
  LVM_SETTEXTBKCOLOR    // 设置文本背景颜色
 LVM_SETTEXTCOLOR    // 设置文本颜色
 LVM_SETTOOLTIPS     // 设置提示
 LVM_SETUNICODEFORMAT
  LVM_SETWORKAREAS

 LVM_SORTITEMS     // 排列项
 LVM_SUBITEMHITTEST    // 子项鼠标点击的详细信息
 LVM_UPDATE     // 更新数据

2. List View Control Notification Messages 

 LVN_BEGINDRAG      // 开始拖动
 LVN_BEGINLABELEDIT     // 开始编辑标签
 LVN_BEGINRDRAG
  LVN_COLUMNCLICK      // 列单击
 LVN_DELETEALLITEMS     // 删除所有项
 LVN_DELETEITEM      // 删除项
 LVN_ENDLABELEDIT     // 启用项
 LVN_GETDISPINFO      // 获取
 LVN_GETINFOTIP
  LVN_HOTTRACK
  LVN_INSERTITEM      // 插入项
 LVN_ITEMACTIVATE     // 项活动
 LVN_ITEMCHANGED      // 项改变
 LVN_ITEMCHANGING     // 项改变中
 LVN_KEYDOWN       // 键按下
 LVN_MARQUEEBEGIN     // 鼠标点击开始拖动
 LVN_ODCACHEHINT      // 滚动视图时
 LVN_ODFINDITEM
  LVN_ODSTATECHANGED
  LVN_SETDISPINFO

 父窗口通过uMsg == WM_NOTIFY 消息接收: 

 wNotifyCode = HIWORD(wParam); // notification code 
  wID = LOWORD(wParam);         // item, control, or accelerator identifier 
  hwndCtl = (HWND) lParam;      // handle of control 
  
  if (message.wparam == _pListView->getCtrlId) {
   NMLISTVIEW *pListView = (NMLISTVIEW *)message.lparam;
   if (pListView->hdr.code == NM_CUSTOMDRAW) {
    LPNMLVCUSTOMDRAW pListDraw = (LPNMLVCUSTOMDRAW) lParam;


 3. List View Control Styles

 list view 有4种不同的视图:
  1. LVS_ICON window 
  2. LVS_SMALLICON window 
  3. LVS_LIST window
  4. LVS_REPORT window 

 

 LVS_ALIGNLEFT    // 图标或者小图标的视图并向左对其
  Items are left-aligned in icon and small icon view. 
   
  LVS_ALIGNMASK    // 限定控件的当前排成直线
  Determines the control's current alignment. 
  
  LVS_ALIGNTOP     // 图标或者小图标的视图并向上对其
  Items are aligned with the top of the list-view control in icon and small icon view. 
  
  LVS_AUTOARRANGE    // 图标自动排列在图标或小图标的视图里
  Icons are automatically kept arranged in icon and small icon view. 
  
  LVS_EDITLABELS    // 项的文本可以被编辑, 父窗口必须处理LVN_ENDLABELEDIT通知消息
  Item text can be edited in place. The parent window must process the LVN_ENDLABELEDIT notification message. 
  
  LVS_ICON     // 指定风格为icon
   This style specifies icon view
   
  LVS_LIST     // 指定风格为list
   This style specifies list view. 
   
  LVS_NOCOLUMNHEADER   // 不在report view中显示列头, 但是默认的情况下report view是有列头的
  Column headers are not displayed in report view. By default, columns have headers in report view. 
  
   
  LVS_NOLABELWRAP    // 项的文本显示在单行的图标视图, 但是默认情况下项文本包囊在图标视图中
  Item text is displayed on a single line in icon view. By default, item text may wrap in icon view. 

 LVS_NOSCROLL    // 滚动被禁用, 所以项必须在客户区域的外面
        // 这个风格无法与LVS_LIST或者LVS_REPORT风格并存
        // 
   Scrolling is disabled. All items must be within the client area. 
   This style is not compatible with the LVS_LIST or LVS_REPORT styles. 
   See Knowledge Base Article Q137520 for further discussion. 
  
  LVS_NOSORTHEADER   // 列头无法像button那样工作
        // 这个风格可以使, 在report view中如果点击一个列头使其无法具有事件, 例如排序
  Column headers do not work like buttons. 
   This style can be used if clicking a column header in report view does not carry out an action, such as sorting. 
  
  LVS_OWNERDATA    // 
   Version 4.70. This style specifies a virtual list-view control. 
   For more information about this list control style, see List-View Controls Overview. 
  
  LVS_OWNERDRAWFIXED   // 在report view这个拥有者窗口可以绘制项
        // 这个list-view控件发送WM_DRAWITEM消息去绘制每一个项
        // 对于每一个子项没有发送分开的消息
        // 这个项的数据为DRAWITEMSTRUCT结构, 包含了详述指定的list-view项
  The owner window can paint items in report view. 
   The list-view control sends a WM_DRAWITEM message to paint each item; 
   it does not send separate messages for each subitem. 
   The iItemData member of the DRAWITEMSTRUCT structure contains the item data for the specified list-view item. 
   
  LVS_REPORT     // 这个风格为report view
         // 当使用这个风格设置一个list-view控件时, 这第列一直项左对其
        // 你无法使用LVCFMT_RIGHT去改变, 更多查看LVCOLUMN关于列的对其
  This style specifies report view. 
   When using the LVS_REPORT style with a list-view control, the first column is always left-aligned. 
   You cannot use LVCFMT_RIGHT to change this alignment. See LVCOLUMN for further information on column alignment. 
  
  LVS_SHAREIMAGELISTS   // 这个图片列表讲不被删除当控件销毁时
        // 这个风格使用在 multiple list-view controls. 
   The image list will not be deleted when the control is destroyed. 
   This style enables the use of the same image lists with multiple list-view controls. 
   
  LVS_SHOWSELALWAYS   // 选中时,  或者任何时刻都一直显示
        // 甚至控件没有焦点时
  The selection, if any, is always shown, even if the control does not have the focus. 
   
  LVS_SINGLESEL    // 只有一行(项)可以被选中, 但是默认情况下多行可以选(项)中
  Only one item at a time can be selected. By default, multiple items may be selected. 
   
  LVS_SMALLICON    // 这个风格详述指定为小图标
  This style specifies small icon view.
   
  LVS_SORTASCENDING   // 项下表的排列基础为项的文本升序
  Item indexes are sorted based on item text in ascending order. 
   
  LVS_SORTDESCENDING   // 项下表的排列基础为项的文本降序
  Item indexes are sorted based on item text in descending order. 
   
  LVS_TYPEMASK    // 决定控件当前的窗口风格
  Determines the control's current window style. 
   
  LVS_TYPESTYLEMASK    // 决定窗口风格可以控制项的对其和头排列和行为
  Determines the window styles that control item alignment and header appearance and behavior. 

 
  LVSIL_NORMAL
  LVSIL_SMALL
  LVSIL_STATE


 Remarks:
   对于 LVS_SORTASCENDING 和 LVS_SORTDESCENDING 风格, 个别的项下标排列基础是项的文本
 升序或降序. 因为 LVS_LIST 和 LVS_REPORT 视图显示项的排序结果对于用户是立即可见的.
  
   这个 LVS_ICON 和 LVS_SMALLICON视图不使用项的小标去决定图片的位置, 有别与其他视图
 这个排序的结果对于用户是不可见的.
  
   你可以使用 LVS_TYPEMASK 掩码去分离这个窗口的风格让当前的视图是一至的:
  LVS_ICON, LVS_LIST, LVS_REPORT, 和 LVS_SMALLICON.
  
   你可以使用 LVS_ALIGNMASK 掩码去分离这个窗口的风格, 详述指定对齐项如下:
  LVS_ALIGNLEFT and LVS_ALIGNTOP.
  
   你可以使用 LVS_TYPESTYLEMASK 掩码去分离窗口的风格, 这个控件的对齐项如下:
  (LVS_ALIGNLEFT and LVS_ALIGNTOP), 或者用(LVS_NOCOLUMNHEADER and LVS_NOSORTHEADER)
  这些去控制头的外表和行为
 

  For the LVS_SORTASCENDING and LVS_SORTDESCENDING styles, 
  item indexes are sorted based on item text in ascending or descending order, respectively. 
  
  Because the LVS_LIST and LVS_REPORT views display items in the same order as their indexes, 
  the results of sorting are immediately visible to the user. 
  
   The LVS_ICON and LVS_SMALLICON views do not use item indexes to determine the position of icons. 
  With those views, the results of sorting are not visible to the user.
  
           // 分离的      // 一致的
 You can use the LVS_TYPEMASK mask to isolate the window styles that correspond to the current view:
  LVS_ICON, LVS_LIST, LVS_REPORT, and LVS_SMALLICON.
  

 You can use the LVS_ALIGNMASK mask to isolate the window styles that specify the alignment of items: 
   LVS_ALIGNLEFT and LVS_ALIGNTOP.

 You can use the LVS_TYPESTYLEMASK mask to isolate the window styles that control item alignment 
  (LVS_ALIGNLEFT and LVS_ALIGNTOP) and those that control header appearance and behavior (LVS_NOCOLUMNHEADER and LVS_NOSORTHEADER).

 


  
 4. List View Control Extended Styles

 设置扩展风格 LVM_SETEXTENDEDLISTVIEWSTYLE
  
     wParam = (WPARAM)dwExMask;
     lParam = (LPARAM)dwExStyle;
  

 LVS_EX_BORDERSELECT   // 版本 4.71 如果这个风格被设置, 当项被选中在一定程度上项的边框会高亮
 Version 4.71. If this style is set, 
  when an item is selected the border color of the item changes rather than the item being highlighted. 

 LVS_EX_CHECKBOXES    // 版本4.70 设置check boxes对于每一项在list-view控件中,
         // 当设置这个风格时, 这个控件创建和设置状态图片列表, 使用DrawFrameControl函数
        // 状态图片1是没有设置的checkbox, 状态图片2是有设置的checkBox
         // 设置状态图片为0去移除所有check box
         // 版本6.0 check box 是可见和有用的
 Version 4.70. Enables check boxes for items in a list-view control. 
  When set to this style, the control creates and sets a state image list with two images using DrawFrameControl. 
  State image 1 is the unchecked box, and state image 2 is the checked box. 
  Setting the state image to zero removes the check box altogether.
  Version 6.00 Check boxes are visible and functional with all list-view modes except the 
  tile view mode introduced in ComCtl32.dll 
  
  version 6. Clicking a checkbox in tile view mode only selects the item; the state does not change.
  You can obtain the state of the check box for a given item with ListView_GetCheckState. To set the check state, use ListView_SetCheckState. If this style is set, the list-view control automatically toggles the check state when the user clicks the check box or presses the space bar.


  LVS_EX_DOUBLEBUFFER   // 版本6.00, 通过双缓冲区绘制, 降低闪烁
        // 这个扩展的风格也使支持它的系统上的alpha混合的选取框。
 Version 6.00. Paints via double-buffering, which reduces flicker. 
  This extended style also enables alpha-blended marquee selection on systems where it is supported.

 LVS_EX_FLATSB     // 版本4.71. 设置肥胖的滚动条在list view
         // 如果您需要更多的控制列表视图的滚动条的外观,
        // 你应该直接使用平面滚动条的API操纵的列表视图的滚动条。
        // 如果系统指标的变化,你是负责调整与FlatSB_SetScrollProp滚动条指标。
        // 平面滚动条作进一步的详细信息,请参阅。
 Version 4.71. Enables flat scroll bars in the list view. 
  If you need more control over the appearance of the list-view's scroll bars, 
  you should manipulate the list-view's scroll bars directly using the Flat Scroll Bar APIs. 
  If the system metrics change, you are responsible for adjusting the scroll bar metrics with FlatSB_SetScrollProp. 
  See Flat Scroll Bars for further details.

 LVS_EX_FULLROWSELECT   // 版本4.70. 当一个项被选中, 这个行(项)和所有的子项都高亮
        // 这个风格仅仅在设置了LVS_REPORT风格时有效
 Version 4.70. When an item is selected, the item and all its subitems are highlighted. 
  This style is available only in conjunction with the LVS_REPORT style.

 LVS_EX_GRIDLINES    // 版本4.70. 在行(项)和子项中显示网格
        // 这个风格仅仅在设置了LVS_REPORT风格时有效
 Version 4.70. Displays gridlines around items and subitems. This style is available only in conjunction with the LVS_REPORT style.

 LVS_EX_HEADERDRAGDROP   // 版本4.70, 使list-view控件列的拖拽有效
        // 这个风格仅仅在设置了LVS_REPORT风格时有效
 Version 4.70. Enables drag-and-drop reordering of columns in a list-view control. 
  This style is only available to list-view controls that use the LVS_REPORT style.

 LVS_EX_INFOTIP     // 版本4.71 当list-view控件使用 LVS_EX_INFOTIP 风格时
        // LVN_GETINFOTIP通知消息在显示项提示时, 发送给父窗口
 Version 4.71. When a list-view control uses the LVS_EX_INFOTIP style, 
  the LVN_GETINFOTIP notification message is sent to the parent window before displaying an item's ToolTip.

 LVS_EX_LABELTIP    // 版本5.80。如果在任何列表视图模式,部分隐藏的标签,缺乏ToolTip文本,
        // 列表视图控件将开展的标签。如果没有设置这种风格,
        // 列表视图控件将开展部分隐藏的标签,只为大图标模式。
 Version 5.80. If a partially hidden label in any list-view mode lacks ToolTip text, 
  the list-view control will unfold the label. If this style is not set, 
  the list-view control will unfold partly hidden labels only for the large icon mode.

 LVS_EX_MULTIWORKAREAS  // 版本4.71, 如果list-view控件设置了LVS_AUTOARRANGE风格
        // 这个控件将不自动排列它的图标, 指定一个或多个工作区域是设定的
        // 让其有效, 这个风格必须设置在任何工作区定义和任何项添加到
        // 控件前
 Version 4.71. If the list-view control has the LVS_AUTOARRANGE style, 
  the control will not autoarrange its icons until one or more work areas are defined (see LVM_SETWORKAREAS). 
  To be effective, this style must be set before any work areas are defined and any items have been added to the control.

 LVS_EX_ONECLICKACTIVATE  // 版本4.70. 当用户单机了项时, 这个lit-view控件发送LVN_ITEMACTIVATE通知消息给
        // 这个风格也可以让鼠标移动到项上时, 使其高亮
        // 看扩展list-view扩展风格注意项
 Version 4.70. The list-view control sends an LVN_ITEMACTIVATE notification message to 
  the parent window when the user clicks an item. 
  This style also enables hot tracking in the list-view control. 
  Hot tracking means that when the cursor moves over an item, it is highlighted but not selected. 
  See the Extended List-View Styles Remarks section for a discussion of item activation.

 LVS_EX_REGIONAL    // 版本4.71。设置列表视图的窗口区域,包括的项目的图标和文字使用SetWindowRgn。
        // 任何地区,是不是一个项目的一部分被排除在窗口区域。
        // 这种风格是只提供给列表视图控件,使用LVS_ICON风格。
 Version 4.71. Sets the list-view window region to include only the item icons and text using SetWindowRgn. 
  Any area that is not part of an item is excluded from the window region. 
  This style is only available to list-view controls that use the LVS_ICON style.

 LVS_EX_SIMPLESELECT   // 版本6.00。在图标视图,动作控制的状态图像右上方的大图标呈现。
        // 在图标视图以外的意见,没有什么改变。
        // 当用户改变使用空格键的状态,所有选定的项目周期结束,没有重点项目。
 Version 6.00. In icon view, moves the state image of the control to the top right of the large icon rendering. 
  In views other than icon view there is no change. 
  When the user changes the state by using the space bar, all selected items cycle over, not the item with the focus.

 LVS_EX_SUBITEMIMAGES   // 允许子项显示图片
        // 这个风格仅限于 LVS_REPORT 风格
 Version 4.70. Allows images to be displayed for subitems. 
  This style is available only in conjunction with the LVS_REPORT style.

 LVS_EX_TRACKSELECT    // 版本4.70 在选中的list-view控件中支持热跟踪
        // 
  Version 4.70. Enables hot-track selection in a list-view control. 
  Hot track selection means that an item is automatically selected when the cursor remains(残余,遗迹,遗体)
  over the item for a certain(肯定) period(一段时间) of time. 
  The delay(延迟) can be changed from the default system setting with a LVM_SETHOVERTIME message. 
  This style applies to all styles of list-view control. You can check whether hot-track selection 
  is enabled by calling SystemParametersInfo.

 LVS_EX_TWOCLICKACTIVATE  // 版本4.70 这个list-view控件发送LVN_ITEMACTIVATE通知消息给父窗口,
         // 当用户双击项时
        // 这个风格也使 hot tracking 在 list-view 控件中有效
        // 
  Version 4.70. The list-view control sends an LVN_ITEMACTIVATE notification message to the parent window 
  when the user double-clicks an item. 
  This style also enables hot tracking in the list-view control. 
  Hot tracking means that when the cursor moves over an item, 
  it is highlighted but not selected. 
  See the Extended List-View Styles Remarks section for a discussion of item activation.

 LVS_EX_UNDERLINECOLD   // 导致这些非热下划线的文本显示的项目可能会被激活。
 Version 4.71. Causes those non-hot items that may be activated to be displayed with underlined text. 
  This style requires that LVS_EX_TWOCLICKACTIVATE be set also. 
  See the Extended List-View Styles Remarks section for a discussion of item activation.

 LVS_EX_UNDERLINEHOT   // 导致下划线的文本显示,那些可能被激活的热点项目。
 Version 4.71. Causes those hot items that may be activated to be displayed with underlined text. 
  This style requires that LVS_EX_ONECLICKACTIVATE or LVS_EX_TWOCLICKACTIVATE also be set. 
  See the Extended List-View Styles Remarks section for a discussion of item activation.

 
  Remarks

 Note  Comctl32.dll version 6 is not redistributable(可再发行的) but it is included in Microsoft 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.
  
  // 当鼠标移动到项上时, 这个项变成 hot
  // 如果hot-tracking是有效的, hot 项将高亮, 但是用户必须单机项在最后一次选中它
 // 一个活跃的项是因为list-view控件发送了 LVN_ITEMACTIVATE 通知消息
 // 当一个项在一个状态中被点击, 项就被选中
 An item becomes hot when the mouse hovers over it. 
  If hot-tracking is enabled, hot items will be highlighted, but the user must still click the item at least once to select it. 
  Activating an item causes the list-view control to send an LVN_ITEMACTIVATE notification. 
  An item may be selected when it is in a state in which a single click will select it.

 // 如果 LVS_EX_ONECLICKACTIVATE 风格被设置, 选择任何项单击是必须的, 所以所有项可以被选中
 // 如果 LVS_EX_TWOCLICKACTIVATE 风格被设置, 选择任何项双击是必须的
 // 借助于这个风格, 项可以被选中仅仅是在已经点击了一下后
 If the LVS_EX_ONECLICKACTIVATE style is set, only one click is required to select any item, so all items may be selected. 
  If the LVS_EX_TWOCLICKACTIVATE style is set, two clicks are required to select an item. 
  With this style, the item may be selected only after it has been clicked once.

 // 设置了 LVS_EX_UNDERLINEHOT 风格, 将导致任何选中的项文本加下划线
 // 设置了 LVS_EX_UNDERLINECOLD 风格, 将导致项的文本在没有 hot 时, 也可以被选中, 设置下划线
 Setting the LVS_EX_UNDERLINEHOT style will cause the text of any hot item that may be selected to be underlined. 
  Setting the LVS_EX_UNDERLINECOLD style will cause the text of items that are not hot, but may be selected, to be underlined.

 
 5. List-View Item States
  LVIS_ACTIVATING    // 目前不支持
 Not currently supported.

 LVIS_CUT      // 剪切状态
 The item is marked for a cut-and-paste operation.

 LVIS_DROPHILITED    // 这个项是高亮的在拖拽时
 The item is highlighted as a drag-and-drop target.

 LVIS_FOCUSED     // 这个项是高亮的, 所以是被标准焦点矩形围住
        // 虽然可能与更多项被选中, 但是仅仅一个项有焦点
 The item has the focus, so it is surrounded(围住的) by a standard focus rectangle. 
  Although more than one item may be selected, only one item can have the focus.

 LVIS_OVERLAYMASK    // 为覆盖在项上的图片设置一个掩码
 The item's overlay image index is retrieved by a mask.

 LVIS_SELECTED     // 这个项被选中. 选定项的外观取决于它是否有重点选择使用系统颜色。
 The item is selected. The appearance of a selected item depends on whether it has 
  the focus and also on the system colors used for selection.

 LVIS_STATEIMAGEMASK   // 为个项的状态图片设置一个掩码
 The item's state image index is retrieved by a mask.

 Remarks
  
  // 你可以使用 LVIS_OVERLAYMASK 掩码去分离覆盖的图片
 // 你可以使用 LVIS_STATEIMAGEMASK 掩码去分离状态的图片
 You can use the LVIS_OVERLAYMASK mask to isolate the one-based index of the overlay image. 
  You can use the LVIS_STATEIMAGEMASK mask to isolate the one-based index of the state image. 

 


 6. struct


 typedef struct tagNMLVCUSTOMDRAW
 {
     NMCUSTOMDRAW nmcd;
     COLORREF clrText;
     COLORREF clrTextBk;
 #if (_WIN32_IE >= 0x0400)
     int iSubItem;
 #endif
 #if (_WIN32_WINNT >= 0x501)
     DWORD dwItemType;

    // Item custom draw
     COLORREF clrFace;
     int iIconEffect;
     int iIconPhase;
     int iPartId;
     int iStateId;

    // Group Custom Draw
     RECT rcText;
     UINT uAlign;      // Alignment. Use LVGA_HEADER_CENTER, LVGA_HEADER_RIGHT, LVGA_HEADER_LEFT
 #endif
 } NMLVCUSTOMDRAW, *LPNMLVCUSTOMDRAW;


 nmcd
  NMCUSTOMDRAW structure that contains general custom draw information. 
  
 clrText
  COLRREF value representing the color that will be used to display text foreground in the list-view control. 
  
 clrTextBk
  COLORREF value representing the color that will be used to display text background in the list-view control. 
  
 iSubItem
  Version 4.71. Index of the subitem that is being drawn. If the main item is being drawn, this member will be zero. 
  
 /*
 dwItemType
  Version 6.0. DWORD that contains the type of the item to draw. This member can be one of the following values. 
  LVCDI_ITEM 
   An item is to be drawn.
  LVCDI_GROUP
   A group is to be drawn.

clrFace
  Version 6.0. COLORREF value representing the color that will be used to display the face of an item. 
  
 iIconEffect
  Version 6.0.  Value of type int that specifies the effect that is applied to an icon, such as Glow, Shadow, or Pulse. 

iIconPhase
  Version 6.0.  Value of type int that specifies the phase of an icon. 

iPartId
  Version 6.0.  Value of type int that specifies the ID of the part of an item to draw. 

iStateId
  Version 6.0.  Value of type int that specifies the ID of the state of an item to draw. 

rcText
  Version 6.0. RECT that specifies the rectangle in which the text is to be drawn. 

uAlign
  Version 6.0. UINT that specifies how a group should be aligned. This member can be one of the following values. 

 LVGA_HEADER_CENTER
   Center the group.
   
  LVGA_HEADER_LEFT
   Align the group on the left.
   
  LVGA_HEADER_RIGHT
   Align the group on the right.

*/

 

typedef struct tagNMCUSTOMDRAWINFO {
 NMHDR hdr;      // 含有通知信息的NMHDR结构;
  DWORD dwDrawStage;     // 目前绘制的步骤;
  HDC hdc;        // 设备上下文句柄;
  RECT rc;        // 绘制的区域;
  DWORD dwItemSpec;     // 绘制项目条的说明;
  UINT uItemState;     // 当前项目条的状态
  LPARAM lItemlParam;    // 应用程序规定的数据;
} NMCUSTOMDRAW, FAR * LPNMCUSTOMDRAW;

typedef struct tagNMCUSTOMDRAWINFO
 {
     NMHDR hdr;
     DWORD dwDrawStage;
     HDC hdc;
     RECT rc;
     DWORD_PTR dwItemSpec;     // 项编号
    UINT  uItemState;
     LPARAM lItemlParam;  // 自行定义的数据
} NMCUSTOMDRAW, *LPNMCUSTOMDRAW;


 hdr:
  NMHDR structure that contains information about this notification message. 
  
 dwDrawStage:

 // 在这些状态中, 通知操作系统(也就是返回相应的值), 我们要做的事
 CDDS_POSTERASE   擦除已结束
 CDDS_POSTPAINT  绘制已结束
 
  CDDS_PREERASE  擦除开始前
 CDDS_PREPAINT  绘制开始前

 
  Item-specific Values:
  
  // 在这些状态中, 做我们想要做的事
 CDDS_ITEM   如果在该阶段,那么dwItemSpec, uItemState, and lItemlParam 成员是可用的
 CDDS_ITEMPOSTERASE 项已擦除
 CDDS_ITEMPOSTPAINT 项以绘制
 
  CDDS_ITEMPREERASE 项擦除前
 CDDS_ITEMPREPAINT 项绘制前
 
  CDDS_SUBITEM  列 // 常用方式 (CDDS_ITEMPREPAINT | CDDS_SUBITEM)
  
 hdc:
  Handle to the control's device context. Use this HDC to perform any GDI functions. 

rc: // 只在于CDDS_ITEMPREPAINT消息时有效
 RECT structure that describes the bounding rectangle of the area being drawn.
  This member is initialized only by the CDDS_ITEMPREPAINT notification. 
  Version 5.80. This member is also initialized by the CDDS_PREPAINT notification. 

dwItemSpec:
  Item number. What is contained in this member will depend on the type of control that 
  is sending the notification. See the NM_CUSTOMDRAW notification reference for the 
  specific control to determine what, if anything, is contained in this member. 
  
 uItemState:
  Current item state. This value is a combination of the following: 

 CDIS_CHECKED  选中状态
 CDIS_DEFAULT  默认状态 
 CDIS_DISABLED  不可用状态
 CDIS_FOCUS   获得焦点状态
 CDIS_GRAYED   灰项
 CDIS_HOT   鼠标在其上
 CDIS_INDETERMINATE 不确定状态
 CDIS_MARKED   被标记状态
 CDIS_SELECTED  选中状态 
 CDIS_SHOWKEYBOARDCUES Version 6.0.The item is a keyboard cue. 
        Note that Comctl32 version 6 is not redistributable, 
        but it is included with Microsoft Windows XP or later operating systems. 
        To use Comctl32.dll version 6, specify it in the manifest. 
        For more information on manifests, see Using Windows XP Visual Styles.


 lItemlParam:
  Application-defined item data. 


 Remarks

 The value your application returns depends on the current drawing stage. 
  The dwDrawStage member of the associated NMCUSTOMDRAW structure holds a value that specifies the drawing stage. 
  
  When the dwDrawStage member equals CDDS_PREPAINT and CDDS_PREERASE, 
  some controls send the CDDS_PREERASE message first and expect 
  the return value to indicate which subsequent messages will be sent. 
  See CustomDrawButtonDlg for a code sample that illustrates states and drawing stages. 


  
  
  
  
  
返回值: 

 The value your application can return depends on the current drawing stage. 
  The dwDrawState member of the associated NMCUSTOMDRAW structure holds a value that specifies the drawing stage. 
  You must return one of the following values.


 // 发生在CDD_PREPAINT
  
 CDRF_DODEFAULT 
  // 返回这个消息, 控件将绘制它本身, 不会再发送任何额外的NM_CUSTOMDRAW消息给这个绘制周期
 // 这将发生在dwDrawState等于CDDS_PREPATINT
  The control will draw itself. It will not send any additional NM_CUSTOMDRAW messages for this paint cycle. 
  This occurs when dwDrawState equals CDDS_PREPAINT. 
  
 CDRF_NOTIFYITEMDRAW 
  // 这个控件将通知父窗口任何与该项相关联的操作
 // 将会发送NM_CURSTOMDRAW通知消息, 在开始和结束绘画项时
 // 这将发生在dwDrawState等于CDDS_PREPAINT
  The control will notify the parent of any item-related drawing operations. 
  It will send NM_CUSTOMDRAW notification messages before and after drawing items. 
  This occurs when dwDrawState equals CDDS_PREPAINT. 

CDRF_NOTIFYITEMERASE         // 未找到该宏的定义
 // 这个控件将通知父窗口当项将被擦除
 // 将会发送NM_CUSTOMDRAW通知消息在开始和结束擦除项时
 // 这将发生在dwDrawState等于CDDS_PREPAINT
  The control will notify the parent when an item will be erased. 
  It will send NM_CUSTOMDRAW notification messages before and after erasing items. 
  This occurs when dwDrawState equals CDDS_PREPAINT. 
  
 CDRF_NOTIFYPOSTERASE 
  // 这个控件将在擦除该项之后通知父窗口
 // 这将发生在dwDrawState等于CDD_PREPAINT
  The control will notify the parent after erasing an item. 
  This occurs when dwDrawState equals CDDS_PREPAINT. 

CDRF_NOTIFYPOSTPAINT 
  // 这个控件将在绘制该项之后通知父窗口
 // 这将发生在dwDrawState等于CDDS_PREPAINT
  The control will notify the parent after painting an item. 
  This occurs when dwDrawState equals CDDS_PREPAINT. 
  
  
 // 发生在CDDS_ITEMPREPAINT

CDRF_NEWFONT 
  // 这个应用程序详述指定了该项的字体
 // 这个控件将使用新的字体
 // 想要获取更多关于字体的变换, 查看变换字体和颜色
 // 这将发生在dwDrawState等于CDDS_ITEMPREPAINT
  The application specified a new font for the item; the control will use the new font. 
  For more information about changing fonts, see Changing fonts and colors. 
  This occurs when dwDrawState equals CDDS_ITEMPREPAINT. 

CDRF_NOTIFYSUBITEMDRAW 
  // 版本4.71. 你的应用程序将接收NM_CUSTOMDRAW消息, 当dwDrawState设置为CDDS_ITEMPREPAINT | CDDS_SUBITEM
  // 在每个list-view子项被绘制时
 // 到时你可以详述指定每个单独的子项字体和颜色, 或者返回CDRF_DODEFAULT默认的处理过程
 // 这将发生在dwDrawState等于CDDS_ITEMPREPAINT
  Version 4.71. Your application will receive an NM_CUSTOMDRAW message with dwDrawState set to 
  CDDS_ITEMPREPAINT | CDDS_SUBITEM before each list-view subitem is drawn. 
  You can then specify font and color for each subitem separately or return CDRF_DODEFAULT for 
  default processing. This occurs when dwDrawState equals CDDS_ITEMPREPAINT. 

CDRF_SKIPDEFAULT 
  // 这个应用程序自己手动绘制项, 这个控件将不绘制项
 // 这将发生在dwDrawState等于CDDS_ITEMPREPAINT
  The application drew the item manually. The control will not draw the item. 
  This occurs when dwDrawState equals CDDS_ITEMPREPAINT. 


  Version 5.80. If you change the font by returning CDRF_NEWFONT, the list-view control might display clipped text. 
  This behavior is necessary for backward compatibility with earlier versions of the common controls. 
  
  
  If you want to change the font of a list-view control, 
  you will get better results if you send a CCM_SETVERSION message with the wParam value set to 
  5 before adding any items to the control.


  
  
 typedef struct tagNMLVDISPINFO {
     NMHDR hdr;
     LVITEM item;
 } NMLVDISPINFO, *LPNMLVDISPINFO;

typedef struct _LVITEM { 
     UINT mask; 
     int iItem; 
     int iSubItem; 
     UINT state; 
     UINT stateMask; 
     LPTSTR pszText; 
     int cchTextMax; 
     int iImage; 
     LPARAM lParam;
 #if (_WIN32_IE >= 0x0300)
     int iIndent;
 #endif
 #if (_WIN32_IE >= 0x560)
     int iGroupId;
     UINT cColumns; // tile view columns
     PUINT puColumns;
 #endif
 } LVITEM, *LPLVITEM; 
 mask
  Set of flags that specify which members of this structure contain data to be set or which members are being requested. 
  This member can have one or more of the following flags set: 
  
 LVIF_COLUMNS
  The cColumns member is valid or must be filled in.
  
 LVIF_DI_SETITEM
 The operating system should store the requested list item information and not ask for it again. This flag is used only with the LVN_GETDISPINFO notification message.

LVIF_GROUPID
 The iGroupId member is valid or must be filled in.

LVIF_IMAGE
 The iImage member is valid or must be filled in.

LVIF_INDENT
 The iIndent member is valid or must be filled in.

LVIF_NORECOMPUTE
 The control will not generate LVN_GETDISPINFO to retrieve text information if it receives an LVM_GETITEM message. Instead, the pszText member will contain LPSTR_TEXTCALLBACK.

LVIF_PARAM
 The lParam member is valid or must be filled in.

LVIF_STATE
 The state member is valid or must be filled in.

LVIF_TEXT
 The pszText member is valid or must be filled in.

iItem
 Zero-based index of the item to which this structure refers. 
 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. 
 state
 Indicates the item's state, state image, and overlay image. The stateMask member indicates the valid bits of this member. 

Bits 0 through 7 of this member contain the item state flags. This can be one or more of the item state values.

Bits 8 through 11 of this member specify the one-based overlay image index. Both the full-sized icon image list and the small icon image list can have overlay images. The overlay image is superimposed over the item's icon image. If these bits are zero, the item has no overlay image. To isolate these bits, use the LVIS_OVERLAYMASK mask. To set the overlay image index in this member, you should use the INDEXTOOVERLAYMASK macro. The image list's overlay images are set with the ImageList_SetOverlayImage function.

Bits 12 through 15 of this member specify the state image index. The state image is displayed next to an item's icon to indicate an application-defined state. If these bits are zero, the item has no state image. To isolate these bits, use the LVIS_STATEIMAGEMASK mask. To set the state image index, use the INDEXTOSTATEIMAGEMASK macro. The state image index specifies the index of the image in the state image list that should be drawn. The state image list is specified with the LVM_SETIMAGELIST message.
 stateMask
 Value specifying which bits of the state member will be retrieved or modified. For example, setting this member to LVIS_SELECTED will cause only the item's selection state to be retrieved. 

This member allows you to modify one or more item states without having to retrieve all of the item states first. For example, setting this member to LVIS_SELECTED and state to zero will cause the item's selection state to be cleared, but none of the other states will be affected. 

To retrieve or modify all of the states, set this member to (UINT)-1.

You can use the macro ListView_SetItemState both to set and to clear bits.


 pszText
 If the structure specifies item attributes, pszText is a pointer to a null-terminated string containing the item text. If the structure receives item attributes, pszText is a pointer to a buffer that receives the item text. Note that although the list-view control allows any length string to be stored as item text, only the first 260 characters are displayed.

If the value of pszText is LPSTR_TEXTCALLBACK, the item is a callback item. If the callback text changes, you must explicitly set pszText to LPSTR_TEXTCALLBACK and notify the list-view control of the change by sending an LVM_SETITEM or LVM_SETITEMTEXT message.

Do not set pszText to LPSTR_TEXTCALLBACK if the list-view control has the LVS_SORTASCENDING or LVS_SORTDESCENDING style.
 cchTextMax
 Number of characters in the buffer pointed to by pszText. This member is only used when the structure receives item attributes. It is ignored when the structure specifies item attributes.
 iImage
 Index of the item's icon in the control's image list. This applies to both the large and small image list. If this member is the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the list-view control sends the parent an LVN_GETDISPINFO notification message to retrieve the index when it needs to display the image.
 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. You can also use the LVM_FINDITEM message to search a list-view control for an item with a specified lParam value. 
 iIndent
 Version 4.70. Number of image widths to indent the item. A single indentation equals the width of an item image. Therefore, the value 1 indents the item by the width of one image, the value 2 indents by two images, and so on. Note that this field is supported only for items. Attempting to set subitem indentation will cause the calling function to fail. 
 iGroupId
 Version 6.0 Identifier of the tile view group that receives the item. 
 cColumns
 Version 6.0 Number of tile view columns to display for this item. 
 puColumns;
 Version 6.0 Pointer to the array of column indices; length of cColumns. 
 Remarks

The LVITEM structure is used with a number of messages, including LVM_GETITEM, LVM_SETITEM, LVM_INSERTITEM, and LVM_DELETEITEM.

Use the last three items in this structure to insert an item into a tile view.

Note  Comctl32.dll version 6 is not redistributable but it is included in Microsoft 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.

 

转载于:https://www.cnblogs.com/moonwind/p/4491792.html

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值