Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dumb question on CListControl

Status
Not open for further replies.

FORAND

Programmer
May 26, 2003
64
CA

How can I change the color of an Item in a CListControl.
I'd like to have one item (text only) in blue... But all i can get is to have the WHOLE box's items to turn blue.....


hElP:!!!
 
you have to change items icon

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
You need to do an "Owner Draw" list control. Owner Draw is a style that you set when creating the control. When set your window handles more messages that allow you to control things like color of specific row etc. There is sample code on MSDN and probably other places like CodeProject.

-pete
 
The sample did not help me... could you be more specific?
 
Thanks. I THINK it will work after i solve this :

VC++ says that this line is not right... :
ON_NOTIFY ( NM_CUSTOMDRAW, IDC_LIST, OnCustomdrawMyList )

error C2440: 'type cast' : cannot convert from 'void (__cdecl *)(struct tagNMHDR *,long *)' to 'void (__thiscall CCmdTarget::*)(struct tagNMHDR *,long *)'

... damn i'm not good in VC++ ...
Help ùe on this one and i'll send some money to this site via paypal.
 
There is something wrong with the signature for your OnCustomdrawMyList() member function. Post both the declaration and definition signatures.

Use the [ c o d e ] TGML tags. If you don't know how to use them see the online help for TGML by clicking the link in the [red]Step 2 Options[/red] below the post edit box.

-pete
 

Code:
ON_NOTIFY ( NM_CUSTOMDRAW, IDC_LIST, OnCustomdrawMyList )


Code:
afx_msg void OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult );


Is this what you wanted?
 
>> ON_NOTIFY

So the code you posted is in a CDialog derived class?

-pete
 
Yeah i tried to reproduce the problem but can't so far. From the error message it appears the compiler does not believe that your class that contains the OnCustomdrawMyList function is of type CCmdTarget.

Of course CDialog does so ??

Post the signature of that function definition. It should look something like
Code:
void CMyDlg::OnCustomdrawMyList(...)
. Also post the class declaration for that class.

-pete
 
I got it... i made a stupid mistake...

Now i've copied the exact code as in the sample at
I've manage to make this work :


Code:
void CMyDlg::OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult )
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );

    // Take the default processing unless we set this to something else below.
    *pResult = CDRF_DODEFAULT;

    // First thing - check the draw stage. If it's the control's prepaint
    // stage, then tell Windows we want messages for every item.

    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
        {
        *pResult = CDRF_NOTIFYITEMDRAW;
        }
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
        {
        // This is the prepaint stage for an item. Here's where we set the
        // item's text color. Our return value will tell Windows to draw the
        // item itself, but it will use the new color we set here.
        // We'll cycle the colors through red, green, and light blue.

        COLORREF crText;

        if ( (pLVCD->nmcd.dwItemSpec % 3) == 0 )
            crText = RGB(255,0,0);
        else if ( (pLVCD->nmcd.dwItemSpec % 3) == 1 )
            crText = RGB(0,255,0);
        else
            crText = RGB(128,128,255);

        // Store the color back in the NMLVCUSTOMDRAW struct.
        pLVCD->clrText = crText;

        // Tell Windows to paint the control itself.
        *pResult = CDRF_DODEFAULT;
        }
}

But I'd like to have only ONE line in red. Only the line that i want.

I'm makin progress ;)
 
Great! Glad you see you are rollin. [cheers]

>> But I'd like to have only ONE line in red. Only the line that i want.

You see where to do that right? [2thumbsup]


-pete
 
Will the OnCustomdrawMyList fuction will be called to draw EACH item?


 
Will the OnCustomdrawMyList fuction will be called to draw EACH item?

AND

I seem to have some problems to compare the pLVCD->nmcd.dwItemSpec with an other data... and when i try debug and i place a watch on the data, I get this :Error in OMF type information.

arg!!! So close now....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top