How to use CSplitterWnd class

11 03 2010

 

 

If you want to create an SDI application with three views, that means we have to split the main window into three different parts and each window have to handle separately. How can we do it?

 

 

MFC provides CSplitterWnd class to establish the functionality of a splitter window, which is a window that contains multiple panes. 

In our case we need three different views, so first of all we have to derive three new classes from CFormView to our SDI application and attach three windows to these classes. Then overrides parent frame’s OnCreateClient function and within that function call the CreateStatic member function of CSplitterWnd with number of  rows and columns specifications. Then we can put the views in the splitter panes using CreateView function.

 

 

include "MyView1.h"
#include "MyView2.h"
#include "MyView3.h"

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
   return CreateSplitters(pContext);
}
bool CMainFrame::CreateSplitters( CCreateContext* pContext )
{
   const bool cbCreated
      = TRUE == m_TimelineSplitter.CreateStatic(
      this,
      1,
      3 );
   int nxScreen, nyScreen;
   nxScreen = GetSystemMetrics(SM_CXFULLSCREEN);
   nyScreen = GetSystemMetrics(SM_CYFULLSCREEN);
   if( cbCreated )
   {
      // Put the views in the splitter panes
      m_TimelineSplitter.CreateView(
         0,
         0,
         RUNTIME_CLASS( MyView1 ),
         CSize(nxScreen/3.5,nyScreen/3.6),
         pContext );
      m_TimelineSplitter.CreateView(
         0,
         1,
         RUNTIME_CLASS( MyView1 ),
         CSize( nxScreen/2.8,nyScreen/2.7 ),
         pContext );
      m_TimelineSplitter.CreateView(
         0,
         2,
         RUNTIME_CLASS( MyView1 ),
         CSize(nxScreen,nyScreen/1.4 ),
         pContext );
   }
   return cbCreated;
}

 

 

Use CSplitterWnd::Create to create a dynamic splitter window and use CSplitterWnd::CreateStatic to create a static splitter window.

Advertisements

Actions

Information

One response

15 03 2011
VAMSHI

PLEASE TELL ME HOW TO CREATE BEAUTIFUL COLORFUL MENUS IN VC++6.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: