CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: CTabCtrl Icons

  1. #1
    Join Date
    May 1999
    Posts
    11

    CTabCtrl Icons

    Hi! I've started working with the CTabCtrl and have gotten the functionality going alright, but I can't get any icons to appear. I create my CImageList from a resource bitmap, and I do the set properly on the tab control. When I run the program, then tabs are shaped the correct size from the bitmaps, but nothing appears. I only want to show an icon so I have the correct ITCIF_IMAGE mask set when I add the tabs. If I do the text, I can see the text, but still no icons. I've also tried setting Owner Draw Fixed, but that causes an exception in the MFC42 debug DLL.

    I found some example code on here that's almost the same, but I'm doing the same thing and it's not working. The thing I'm doing differently is using the resource editor to insert the tab control and I think the sample is creating it from a class.

    Anyone have any ideas?

    Thanks!


  2. #2
    Join Date
    Apr 1999
    Location
    WA, USA
    Posts
    15

    Re: CTabCtrl Icons

    These are the things to be done:

    1) Create the image list.

    2) Associate the image list with tab control:
    CImageList * SetImageList( CImageList * pImageList );

    3) In the tc_item structure, set appropriate value to iImage ie 0, 1 etc:
    iImage;

    I think that should be it.


  3. #3
    Join Date
    May 1999
    Posts
    11

    Re: CTabCtrl Icons

    Unfortuantely, I've done this. Here's my code in my OnInitDialog() function:

    ----------------
    CImageList test;
    test.Create( IDB_FEATURE_MENU, 70, 0,RGB(255,255,255));
    m_tab.SetImageList(&test);

    // Create a CImageList and associate this somehow to the tab control
    // Then specify the image index for each item
    TC_ITEM TabCtrlItem;
    TabCtrlItem.mask = TCIF_IMAGE;
    TabCtrlItem.pszText = "Quality";
    TabCtrlItem.iImage = 0;
    m_tab.InsertItem( 0, &TabCtrlItem );
    TabCtrlItem.iImage = 1;
    TabCtrlItem.pszText = "Finish";
    m_tab.InsertItem( 1, &TabCtrlItem );
    TabCtrlItem.iImage = 2;
    TabCtrlItem.pszText = "Paper";
    m_tab.InsertItem( 2, &TabCtrlItem );
    TabCtrlItem.iImage = 3;
    TabCtrlItem.pszText = "NiceStuff";
    m_tab.InsertItem( 3, &TabCtrlItem );
    ----------------

    void CMopier:oDataExchange(CDataExchange* pDX)
    {
    CDialog:oDataExchange(pDX);
    //{{AFX_DATA_MAP(CMopier)
    DDX_Control(pDX, IDC_TAB_FEATURES, m_tab);
    //}}AFX_DATA_MAP
    }



  4. #4
    Join Date
    May 1999
    Posts
    11

    Re: CTabCtrl Icons

    Ok, I guess I"m a begginner, but I figured out my problem. INstead of my previous init code I did a:

    CImageList * test = new CIMageList;
    test->Create(etc...)
    m_tab.SetImageList(test)

    INstead of:
    CimageList test;
    test.Create(etc);
    m_tab.SetIMageList(&test);


    So this is me not quite knowing how to use objects and pointers, but the code works now!
    Can someone give me a few pointers? I know enough about this stuff to be dangerous and to
    try it out (which is how I stumbled over it to get my code to work) but I don't quite
    understand why.


  5. #5
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    100

    Re: CTabCtrl Icons

    Seems like U hav declared "CimageList test;" locally
    so when U exit OnInitDialog, "test" is gone with ur
    Images. But pointers won't bite U if U are careful enough.
    And if my assumption is right, don't forget to
    deallocate "test" variable or ur imagelist when U exit
    ur dialog since U used "new" to create an imagelist.

    Good thing it worked BUT CHECK!!

    Walter


  6. #6
    Join Date
    May 1999
    Posts
    11

    Re: CTabCtrl Icons

    Yah, I have a clearer grasp of this stuff now. In my destructor on my class, I make sure to clean up
    the imagelist then delete the pointer, so no memory leak!


    Thanks for your help!


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