How to get the item state in NM_CUSTOMDRAW notification of a header in listview

Windows specific questions.
Post Reply
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

How to get the item state in NM_CUSTOMDRAW notification of a header in listview

Post by kcvinu »

Hi all,
I have a list view control and I am trying to do the custom draw for header control. So far so good. This is the code. Sorr, it's D. But I think it's readable for you guys.

Code: Select all

case WM_NOTIFY:                
    auto nmcd = cast(NMCUSTOMDRAW*) lParam;    
    switch (nmcd.hdr.code) {
        case NM_CUSTOMDRAW :                                          
            switch (nmcd.dwDrawStage) {
                case CDDS_PREPAINT : 
                    /* When drawing started, system will send a NM_CUSTOMDRAW notification to...
                    parent of the control. Here, parent of header control is list view. So we...
                    get the notification with WM_NOTIFY message. We returns the CDRF_NOTIFYITEMDRAW...
                    value so that system will notify us when the pre paint stage begins for each item.*/ 
                                                     
                    return CDRF_NOTIFYITEMDRAW ; break;
                
                case CDDS_ITEMPREPAINT :      
                    /* So we get the notification at the pre paint statge. We can draw the header...
                    colors, text and tell the system to not to draw anything on this header. So...
                    system will skip the default drawing jobs. */ 
                    print("item state", nmcd.uItemState); // this will print 0
                    lv.headerCustomDraw(nmcd);
                    return CDRF_NEWFONT | CDRF_SKIPDEFAULT;
                    break;                 
                
                default : break;
            } break; 
        default : break;
    }
    
    break;
    
And here is the function to draw the headers,

Code: Select all

void headerCustomDraw(NMCUSTOMDRAW* nmcd) {
    auto colTxt = this.mColumns[nmcd.dwItemSpec].text;  // Get the column text                                  
    SetBkMode(nmcd.hdc, TRANSPARENT);            
    auto rct = adjustRect(nmcd.rc,0, -1); 
    FillRect(nmcd.hdc, &rct,  this.mHdrBkBrush ); // Paint the background                                   
    if (this.mHdrDrawFC) SetTextColor(nmcd.hdc, this.mHdrFrClrRef); // Set the text color
    if (this.mHdrDrawFont)  SelectObject(nmcd.hdc, this.mHdrFont.handle);                
    DrawText(nmcd.hdc, colTxt.toUTF16z, -1, &nmcd.rc, mTxtFlag ) ;  // Drawing text again
    
}
My problem is - I can't get the proper item state from uItemState member of NMCUSTOMDRAW struct. It prints always a zero. But if I click on the header, it prints 1. AFAIK, uItemState is the control's current state. Later, I have tried to find the bit mask method to get the exact value like this.

Code: Select all

if ((CDIS_HOT & nmcd.uItemState) == CDIS_HOT) {/* do something */;}
But that too didn't worked.
Why I am trying to get the item state ?
Ans : Since I am returning CDRF_SKIPDEFAULT flag, I am responsible for the rest of the drawing job. So I want to change the back color of this header when mouse entered. In order to do that, I must get the item state. Please help. Thanks in advance.
SARG
Posts: 1756
Joined: May 27, 2005 7:15
Location: FRANCE

Re: How to get the item state in NM_CUSTOMDRAW notification of a header in listview

Post by SARG »

Are you using LVS_SHOWSELALWAYS style ?
It seems causing problem and in this case use LVM_GETITEMSTATE to get the state of the item.

Hope it helps but no warranty :wink:
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: How to get the item state in NM_CUSTOMDRAW notification of a header in listview

Post by kcvinu »

@SARG,
Thanks for the reply. But I am not using that flag.
This is the style I am using in this LV

Code: Select all

DWORD lvStyle = WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|LVS_REPORT|WS_BORDER|LVS_ALIGNLEFT|LVS_SINGLESEL;
SARG
Posts: 1756
Joined: May 27, 2005 7:15
Location: FRANCE

Re: How to get the item state in NM_CUSTOMDRAW notification of a header in listview

Post by SARG »

ok.
Did you try LVM_GETITEMSTATE ?
kcvinu
Posts: 232
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: How to get the item state in NM_CUSTOMDRAW notification of a header in listview

Post by kcvinu »

@SARG,
LVM_GETITEMSTATE is for get the lv item. I want to know about the item state (which means, weather the item is under mouse pointer, or the item is selected etc.) Here, item means each column of header. Not the lv item. I am drawing the header.
Post Reply