简体   繁体   English

在NMLVCUSTOMDRAW C ++中获取列ID

[英]Get Column ID in NMLVCUSTOMDRAW C++

I need to get the column id will be drawn. 我需要获取列ID。 This is my some of my code I try to get item id and column id to use ListView_GetItemText and set the correct color of the item to be drawn. 这是我的一些代码我尝试获取项目ID和列ID以使用ListView_GetItemText并设置要绘制的项目的正确颜色。

switch( ((LPNMLVCUSTOMDRAW)lParam)->nmcd.dwDrawStage){
case CDDS_PREPAINT:
    return CDRF_NOTIFYITEMDRAW;
    break;
case CDDS_ITEMPREPAINT:
   {
    LPNMLVCUSTOMDRAW customDraw = (LPNMLVCUSTOMDRAW)lParam;
    int itemid = (customDraw->nmcd).dwItemSpec //this is item id
    //column id is missing                                                                                          
    return CDRF_NEWFONT;
        break;
   }
default: return CDRF_DODEFAULT;
}

if you include 如果你包括

case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
     int iSubItem = ((LPNMLVCUSTOMDRAW)lParam)->iSubItem;
break;

this will get you the column. 这将为您提供专栏。 The reason why this isn't happening is you have to return the notifications you want to receive in the future through the LRESULT pointer passed in the function header, so for instance 没有发生这种情况的原因是您必须通过函数头中传递的LRESULT指针返回您希望以后接收的通知,例如

If your function header looked like: 如果您的函数标题如下所示:

::OnNMCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)

You'd need: 你需要:

*pResult |= CDRF_NOTIFYITEMDRAW;
*pResult |= CDRF_NOTIFYSUBITEMDRAW;
*pResult |= CDRF_NOTIFYPOSTPAINT;
*pResult |= CDRF_NOTIFYPOSTERASE;

At the end of your function 在你的功能结束时

NMLVCUSTOMDRAW contains a member called iSubItem , this will tell you which "column" is being drawn. NMLVCUSTOMDRAW包含一个名为iSubItem的成员,它将告诉您正在绘制哪个“列”。

The documentation describes the member thus: 文档描述了该成员:

iSubItem

Type: int 输入: int

... Index of the subitem that is being drawn. ...正在绘制的子项目的索引。 If the main item is being drawn, this member will be zero. 如果正在绘制主项目,则该成员将为零。

You should be able to refer to it via customDraw->iSubItem . 您应该能够通过customDraw->iSubItem引用它。 If you can't then you will need to make sure you have _WIN32_IE defined (directly or indirectly) to be at least 0x0400 . 如果你不能那么你需要确保_WIN32_IE定义(直接或间接)至少为0x0400

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM