CListBox item background - mfc

I need to set background CListBox background.
I can't find solution for set different colors for each item.
How can I do that?

To get different colors for each item you have to owner-draw the list box. That means you must paint each item yourself. See the CTRLTEST sample in MSDN.

Related

C++ MFC How to draw selection rectangle?

I have a list control. I want to draw selection rectangle on my own.
For example: when i clicked on an item it will draw an selection ractangle on that item and the item is next to it (or can be somewhere else).
Can anybody tell me how to do that ?
Thank you!
To draw a focus rectangle, call the DrawFocusRect function. To enable Visual Styles, call the DrawThemeBackground function (Parts and States: LBCP_ITEM and LBPSI_SELECTED).
Either way, you will have to create an owner-drawn List Box to be able to adjust rendering. For an MFC CListBox control you have to override at least CListBox::DrawItem (and usually also CListBox::MeasureItem).

How to disable ListView select visual effect and draw a rectangle around item instead?

When a ListView item is selected, its color changes to indicate that it is selected. Now what I want to do is to disable this visual effect and implement my own, so for example I want when an item is selected to draw a rectangle around the item.
How can I do that? (Note that I am talking about the Icon view).
This is a case for custom drawing of controls.
It's all about handling the NM_CUSTOMDRAW notification and then to draw the control more or less by yourself.
I've never done it by myself changing the appearance seriously but I've change background colors of controls using this mechanism.
There is a lot of information about this on the internet...

Button in MFC CtreeCtrl column

I have a CTreeListCtrl in my MFC application.What I need to do is add a button in a particular column of a node when a particular condition is satisfied(type is changed to reference).
In the image I have edited and added a blue rounded oval to mark the place of desired button.What I want to do is to invoke a dialog on clicking it.But I don't have any clue whether it is possible or not.If yes then pls give me some suggesions.
This is no normal tree control. It is already customized to use multiple columns and I am sure it uses some kid of owner draw. For me it seams more like a list control with tree Features... I know some similar code from Codepproject..
Creating a "real" button (window) isn't wise/good. because it is another window inside the list control...
Change your code to "Draw a button. You can use DrawFrameControl.
Just intercept the left mouse click. Check the range if this area is cliecked. Fire a user defined message to the parent window.

Setting the color of the highlighted item in list when it has no input focus by means of CMFCVisualManager Class

Brief introduction:
In order to set custom look for control elements of my Win application I use CMFCVVisualManagerOffice2007 which has the set of mapping: color->element of control, and implements drawing of controls, based on that mapping, this allows to give consistent look to the application.
I override some mappings, by providing colors I need, in order to organize my own palette.
Problem description:
I need to change the color of the item selected in the list, when list has no input color.
When the list has input focus - it is alright,selected element is highlighted with the blue, clearly visible color, but when focus is lost - it is highlighted with gray which doesn`t fit to the palette of my application.
Among mappings I can`t find one for the case when element of the list, with always select style, is selected, but that list has no input focus.
I am aware that I can implement my own draw for that list and set color I need for the situation when element is highlighted and hasn`t got the input focus.
But I want to find the solution based on the configuration of palette.
Question:
What is the name of palette element what represents color for highlight of selected element in the list which has no focus?

How to prevent an icon being highlighted?

I have a listwidget with items which have icons. When the item is selected both the text and the icon are highlighted. My problem is that when the icon is highlighted it just goes entirely black because I'm using only two colours. Is there a way to prevent the icon from being selected?
You can add additional images to the QIcon, depending on it's state:
QIcon icon(...);
icon.addFile("selected.png", size, QIcon::Selected);
See also the documentation of QIcon::addFile().
Best solution was to make your own qstyle which handled the painting of the backgrounds of listitem sub controls and draw the icons qrect as white
Another possibility would be to reimplement QListWidgetItem... You could therefore have a bigger control on how things gets done during the process of selection and painting...
Of course, it's a lot more work...