Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CSDITrueColorTabs

0.00/5 (No votes)
28 Jun 2003 1  
A tab control with true color icons for an SDI application with multiple views.

Sample Image - CSDITrueColorTabs.jpg

Introduction

I have an SDI (Single Document Interface) application with several views. I had to do the switching between the views with a tab control but I didn�t find anywhere an example for this. I found Christian Rodemeyer�s CMDITabs and it took me half an hour to modify it into this class. I also liked Dany Cantin�s CTrueColorToolBar and from that class I used the method that does the true color bitmaps (SetTrueColorTabs). So there you have it: you can have several views and switch between them without using CpropertySheet or something else..

How to use

It�s very easy to use. You don�t have to change anything in your application architecture. You have to add SDITrueColorTabs.h and SDITrueColorTabs.cpp to your project. In your CmainFrame class add a new member m_wndSDITabs of class CSDITrueColorTabs (don�t forget to include SDITrueColorTabs.h).

// MainFrm.h

class CMainFrame : public CMDIFrameWnd
{
  [...]
  CSDITrueColorTabs m_wndSDITabs;
  
  virtual void OnUpdateFrameTitle(BOOL bAddToTitle); 
  [...]  
};
// MainFrm.cpp

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) {
  [...]
 m_wndTabs.Create(this,MT_TOP | MT_IMAGES);
 //m_wndTabs.SetImageList(&m_ToolTipIcons1);

 m_wndTabs.ViewsList.AddTail(m_pView1);
 m_wndTabs.ViewsList.AddTail(m_pView2);
 m_wndTabs.TextLabels.AddTail("Contacte");
 m_wndTabs.TextLabels.AddTail("Informatii");
 m_wndTabs.LoadTrueColorTabs(26,IDB_TABS_ICONS);
 return 0;
}
void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
  CFrameWnd::OnUpdateFrameTitle(bAddToTitle);
  m_wndSDITabs.Update(); 
}

m_pView1 and m_pView2 are pointers to your views.

The method SwitchView(viewNo) used to switch between the views is declared in my app.cpp and it looks like this:

CView* CtestApp::SwitchView(int viewNo)
{
          CView* pActiveView =
      ((CFrameWnd*) m_pMainWnd)->GetActiveView();
 
   CView* pNewView= NULL;
 
   if ((viewNo == 1 && pActiveView == m_pView1) || 
            (viewNo == 2 && pActiveView == m_pView2)) { 
       return pNewView;
   } else {
       switch (viewNo) {
           case 1:
               pNewView = m_pView1;
               break;
           case 2:
               pNewView = m_pView2;
               break;
       }
          
       // Exchange view window IDs so RecalcLayout() works.

       #ifndef _WIN32
           UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID);
           ::SetWindowWord(pActiveView->m_hWnd, GWW_ID, 
                  ::GetWindowWord(pNewView->m_hWnd, GWW_ID));
           ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp);
       #else
             UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
             ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, 
                 ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
             ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);
       #endif
 
       pActiveView->ShowWindow(SW_HIDE);
       pNewView->ShowWindow(SW_SHOW);
       ((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView);
       ((CFrameWnd*) m_pMainWnd)->RecalcLayout();
       pNewView->Invalidate();
       return pActiveView;
   }
}

For more information read CTrueColorToolBar and CMDITabs.

Have fun!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here