MFC: How to change color/boldness of inidividual rows of ListCtrl?

纵饮孤独 提交于 2019-12-05 06:09:25

The key message here is the NM_CUSTOMDRAW message sent to your CListCtrl (and some other controls). It allows you to tell Windows that you want to custom draw some part of the CListCtrl. The idea is that the message allows you tell which part of the control should be custom drawn. Because custom drawing the whole CListCtrl only to change the text color of a cell would be totally overkill.

Don't worry, you don't have to handle custom draw yourself: The message allows to set the font and/or text/back color for one specific row or cell of the control.

This codeproject article is probably a good starting point.

Here is a shorter code example to set the color of a specific line in your CListCtrl.

You can use the following code to alter the whole list backgroud colour but I am not sure there is supported functionality to change the colour per row. Following is the code:

YourControl.SetBkColor(RGB(212,208,200));

I hope it helps.

Wysla

Here is what i did to my program, if the row i want highlighted is a cin or a cout or any other just put this code above the that row

SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);

the last part i.e, 0x0F lets u change the colour code of the background and text

after changing that to your desired colour, just insert another below the row you want highlighted, i.e;

 SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), 0x0C);

here is the table of colours and their codes

    0 = Black       8 = Gray
    1 = Blue        9 = Light Blue
    2 = Green       A = Light Green
    3 = Aqua        B = Light Aqua
    4 = Red         C = Light Red
    5 = Purple      D = Light Purple
    6 = Yellow      E = Light Yellow
    7 = White       F = Bright White

EXAMPLE for a black background and blue text;

SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), 0x01);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!