Solved

Urgent CTabCtrl & CImageList Problem

Posted on 1998-06-12
5
370 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
Comment Utility
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
Comment Utility
This code is not working within my program and the tab is opened
with the default look.
0
 

Author Comment

by:moshei
Comment Utility
My CTabCtrl is an owner draw control
0
 

Author Comment

by:moshei
Comment Utility
Adjusted points to 70
0
 
LVL 3

Accepted Solution

by:
shaig earned 70 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now