Solved

Colored TreeView Items

Posted on 1997-05-06
7
337 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 87
Unix / Linux grid computing 5 127
viewing source code from eclipse 13 74
format the code in java 6 72
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…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now