سؤال

I need to get the column id will be drawn. 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.

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

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.

The documentation describes the member thus:

iSubItem

Type: 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. If you can't then you will need to make sure you have _WIN32_IE defined (directly or indirectly) to be at least 0x0400.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top