?
Solved

Colored TreeView Items

Posted on 1997-05-06
7
Medium Priority
?
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 200 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

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

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!

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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