moshei
asked on
Urgent CTabCtrl & CImageList Problem
i am tring to change the tab cntrol to work with CImageList
and it is not working . This is my OnInitDialog() .
What is the problem with it ?? ( IDB_BACK,IDB_FORE are two
bitmaps )
BOOL CMfcDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
if (!m_ImageList.Create( 37,20,FALSE,0,2) == true )
AfxMessageBox("Not O.K");
if (!m_Fore.LoadBitmap(IDB_FO RE))
AfxMessageBox("Not O.K");
if (!m_Back.LoadBitmap(IDB_BA CK))
AfxMessageBox("Not O.K");
int l;
if ( l = m_ImageList.Add(&m_Fore,WH ITE) == -1 )
AfxMessageBox("Not O.K");
if ( l = m_ImageList.Add(&m_Back,NA VIG_BTN_CL R) == -1 )
AfxMessageBox("Not O.K");
l = m_ImageList.GetImageCount( );
m_TabCtrl.SetImageList(&m_ ImageList) ;
IMAGEINFO pImageInfo;
if (m_ImageList.GetImageInfo( 0,&pImageInfo ) == 0)
AfxMessageBox("Not O.K");
TC_ITEM local;
local.mask = TCIF_IMAGE;
local.iImage = 0;
if (m_TabCtrl.InsertItem(1,&l ocal) == -1 )
AfxMessageBox("Not O.K");
TC_ITEM local2;
local2.mask = TCIF_IMAGE;
local2.iImage = 1;
if ( m_TabCtrl.InsertItem(2,&lo cal2) == -1 )
AfxMessageBox("Not O.K");
TC_ITEM local3;
local3.mask = TCIF_IMAGE ;
local3.iImage = 1;
if ( m_TabCtrl.InsertItem(3,&lo cal3) == -1 )
AfxMessageBox("Not O.K");
m_TabCtrl.SetCurSel(0);
return TRUE;
}
and it is not working . This is my OnInitDialog() .
What is the problem with it ?? ( IDB_BACK,IDB_FORE are two
bitmaps )
BOOL CMfcDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
if (!m_ImageList.Create( 37,20,FALSE,0,2) == true )
AfxMessageBox("Not O.K");
if (!m_Fore.LoadBitmap(IDB_FO
AfxMessageBox("Not O.K");
if (!m_Back.LoadBitmap(IDB_BA
AfxMessageBox("Not O.K");
int l;
if ( l = m_ImageList.Add(&m_Fore,WH
AfxMessageBox("Not O.K");
if ( l = m_ImageList.Add(&m_Back,NA
AfxMessageBox("Not O.K");
l = m_ImageList.GetImageCount(
m_TabCtrl.SetImageList(&m_
IMAGEINFO pImageInfo;
if (m_ImageList.GetImageInfo(
AfxMessageBox("Not O.K");
TC_ITEM local;
local.mask = TCIF_IMAGE;
local.iImage = 0;
if (m_TabCtrl.InsertItem(1,&l
AfxMessageBox("Not O.K");
TC_ITEM local2;
local2.mask = TCIF_IMAGE;
local2.iImage = 1;
if ( m_TabCtrl.InsertItem(2,&lo
AfxMessageBox("Not O.K");
TC_ITEM local3;
local3.mask = TCIF_IMAGE ;
local3.iImage = 1;
if ( m_TabCtrl.InsertItem(3,&lo
AfxMessageBox("Not O.K");
m_TabCtrl.SetCurSel(0);
return TRUE;
}
ASKER
This code is not working within my program and the tab is opened
with the default look.
with the default look.
ASKER
My CTabCtrl is an owner draw control
ASKER
Adjusted points to 70
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CTabCtrl *pTab = GetTabControl(); // not relevant for you
if( pTab == NULL ) return bResult;
m_pImageList = new CImageList;
if( m_pImageList == NULL ) return bResult;
if( !m_pImageList->Create( 16, 16, TRUE, 2, 2 ) ) return bResult;
INT nImageIndex = m_pImageList->Add( pApp->LoadIcon( IDI_CASSETTE )
);
if( nImageIndex == -1 ) return bResult;
pTab->SetImageList( m_pImageList );
TC_ITEM tabCtrlItem;
tabCtrlItem.mask = TCIF_IMAGE;
tabCtrlItem.iImage = nImageIndex;
pTab->SetItem( 0, &tabCtrlItem );