CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Cannot see image using CTreeCtrl

    Quote Originally Posted by Jim Bassett
    ... sorry for my lack of knowledge on "Code tags"
    You had to have read the "Announcement: Before you post.... " section before you posted to this Forum.

    As I wrote you, at least twice, you should always use _T() macro with the text values. Why are you using it only "occasionally"? Because the text appeared whether I used _T or left it off, the main thing I always had to do and the Microsoft Example did as well is always recasting to (LPCTSTR) and I was only mixing it trying to understand what the difference is since I didn't have to use it (_T) but always had to use LPCTSTR.
    Casting ANSI string to (LPCTSTR) will fail in the UNICODE build.
    Note: casting is not the same as conversion!

    Again Victor I do appreciate the help!!! But please I don't need a lecture and even Microsoft is a little puzzled on this one.
    Where did you see "a lecture"?
    I only tried to point you out (and not once!) that you are doing serious mistakes!
    Having an image list object locale variable already causes what you have: images cannot be displayed, since they already have been destroyed!
    Thus all other variations make no sense!

    You also refer to some "Microsoft Example". What is it? Does the example (without modifying by you) work? If yes - start with this and modify it step by step for your needs.

    And finally: you are absolutely free to follow the advices you get in this Forum or to ignore them. But if you ignore - why do you re post the same problem with the same mistakes?

    With the best regards,
    Victor
    Last edited by VictorN; June 13th, 2007 at 12:54 PM.

  2. #17
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    Thumbs up Re: Cannot see image using CTreeCtrl

    Victor

    Again I appreciate your help but I been using CodeGuru for over 10 years and I have never had anyone tell me how I need to tag code examples or do this or question why I am posting, etc. which is what you have done for the last two posts. I have also helped others when I have been able to but I get more help than I help others but I would never lecture someone. Victor I apologize for being sensitive but I am working on various projects involving a mix of different technologies with them having nearly the same deadlines so I am stressed out big time here and fit to be tied that the documentation on the use of the tree control and images is poor. If your intent was not to be lecturing me OK but it comes across to me like that especially under the conditions going on here so please try to understand.

    On the matter of the _T, it works with or without it at least on my machine and I am not having a text problem, it is a bitmap problem which has been my main focus. I do appreciate you pointing out the _T but as I have said that is not affecting the bitmap appearance and I am not seeing any effects of using it or not using it.

    You were right about the image object needed to be a member of the dialog class that the tree control resides in, which I pointed out in my last reply but doing that alone did not solve the problem nor did it give me any clue to the problem so I did not think that had anything to do with it. Yes it has to be a member of the dialog class I am using the tree control in which I will do as production code but this was a simple quick and dirty three away learning piece of code so I was doing it quick and need to change that practice. Yes I should have realized the image would not appear in the tree since the image object went out of scope but I was wrongly under the impression that the SetImageList method was placing the image into the tree object and the image object was no longer needed, my mistake which I have no problem admitting. One issue is I haven’t done any MFC coding for 7 years now and I am helping out on creating this dialog in addition to other coding and management tasks so that the project this dialog is involved with comes in on time or nearly on time. Now the second part of the image problem was the second and third parmeters in the image create method ( m_ImgList.Create(IDB_BITMAP1, 16, 10, RGB(255,255,255)); and their purpose is not clear in the documention nor their use/purpose and you also made no mention of them which I can understand because the documentation and examples for using the tree control is poor as far as I am concern. I have been trying so many different things and not getting naywhere which is why I posted on CodeGuru and on the MS MFC forum. Suggestions I received made sense but also didn’t help and even the MS engineer had to research it to see what was occurring and how to code it, he didn’t just grind it out.

    I will be posting the Microsoft example code along with my code using a button image (most likely the ugly button I posted as I have to have the button redone) along with an explanation of the steps and hopefully an explanation of those two parameters in the image create method. Again Victor I apologize if I am coming across short or sensitive about your remarks but please try to understand that there has been more going on here causing stress and sensitive nerves that I just am not in the mood to be lectured to or my impressive of being lectured to.

  3. #18
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Cannot see image using CTreeCtrl

    Quote Originally Posted by Jim Bassett
    Victor

    Again I appreciate your help but I been using CodeGuru for over 10 years and I have never had anyone tell me how I need to tag code examples
    It doesn't matter: 10 years or 10 days.
    We all should learn permanently!
    So, please check it out: Announcement: Before you post....
    And not only Code tags - there are many other very useful things.

    Now the second part of the image problem was the second and third parmeters in the image create method ( m_ImgList.Create(IDB_BITMAP1, 16, 10, RGB(255,255,255)); and their purpose is not clear in the documention nor their use/purpose and you also made no mention of them
    What is the problem with "the second and third parameters"?
    From MSDN:
    CImageList::Create
    ...
    BOOL Create( UINT nBitmapID, int cx, int nGrow, COLORREF crMask );
    ...
    Parameters

    cx
    Dimensions of each image, in pixels.

    nGrow

    Number of images by which the image list can grow when the system needs to resize the list to make room for new images. This parameter represents the number of new images the resized image list can contain.
    Well, if it is hard to understand - why not use another overloaded Create method:
    BOOL Create( int cx, int cy, UINT nFlags, int nInitial, int nGrow );
    as HanneSThEGreaT an I recommended you?

  4. #19
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    Exclamation Re: Cannot see image using CTreeCtrl

    Victor maybe I am just worn out, but I don't understand your 10 years or 10 days statement, why say that are you always in daddy mode or something? If you are so smart, always a good practitioner, and follower of rules, etc. and then write a book for the rest of us dummies or who don't have good practices like you. Whew....

    About the two parameters I read that but the second parameter is not needed and can be set to anything if you are not going to add any additional images. In that context it is just an optional parameter and the documentation could say something about that. Heck I can take the code that does now show my button or the example code that Microsoft sent me and change that nGrow (a real descriptive parameter name) and set it to -10 or to 1000 and it makes no difference, yet what few examples are there of the control and image use it suggest the value is required in all cases and serves a purpose it that context which it doesn’t.

    Victor you and I don't look at things the same especially in terms of being respectful. I posted because I was having problem, and I do appreciate your help but I do not appreciate you talking down to me and besides you did not have the complete solution only part of it and I had most of the code correct with or without the “_T” so get off your high horse and learn to write and instruct with respect.

  5. #20
    Join Date
    Jun 2007
    Posts
    2

    Re: Cannot see image using CTreeCtrl

    I may have a work around for your problem. Though it is certainly no fix, it might give the microsoft guys a clue to what's going on. It seems like they're stumped.

    I recently tried to add an image myself and ran into the same exact problem, but I also wanted to be able to highlight items based on context. Because of this I had to use custom draw for the item. Custom draw allows you to add anything you want to an item (or cell) right before or right after an item (or cell) is drawn or erased. Here's a link to how to get custom draw to work:

    http://www.codeproject.com/listctrl/lvcustomdraw.asp

    Long story short, after using custom draw the image appeared. If this still doesn't work, the tutorial gives you instructions on how to insert an image in any cell, which you can also try. It's not pretty, but I think it'll work

    -Travis

  6. #21
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Cannot see image using CTreeCtrl

    It is not clear what problem did you have with the list control, although using custom draw one could, of course, draw everything.

    Note also that OP had the problem with the tree control images, not with a list control!

  7. #22
    Join Date
    Jun 2007
    Posts
    2

    Re: Cannot see image using CTreeCtrl

    I wanted to be able to highlight some cells in yellow based on what was in them, so i had to use custom draw.

    Good point about the list view. The article is still applicable as tree and list controls treat custom draw identically, because tree views are just a specialization of list views. One caveat : when receiving the message parameter (NMHDR) you'll want to reinterpret_cast it to NMTVCUSTOMDRAW, not an NMLVCUSTOMDRAW (note the T and L).

    The two values are identical in data, so you actually could use NMLVCUSTOMDRAW, but I guess it would be more consistent.

    Hope that helps,

  8. #23
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    Exclamation Re: Cannot see image using CTreeCtrl

    Victor and anyone else who is on this thread go look at http://www.codeguru.com/forum/showthread.php?p=1592009 and notice the person who posted that thread also felt like Victor comes across angry. So it isn't just me that felt this way Victor so maybe you should take a look at how you write because it comes across like you are angry.

  9. #24
    Join Date
    Oct 2009
    Posts
    1

    Smile Re: Cannot see image using CTreeCtrl

    Quote Originally Posted by HanneSThEGreaT View Post
    Oh, sorry about that, let's attempt this step by step :
    I added the TreeCtl and the ImageList to my dialog
    I added a Bitmap Resource ( this is used for our ImageList's pictures )
    In the ClassWizard, I added a variable to the TreeCtl, named m_tree ( and it's a Control variable )

    In my Dialog class's construction ( the header file ) , I added these 2 lines :
    Code:
    CImageList m_imageList; //image list used by the tree
    CBitmap m_bitmap; //bitmap which loads  bitmap
    So my entire construction code looks like :
    Code:
    class CPictureTreesDlg : public CDialog
    {
    // Construction
    public:
    	CPictureTreesDlg(CWnd* pParent = NULL);	// standard constructor
    CImageList m_imageList; //image list used by the tree
    CBitmap m_bitmap; //bitmap which loads  bitmap
    // rest omitted
    Then, at the end of my OnInitDialog, just above return TRUE; I added this :
    Code:
    		// Create  ImageList
    	m_imageList.Create (16, 16, ILC_COLOR32 , 1,1);
    	m_bitmap.LoadBitmap(IDB_BITMAP1);
    
    	//Add the bitmap to the ImageList
    	m_imageList.Add(&m_bitmap, RGB(255,0,255));
    
    	//Manage your tree items......
    	m_tree.SetImageList (&m_imageList, TVSIL_NORMAL);
    	m_tree.InsertItem("Excel",0,0,TVI_ROOT);
    	m_tree.InsertItem("HTML",1,1,TVI_ROOT);
    	m_tree.InsertItem("C++",2,2,TVI_ROOT);
    	m_tree.InsertItem("Word",3,3,TVI_ROOT);
    	m_tree.InsertItem("Outlook",4,4,TVI_ROOT);
    It works, but if you need a sample, just let me know
    I hope this helps!


    Thank You Sir,
    It worked for me.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured