Solved

Urgent CTabCtrl & CImageList Problem

Posted on 1998-06-12
5
376 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 70 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 51
Strange date stored 22 148
child constructor and parent constructor, overriding and overloading 6 88
x-bar in Google Sheets 2 69
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 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