![]() |
Desktop Development »
Document / View »
General
Intermediate
License: A Public Domain dedication
Automatic Tab Bar for MDI FrameworksBy Paul SelormeyA dockable bar containing a tabbed list of open windows |
VC6, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

CDocumentList, which lists all open documents. This is really
where life begins... CDocumentList class can
be very useful for many applications, take a good look.
_APS_NEXT_RESOURCE_VALUE by 2, i.e. 1 more than
the last incremental id.
_APS_NEXT_CONTROL_VALUE by 8.
_APS_NEXT_COMMAND_VALUE by 9. The
project should now compile without any problem, and you can now delete the
tabview.h file. CMDIClient m_MDIClient;
void GetControlBarsEx(CArray<CControlBar*, CControlBar*>& arrBars);
void CMainFrame::GetControlBarsEx(CArray<CControlBar*, CControlBar*>& arrBars) { if (::IsWindow(m_wndToolBar.m_hWnd)) arrBars.Add(&m_wndToolBar); if (::IsWindow(m_wndStatusBar)) arrBars.Add(&m_wndStatusBar); //...more here }
VERIFY(m_MDIClient.SubclassMDIClient(this));
The SubclassMDIClient() is prototyped as BOOL SubclassMDIClient(CMDIFrameWnd* pMDIFrameWnd,
CViewManager* pViewManager, UINT uID = ID_VIEW_VIEWTAB);
ON_COMMAND_EX(ID_THE_NEWVALUE, OnBarCheck)
ON_UPDATE_COMMAND_UI(ID_THE_NEWVALUE, OnUpdateControlBarMenu)
CWindowManager, use the ClassWizard to override the
OnCmdMsg() method of the main frame and modify it to be similar
to the ff: // This function routes commands to window manager, then to rest of system. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { // Without this, the window manager menu commands will be disabled, // this is because without routing the command to the window manager, // MFC thinks there is no handler for it. if (m_MDIClient.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); }
| Menu Item ID | MENU ITEM STRING |
| ID_VIEW_VIEWTAB | Op&en File Tabs |
| ID_VIEW_FULLSCREEN | F&ull Screen |
| ID_WINDOW_NEXT | Ne&xt Window |
| ID_WINDOW_PREVIOUS | Pre&vious Window |
| ID_WINDOW_CLOSE_ALL | C&lose All |
| ID_WINDOW_SAVE_ALL | &Save All |
WM_CLOSE message for your main
frame, or modify the existing one adding the following single line, calling
the SaveMainFrameState() method... void CMainFrame::OnClose()
{
......
m_MDIClient.SaveMainFrameState();
......
CMDIFrameWnd::OnClose();
}
InitInstance() of application class with the
RestoreMainFrameState() as BOOL CDemoApp::InitInstance()
{
.............................
// The main window has been initialized, so show and update it.
// pMainFrame->ShowWindow(m_nCmdShow); ///// <--- we do not need this one!
pMainFrame->m_MDIClient.RestoreMainFrameState(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
For the current implementation...
The OnCreate() function of
the CViewManager, which created both the tab and itself (the tab
bar), simply creates a place holder icon to fill an image list, which is then
attached to the tab.
int CViewManager::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CControlBar::OnCreate(lpCreateStruct) == -1) return -1; m_ViewTabImages.Create(16, 16, ILC_MASK, 5, 5); m_ViewTabCtrl.Create(WS_CHILD | WS_VISIBLE | WS_EX_NOPARENTNOTIFY | TCS_TOOLTIPS | TCS_SINGLELINE | TCS_FOCUSNEVER | TCS_FORCELABELLEFT, CRect(0, 0, 0, 0), this, ID_VIEWTAB); m_ViewTabCtrl.SetImageList(&m_ViewTabImages); // Build the image list here HICON hIcon = AfxGetApp()->LoadStandardIcon(IDI_APPLICATION); // HICON hIcon = AfxGetApp()->LoadIcon(IDR_DEMOTYPE); m_ViewTabImages.Add(hIcon); // Enable tooltips for all controls EnableToolTips(TRUE); return 0; }
LoadStandardIcon() is used to load system icon in there. You
may wish to replace this with the commented code, IDR_DEMOTYPE is
your application specific resource type. HICON hIcon = AfxGetApp()->LoadIcon(IDR_DEMOTYPE);
In the AddView() function of the same class, the tab image
index is set to 0 (zero) the only image in the image list. Finally, in the
DrawItem() function of the tab, CWindowTabCtrl, the
dummy icon is replaced by the small icon attached to the frame of your child
window, parent of the view. void CWindowTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { .... CView* pView = reinterpret_cast<CView*>(tci.lParam); CDocument* pDoc = pView->GetDocument(); // Draw image if (m_bDisplayIcons) { CImageList* pImageList = GetImageList(); CMDIChildWnd* pViewFrame = static_cast<CMDIChildWnd*>(pView->GetParent()); HICON hIcon = reinterpret_cast<HICON>(GetClassLong(pViewFrame->m_hWnd, GCL_HICONSM)); pImageList->Replace(nTabIndex, hIcon); .... } .... }Initially, I considered getting the icon from the Windows shell, based on the registered file extension
SHGetFileInfo() API. However, it does
not look nice for the view frame icon to be different from the tab view icon. By
the current implementation, all is needed is a good citizenship like the VC++
itself. Let your application child window system icons reflect the file type and
there will be no need to write extra codes.
| Use this code in any project, there is no restriction!
Write whatever you like or do not like about this code in the comment
section, I will take note of all. Happy coding... Paul Selormey, Japan. |
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 3 Jan 2003 Editor: Chris Maunder |
Copyright 2000 by Paul Selormey Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |