Solved

Colored TreeView Items

Posted on 1997-05-06
7
358 Views
Last Modified: 2013-11-20
Environment: MFC 4.0, MSVC 4; Win95

Hi,
I need a TreeView that displays text and an associated color as text background or as icon.
The associated colors are not predefined, but can be selected with a CColorDialog.
This seems a problem that turns up every day - but I found no solution in MFC.
I tied:
1) Using CImageList  does  not seem to make sense, since I don’t know the colors selected in advance and CImageList::SetBkColor seems to change the back ground color for all images in the list.
2) I_IMAGECALLBACK seems to call the parent of my TreeView, but I want to handle it all in TreeView.

any help is welcomed

Edgar
0
Comment
Question by:EHaimerl
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1301349
re: 2) above, use a message reflector instead, ie:

ON_NOTIFY_REFLECT ( LVN_GETDISPINFO, OnGetdispinfo )

Then you can handle the requests generated by I_IMAGECALLBACK within your tree control class.

0
 

Author Comment

by:EHaimerl
ID: 1301350
OK - now I am in OnGetdispinfo. But how do I change the background color for a single item in the TreeView?

I tried this:

void CAutoTaxView::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
{      
      TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
      // TODO: Add your control notification handler code here

      // set new BkgColor - THIS DOES NOT WORK !!
      SetBkColor( ::GetDC( pNMHDR->hwndFrom), RGB (255,0, 0));
      *pResult = 0;
}

Seems as if something's not OK with pNMHDR->hwndFrom. I suppose hwndFrom belongs to one single textlable, is this right? Why can I not get the DC and define the background color??

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301351
The won't work - GetDC won't necessarily return the same DC as the control is using for drawing.

What I assumed you would do is check the pTVDispInfo->item.mask bits to dertermine that is was actually an image you wanted, and change the image for this item to be the appropriate color.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:EHaimerl
ID: 1301352
It tried to find some way around this problem but it seems, that painting the background for each TreeView item separatly does not work. So I am trying the first method now: Use CImageList, fill the list with the colors I need and attach it to the Tree Items. But no success. I find no way to create bitmaps from RGB information only without a hDC.  
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1301353
Simply create a compatible DC and select your desitnation bitmap (image list) into it then use PatBlt to fill it, or just use std GDI calls to fill a rectangle with color(s).
0
 

Author Comment

by:EHaimerl
ID: 1301354
Thats what I tried (beside many other things): But I cannot change the Bitmaps in m_imageList.
I  load 1 defaultBitmap 8 times into m_imageList  in CImageListView() constructor.
Here I try to change the images but nothing happens.
The defautl image is printed (m_imageList.draw) without any changes.

int CImageListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{   int i;
     CBrush Brush;
     CBitmap Bitmap;
     CSize Size(32,32);  
     if (CView::OnCreate(lpCreateStruct) == -1)
       return -1;
    // Simply create a compatible DC and select your
    //desitnation bitmap   (image-list) into it
    CDC dcMem;
    dcMem.CreateCompatibleDC ( GetDC() );
    dcMem.DPtoLP(&Size);
    for (i=0; i < 8; i++)
    {   dcMem.SelectObject ( m_imageList.ExtractIcon(i) ) ;
        // then use PatBlt to fill it, or
       //    just use std GDI calls to fill a rectangle with color(s).
      dcMem.FillSolidRect ( 0, 0, Size.cx, Size.cy, ( RGB ( 255, 250, 0 ) ) );
}

/* Brush.CreateSolidBrush(RGB (255,0,120) );
for (i=0; i < 8; i++)
{dcMem.SelectObject ( Brush );
dcMem.SelectObject ( m_imageList.ExtractIcon(i) );
dcMem.PatBlt( 0, 0, 32, 32, PATCOPY );
}
*/
return 0;      
}


thanks for you answer.
0
 

Author Comment

by:EHaimerl
ID: 1301355
Hi Mr. Ronslow,I am waiting for an answer or at least a good hint ...I tried a lot of differnt things in the last days, no success. The problem seems to be, that you cannot change the bitmaps in the imageList as you would do with ordinary bitmaps?If you have no solution be so kind an hand the problem over to another expert.thanks for your response.  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 112
isEverywhere  challenge 19 86
wait notify demo infinite loop 3 137
fix34  challenge 9 168
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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