Click here to Skip to main content
15,919,434 members
Articles / Desktop Programming / MFC
Article

CSDITrueColorTabs

Rate me:
Please Sign up or sign in to vote.
1.50/5 (16 votes)
28 Jun 2003 93.7K   1.9K   30   10
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


Written By
Architect
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionDemo reqired Pin
Member 492937511-Dec-11 16:09
Member 492937511-Dec-11 16:09 
GeneralDEMO Required urgently Pin
fatima8228-Nov-03 19:29
fatima8228-Nov-03 19:29 
GeneralProblems & Demo (Urgent) Pin
Arsalan Minhas4-Nov-03 23:52
Arsalan Minhas4-Nov-03 23:52 
GeneralRe: Problems & Demo (Urgent) Pin
Lars_Munch19-Nov-03 23:31
Lars_Munch19-Nov-03 23:31 
GeneralRe: Problems & Demo (Urgent) Pin
Anonymous10-May-04 22:51
Anonymous10-May-04 22:51 
GeneralDoes this work in splitter windows Pin
andyandlaurie11-Oct-03 7:06
andyandlaurie11-Oct-03 7:06 
GeneralDemo needed Pin
Member 5267229-Jun-03 13:15
Member 5267229-Jun-03 13:15 
GeneralRe: Demo needed Pin
Florin Ochiana1-Jul-03 12:24
Florin Ochiana1-Jul-03 12:24 
Have you encountered problems implementing this?

-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.

GeneralRe: Demo needed Pin
fox-y15-Jul-03 7:37
fox-y15-Jul-03 7:37 
GeneralRe: Demo needed Pin
Florin Ochiana15-Jul-03 15:47
Florin Ochiana15-Jul-03 15:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.