One way is to draw the listbox yourself. Create a member variable which holds the color for your listbox. Depending on the condition you can set your membervariable with a certain color and call Invalidate() and your listbox will be redrawn with the color you want. Try a search on custom drawing techniques. Hope this helps.
Simply ret the rect of Selected Row.and then use Fillrect() method to Fill the Color in that particualr Row.The Following Code Will Change The List Control alternative Row Color.
Simply ret the rect of Selected Row.and then use Fillrect() method to Fill the Color in that particualr Row.The Following Code Will Change The List Control alternative Row Color.
Simply ret the rect of Selected Row.and then use Fillrect() method to Fill the Color in that particualr Row.The Following Code Will Change The List Control alternative Row Color.
Where would you have this piece of code? Judging by the GetDlgItem() call, somewhere in the dialog? Why would you paint List Control from the Dialog's code? Wouldn't that be painted over by the control?
Custom colors should be applied by processing NM_CUSTOMDRAW notification.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
Where would you have this piece of code? Judging by the GetDlgItem() call, somewhere in the dialog? Why would you paint List Control from the Dialog's code? Wouldn't that be painted over by the control?
Custom colors should be applied by processing NM_CUSTOMDRAW notification.
OP want to change the list Control color at run time.and you can't do a logic for this in your custom draw so manually you have to paint your List Control you can use above code at the time when you want to change the Color of any row at run time.for this you have to get Client rect etc and other thing.
OP want to change the list Control color at run time.and you can't do a logic for this in your custom draw...
Why not? Sure you can, use the same logic...
Originally Posted by humptydumpty
...you have to paint your List Control you can use above code at the time when you want to change the Color of any row at run time....
And the list control will erase your drawing the very next time you click on something in it, scroll it or change the data in some way.
Also, your control has no data in it...
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
Listen List Control Fire a Event NM_CUSTOMDRAW whenever you are performing some calculation on list control it can be deletion insertion etc.but Simply Clicking on List Control Doesn't going to Fire any Custom draw message For you.and if you have some sample then Please demonstate this.
remember Don't forget to consider OP condition.
thanx
Listen List Control Fire a Event NM_CUSTOMDRAW whenever you are performing some calculation on list control it can be deletion insertion etc.but Simply Clicking on List Control Doesn't going to Fire any Custom draw message For you.
Clicking on the list can change selection and focus - both of these state changes will cause custom draw request.
Your code sample simply draws red and white stripes over the area where list control is. And I suspest there are problems even with this task...
Regardless, ANY CHANGE to a list control will cause paint right over these stripes.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
// Take the default processing unless we set this to something else below.
*pResult = 0;
// 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;
// Store the color back in the NMLVCUSTOMDRAW struct.
pLVCD->clrText = crText;
// Tell Windows to paint the control itself.
m_obj->check = "";
*pResult = CDRF_DODEFAULT;
}
}
It is working but some problem is there i.e.
1: It changes only the colour of a subitem not comlete row
2: when I click on other other row . the color of row is being changed with subitems color
Please tell me What changes should i make to prevent this
Thanks
First THing you have to set style LVS_EX_FULLROWSELECT to your ListControl to select Complete Row of list Control. Second I am not Sure How you are going to achieve this i Will Suggest simply paint your list Control With your Self.and Still if you want to handle it in your Custom Draw Then use some Short of Collection Classes. and Store in That your List Control Row index and Corresponding COLORREF Value.Now you can Perform your calculation in your CustomDraw in a Efficient manner. and i think you can do this very easily wothout worry other things. like in my 3rd Post i suggest to perform a lots of calculation on your List Control.
Hi
I m posting the detailed description of my problem with demo code
please take a step before compiling this.
1: copy temp.txt from debug folder to "c" derive.
2: there is no any function to stop the running thread so it will prompt error message on close( no issue) ;
now i explain what i want to do..........
when i run my project and start all server some row contains online status and some offline .
If any row consist Offline i want to change its colour or text colour so that user can easily get the down server.
I have tried lot of thing but i could not make it.
Please try to resolve my issue.
Thanks in Advance...................Expecting a favorable reply..
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.