Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / MFC
Article

Embedding CMFCOutlookBar in CSplitterWnd panes

Rate me:
Please Sign up or sign in to vote.
3.21/5 (7 votes)
16 Sep 2008CPOL1 min read 43.7K   21   11
Create a 2008 MFCOutlookBar in any pane of a SplitterWnd.

Image 1

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 /*lpcs*/,    
                       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); //Base class

    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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
Vikas Maan is a software developer for last 4 years working on windows platform with multiple programming languages mainly VC++, C#.net etc.

Comments and Discussions

 
GeneralMy vote of 4 Pin
shetkarabhijeet20-Nov-12 19:28
shetkarabhijeet20-Nov-12 19:28 
GeneralRe: My vote of 4 Pin
vikas maan20-Nov-12 19:42
vikas maan20-Nov-12 19:42 
GeneralRe: My vote of 4 Pin
shetkarabhijeet22-Nov-12 18:24
shetkarabhijeet22-Nov-12 18:24 
GeneralMy vote of 1 Pin
cute_friend707714-Jun-10 2:52
cute_friend707714-Jun-10 2:52 
GeneralHelp me! Thanks! Pin
qidaimengxing9-Mar-09 22:58
qidaimengxing9-Mar-09 22:58 
QuestionWhere can I obtain this source code? Pin
netivs23-Feb-09 2:14
netivs23-Feb-09 2:14 
AnswerRe: Where can I obtain this source code? Pin
vikas maan4-Mar-09 5:50
vikas maan4-Mar-09 5:50 
AnswerRe: Where can I obtain this source code? Pin
Barretto VN3-Nov-11 4:32
Barretto VN3-Nov-11 4:32 
GeneralRemove MFC Pin
jit_infy13-Oct-08 23:50
jit_infy13-Oct-08 23:50 
QuestionHow can you used these new controls in C# Pin
Patrick Blackman18-Sep-08 5:23
professionalPatrick Blackman18-Sep-08 5:23 
Do you have any idea how I could use these controls in C#. Are they in a special dll that I can reference in my project?Confused | :confused:
AnswerRe: How can you used these new controls in C# Pin
vikas maan19-Sep-08 0:05
vikas maan19-Sep-08 0:05 

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.