Introduction
This article helps to add a CMFCOutlookbar
in CSplitterWnd
panes. The above image shows an Office 2007 type UI that is available with Visual Studio 2008 and the MFC feature pack. Refer this link for more details: Visual C++ 2008 Feature Pack: MFC Enhancements.
Using the code
By default, the CMFCOutlookBar
in the Office 2007 UI generated code is embedded in a CFrameWnd
derived class. Here, we will discuss about adding a CMFCOutlookBar
in CSplitterWnd
/CSplitterWndEx
panes.
BOOL COffice2007Frame::OnCreateClient(LPCREATESTRUCT ,
CCreateContext* pContext)
{
BOOL bRet=true;
bRet=bRet&m_wndSplitter.CreateStatic(this,2,2);
CRect rectClient;
this->GetClientRect(&rectClient);
bRet=bRet&m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CMFCOutlookBar),
CSize(rectClient.Width()/4,rectClient.Height()/2),pContext);
bRet=bRet&m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(COffice2007View),
CSize(rectClient.Width()*3/4,rectClient.Height()/2),pContext);
bRet=bRet&m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(COffice2007View),
CSize(rectClient.Width()/4,rectClient.Height()/2),pContext);
bRet=bRet&m_wndSplitter.CreateView(1,1,RUNTIME_CLASS(COffice2007View),
CSize(rectClient.Width()*3/4,rectClient.Height()/2),pContext);
return bRet;
}
This above code divides the splitter window in four unequal panes. During the creation of the view in the first pane, a CMFCOutlookBar
runtime pointer is given, so it will create an OutlookBar in the first pane.
CMFCOutlookBar* pPane_0_0=(CMFCOutlookBar*)m_wndSplitter.GetPane(0,0);
pPane_0_0->GetParent()->ModifyStyle(WS_CHILDWINDOW,WS_CHILDWINDOW|
WS_CLIPCHILDREN,SWP_DRAWFRAME);
In the above code, we take the pointer of the OutlookBar using the GetPane
function and modify the properties of the splitter parent pane to add the WS_CLIPCHILDREN
property. If we don't add this property, then on focus change, the splitter window pane will over-paint the OutlookBar.
By changing this property, it creates a problem of debug assertion fail in the Debug compile mode. To solve this problem, derive the class CSplitterWndEx
and override the function OnInvertTracker()
.
void CDSplitterWndEx::OnInvertTracker(const CRect& rect )
{
this->GetPane(0,0)->GetParent()->ModifyStyle(WS_CLIPCHILDREN,
0,SWP_DRAWFRAME);
this->GetPane(0,1)->GetParent()->ModifyStyle(WS_CLIPCHILDREN,
0,SWP_DRAWFRAME);
this->GetPane(1,0)->GetParent()->ModifyStyle(WS_CLIPCHILDREN,
0,SWP_DRAWFRAME);
this->GetPane(1,1)->GetParent()->ModifyStyle(WS_CLIPCHILDREN,
0,SWP_DRAWFRAME);
CSplitterWndEx::OnInvertTracker(rect);
this->GetPane(0,0)->GetParent()->ModifyStyle(0,
WS_CLIPCHILDREN,SWP_DRAWFRAME);
this->GetPane(0,1)->GetParent()->ModifyStyle(0,
WS_CLIPCHILDREN,SWP_DRAWFRAME);
this->GetPane(1,0)->GetParent()->ModifyStyle(0,
WS_CLIPCHILDREN,SWP_DRAWFRAME);
this->GetPane(1,1)->GetParent()->ModifyStyle(0,
WS_CLIPCHILDREN,SWP_DRAWFRAME);
}
The above code removes the WS_CLIPCHILDREN
property of each pane before calling OnInverTracker
to escape from a debug assertion fail, and then again adds the property back to each pane.
Points of Interest
This code is particularly useful for those who want to modify the MFC Outlook 2008 in their own way. This just demonstrates how to add a CMFCOutlookBar
in a SplitterWnd
pane in place of the default main frame window.
Vikas Maan is a software developer for last 4 years working on windows platform with multiple programming languages mainly VC++, C#.net etc.