[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Unable to color sub items in a CListCtrl

Posted on 1999-11-29
5
Medium Priority
?
957 Views
Last Modified: 2013-11-20
I am changing the colors of separate lines of a CListCtrl using OnCustomDraw, but it cannot change the text color of sub items (only the background is changed). Can someone tell me what I should change to solve this problem - is it possible from whithin OnCustomDraw?. The code of the OnCustomDraw I am using is as follows:


void CMyListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
      LPNMLVCUSTOMDRAW lvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
      switch(lvcd->nmcd.dwDrawStage)
      {
            case CDDS_PREPAINT:
                  *pResult = CDRF_NOTIFYSUBITEMDRAW;
                  break;
            case CDDS_ITEMPREPAINT:
                  *pResult = CDRF_NOTIFYSUBITEMDRAW;
                  break;
            case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
            {
                  *pResult = CDRF_DODEFAULT;
                  int iCol = lvcd->iSubItem;
                  int iRow = lvcd->nmcd.dwItemSpec;

                  COLORREF c = RGB(240, 240, 255);
                  CBrush brush(c);
                  CRect rc;
                  GetCellRect(iRow, iCol, LVIR_BOUNDS, rc);
                  // get the device context.
                  CDC *pDC= CDC::FromHandle(lvcd->nmcd.hdc);
                  pDC->FillRect (rc, &brush);
                  lvcd->clrTextBk = c;
                  lvcd->clrText = ::GetSysColor(COLOR_HIGHLIGHT);
                  *pResult = CDRF_NEWFONT;

                  break;
            }
            default:
                  *pResult = CDRF_DODEFAULT;
      }
}

0
Comment
Question by:Brian_HP
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
V_Bapat earned 50 total points
ID: 2240452
Remove these lines:

COLORREF c = RGB(240, 240, 255);
CBrush brush(c);
CRect rc;
GetCellRect(iRow, iCol, LVIR_BOUNDS, rc);
// get the device context.
CDC *pDC= CDC::FromHandle(lvcd->nmcd.hdc);
pDC->FillRect (rc, &brush);


Just put:

lvcd->clrTextBk = RGB(240, 240, 255);
lvcd->clrText = ::GetSysColor(COLOR_HIGHLIGHT);
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2240457
Also try this:

lvcd->clrText = RGB(255, 0, 0);

Vicky
0
 

Author Comment

by:Brian_HP
ID: 2240586
First, the delete lines proposed are need, otherwise white areas can appear! Therefore, I could not delete that.

The proposed answer did not help, but the comment helped: The actual problem was the ::GetSysColor because COLOR_HIGHLIGT is different for subitems than for the main item.
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2240620
>First, the delete lines proposed are need, otherwise white areas can appear!

I did not get you. Can you please tell me what is the purpose of that? And what do you mean by 'white areas can appear'?

Vicky
0
 

Author Comment

by:Brian_HP
ID: 2240673
Ok.

Assume an item of the CListCtrl is selected, then it gets colored by the above. The CListCtrl looses the focus and afterwards it is repainted for some reason, the above coloring is still present but a white area (rectangle) appears between the end of the text of the main item and the sub item, eg.
  ["MAIN ITEM"xxxxxxxxxx"SUB ITEM"]
The x'ed area is white and the "..." areas are in 'my' color.

Was this more clear ?

Brian
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

611 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question