Click to See Complete Forum and Search --> : CTabCtrl Icons


Fooo
April 12th, 1999, 12:51 PM
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!

Mallik Bulusu
April 12th, 1999, 01:10 PM
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.

Fooo
April 12th, 1999, 03:19 PM
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::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMopier)
DDX_Control(pDX, IDC_TAB_FEATURES, m_tab);
//}}AFX_DATA_MAP
}

Fooo
April 12th, 1999, 03:25 PM
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.

Walter I An
April 12th, 1999, 03:48 PM
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

Fooo
April 12th, 1999, 03:55 PM
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!