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).
class CMainFrame : public CMDIFrameWnd
{
[...]
CSDITrueColorTabs m_wndSDITabs;
virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
[...]
};
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) {
[...]
m_wndTabs.Create(this,MT_TOP | MT_IMAGES);
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;
}
#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!
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.