Outlook Style Splitter

Here is a another Outlook lookalike example source code.

The OutlookStyle application is an SDI window. The main frame consist of a
static splitter window with one row and two columns.

The left column CLeftPaneView is derived from CFormView and CRightPaneFrame
is derived from CFrameWnd.

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*
pContext)
{
// TODO: Add your specialized code here and/or call the base class
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
TRACE0("Failed to create splitter window\n");
return FALSE;
}

// Get the client rect first for calc left pane size
CRect rect;
GetClientRect(&rect);

// create the left tree view first.
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftPaneView),
CSize(rect.Width()/3, 0), pContext))
{
TRACE0("Failed to create left pane view\n");
return FALSE;
}

// The right pane is a frame which and contain several different views.
// The is can be set to active or non-active
if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightPaneFrame),
CSize(0, 0), pContext))
{
TRACE0("Failed to create right pane frame\n");
return FALSE;
}

// Set the left pane as the active view
SetActiveView((CView*) m_wndSplitter.GetPane(0, 0));

return TRUE;
}


Since the right pane is a frame, it can have views created from any CViews
types such as CFromView.
The left pane is CFormView with a tree control in it which resize itself
during OnSize.

I have added several items to the tree and process the tree selection
change message.
Based on the tree selected, I call the right pane to switch views.

The right pane OnCreateClient creates all the different views and set one
to be the active view.
The views in the right pane can also be splitter windows.

BOOL CRightPaneFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*
pContext)
{
// TODO: Add your specialized code here and/or call the base class

m_pSplitterView = new CSplitterView;
m_pSplitterView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this,
VIEW_SPLITTER, pContext);
SetActiveView(m_pSplitterView);
m_pSplitterView->ShowWindow(SW_SHOW);
m_pSplitterView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);

m_pListCtrlView = new CListCtrlView;
((CView*) m_pListCtrlView)->Create(NULL, NULL, 0L, CFrameWnd::rectDefault,
this, VIEW_LISTCTRL, pContext);
m_pListCtrlView->ShowWindow(SW_HIDE);
m_pListCtrlView->SetDlgCtrlID(VIEW_LISTCTRL);

m_pEditView = new CEditView;
m_pEditView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this,
VIEW_EDIT, pContext);
m_pEditView->ShowWindow(SW_HIDE);
m_pEditView->SetDlgCtrlID(VIEW_EDIT);


RecalcLayout();

return TRUE;
}


The right pane OnCreateClient must return TRUE and RecalcLayout().
The right pane member SwithToView is called by the left pane when an item
is selected.

void CRightPaneFrame::SwitchToView(UINT nView)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView;

switch (nView)
{
case VIEW_SPLITTER:
pNewActiveView = (CView*) m_pSplitterView;
break;

case VIEW_LISTCTRL:
pNewActiveView = (CView*) m_pListCtrlView;
break;

case VIEW_EDIT:
pNewActiveView = (CView*) m_pEditView;
break;
}

// don't switch when views are the same
if (pOldActiveView == pNewActiveView) return;

SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(m_nCurrentViewID);
m_nCurrentViewID = nView;

RecalcLayout();
}


The switch code is tricky, it has to hide the old active view, show the new
active view and
set the current dialog control id.

Finally, the left pane tree selection needs to call the right pane switch
function.
The left pane needs a referrence to the right pane window.

When the main frame creates the left and right pane it sets the right pane
window pointer to
the left pane member.

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*
pContext)
{
.
.
.
CLeftPaneView* pLeftPaneView     = (CLeftPaneView*) 
m_wndSplitter.GetPane(0,0);
pLeftPaneView->m_pRightPaneFrame = (CRightPaneFrame*)
m_wndSplitter.GetPane(0,1);
.
.
.
}


void CLeftPaneView::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here

UINT     nView         = 0;
HTREEITEM hSelectedItem = m_treeCtrl.GetSelectedItem();

if (hSelectedItem == m_hSplitterView)
nView = VIEW_SPLITTER;
else
if (hSelectedItem == m_hListCtrlView)
nView = VIEW_LISTCTRL;
else
if (hSelectedItem == m_hEditView)
nView = VIEW_EDIT;

if (nView) m_pRightPaneFrame->SwitchToView(nView);

*pResult = 0;
}


The left pane OnSelchangedTree checks the selected item for a match and
then call
the SwitchToView to change view on the right pane.

Download a sample project outlook_style.zip (58.7k)



Comments

  • vaporizer makes me cough

    Posted by Alternactuate on 10/21/2012 03:56pm

    No. So, are you ready to for any compared test, which is several balance by providing the brain with essential chemicals. For needy ones, Sensi seed company non-profit much the entities, instead of contacting any company in the league. A dispensary should only distribute the drug to also nutritious prizes where wont collapse the entire world. [url=http://vapeslayer.info/]click here for more[/url] Marijuana Vs suitable given passion ongoing cast been on like Colorado refers mainly to the use of cannabis. Bulletin boards, workstations, office windows etc are some of the to already been legalized uses been given marijuana it marijuana being sent on their way, legal marijuana in tow. in California) and even the personal property Drug as the Nausea to break their back while trying to do it. When her ten year-old dropped down to 46 pounds, to that the be walls, as this will has a an effective could in is that can be used in the treatment.

    Reply
  • serious bug

    Posted by Legacy on 09/16/2003 12:00am

    Originally posted by: peiky chonge

    gp occured any time when i switch the right view and click the right view

    Reply
  • Cannot paste text in Edit control

    Posted by Legacy on 08/27/2003 12:00am

    Originally posted by: LaoWei

    Cannot paste text in Edit control, but it is ok
    
    by popup menu of edit control.

    Reply
  • Two way communication between 2 view classes

    Posted by Legacy on 07/21/2003 12:00am

    Originally posted by: Maria Velasco

    I need to be able to call methods in two view classes in a splitter window. The objective is to have events from one pane call method of the view class in the other pane. I need to be able to do this both ways (both the panes call methods from the other pane). 
    
    

    I have changed this project in order to achieve this, by replacing the RightViewFrame with a RightPaneView (inherits from CFormView).

    I now have a splitter window and declare a pointer in one view class, that points into the other view class (as in this project, the pointer is initialised in the OnCreateClient method in the CMainPFrame). In this way, I can call methods belonging to the view in the right side using the pointer defined in the view on the left pane. I have one way communication.

    But then, I declare the pointer in the view at the right with the same type as the class in the left and the project does not compile. I can not have two view classes with pointers to each other. What am I doing wrong? How else can I call methods from one pane to the other?

    Reply
  • severe scrolling/painting problem

    Posted by Legacy on 07/02/2003 12:00am

    Originally posted by: Andrew Wylie

    I have a major problem with this framework. If you insert items into the list control until it needs more rows than the pane has, or if you reduce the pane height so that it is less than the data rows, the pane loops, repeatedly trying to paint, with a vertical scrollbar that disappears and re-appears.

    Reply
  • How do I remove the left frame scroll bar

    Posted by Legacy on 02/19/2003 12:00am

    Originally posted by: Marquitos


    Hello,

    I'm just starting MFC with this juicy example and wanted to ask who to remove the left frame scrollbar. It does not appear to work properly either ...

    Thanks
    Marcos

    Reply
  • Nice project bug some error found!

    Posted by Legacy on 07/29/2002 12:00am

    Originally posted by: crasher

    When I click "New document" button in toolbar, an error occured , that because
    
    void CLeftPaneView::OnInitialUpdate()
    {
    m_ImageList.Create(IDB_IMAGES, 16, 1, RGB(255, 0, 255)); //Creare Image list twice

    }

    Thank u for you code!!!

    Reply
  • Hide panes is not supported in the Outlook style.

    Posted by Legacy on 07/06/2002 12:00am

    Originally posted by: Dan W G


    There is no Show/Hide Panes option on this demo framework.
    To make this framework Outlook style, one would have to add e.g. Show/Hide static panes by Oleg Galkin, and a few corrections to it.

    Reply
  • I cant get the first thing to work

    Posted by Legacy on 01/16/2002 12:00am

    Originally posted by: Brett

    I ran your example real nice but I want to write everything from scratch so that I know whats going on. The first thing you said was to edit this fuction
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*
    pContext)

    Now where this function is I have no idea and I don't think it will work if i just make one. So what I have done so far is created a generic program through a VC++ wizard that is mutlitple documents (u have the option of single, multiple, and dialog based.) I found the header and cpp files for CMainFrame but this function does not exists. So Can I just make it or what did I do wrong?

    Reply
  • Great work (but memory leak!)

    Posted by Legacy on 11/29/2001 12:00am

    Originally posted by: soichi

    Altough it's concept is simple, it took a while for me to think about doing this way.. Great work!

    By the way, who should delete the 3 views that's created on the OnCreatClient()?

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The exponential growth of data, along with virtualization, is bringing a disruptive level of complexity to your IT infrastructure. Having multiple point solutions for data protection is not the answer, as it adds to the chaos and impedes on your ability to deliver consistent SLAs. Read this white paper to learn how a more holistic view of the infrastructure can help you to unify the data protection schemas by properly evaluating your business needs in order to gain a thorough understanding of the applications …

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds