Click here to Skip to main content
Licence 
First Posted 28 Jun 2003
Views 78,501
Bookmarked 30 times

CSDITrueColorTabs

By | 28 Jun 2003 | Article
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

About the Author

Florin Ochiana

Architect

Romania Romania

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionDemo reqired PinmemberMember 492937516:09 11 Dec '11  
GeneralDEMO Required urgently Pinmemberfatima8219:29 28 Nov '03  
GeneralProblems & Demo (Urgent) PinmemberArsalan Minhas23:52 4 Nov '03  
GeneralRe: Problems & Demo (Urgent) PinmemberLars_Munch23:31 19 Nov '03  
GeneralRe: Problems & Demo (Urgent) PinsussAnonymous22:51 10 May '04  
GeneralDoes this work in splitter windows Pinmemberandyandlaurie7:06 11 Oct '03  
GeneralDemo needed Pinmemberhero3blade13:15 29 Jun '03  
GeneralRe: Demo needed PinmemberFlorin Ochiana12:24 1 Jul '03  
GeneralRe: Demo needed Pinmemberfox-y7:37 15 Jul '03  
GeneralRe: Demo needed PinmemberFlorin Ochiana15:47 15 Jul '03  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 29 Jun 2003
Article Copyright 2003 by Florin Ochiana
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid