?
Solved

Urgent CTabCtrl & CImageList Problem

Posted on 1998-06-12
5
Medium Priority
?
414 Views
Last Modified: 2013-11-20
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;
}
0
Comment
Question by:moshei
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:shaig
ID: 1317903
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 );
0
 

Author Comment

by:moshei
ID: 1317904
This code is not working within my program and the tab is opened
with the default look.
0
 

Author Comment

by:moshei
ID: 1317905
My CTabCtrl is an owner draw control
0
 

Author Comment

by:moshei
ID: 1317906
Adjusted points to 70
0
 
LVL 3

Accepted Solution

by:
shaig earned 140 total points
ID: 1317907
This code is taken out of a working program.
is your tab control created? ( does he have a valide HWND )
can you supply more details if not, so i can be moer helpful
( like, is there a spot in this code i've supplied that fails - does the code execute till it's last line or does it break on it's way? )
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question