Link to home
Start Free TrialLog in
Avatar of moshei
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_FORE))
            AfxMessageBox("Not O.K");
      if (!m_Back.LoadBitmap(IDB_BACK))
            AfxMessageBox("Not O.K");
      int l;
      if ( l = m_ImageList.Add(&m_Fore,WHITE) == -1 )
                  AfxMessageBox("Not O.K");      
      if ( l = m_ImageList.Add(&m_Back,NAVIG_BTN_CLR) == -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,&local) == -1 )
            AfxMessageBox("Not O.K");
      TC_ITEM local2;
      local2.mask = TCIF_IMAGE;        
      local2.iImage = 1;        
      if ( m_TabCtrl.InsertItem(2,&local2) == -1 )
                  AfxMessageBox("Not O.K");
      TC_ITEM local3;
      local3.mask = TCIF_IMAGE  ;        
      local3.iImage = 1;        
      if ( m_TabCtrl.InsertItem(3,&local3) == -1 )
            AfxMessageBox("Not O.K");
      m_TabCtrl.SetCurSel(0);
      return TRUE;
}
Avatar of shaig
shaig
Flag of Afghanistan image

This simple code works:

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 );
Avatar of moshei
moshei

ASKER

This code is not working within my program and the tab is opened
with the default look.
Avatar of moshei

ASKER

My CTabCtrl is an owner draw control
Avatar of moshei

ASKER

Adjusted points to 70
ASKER CERTIFIED SOLUTION
Avatar of shaig
shaig
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial