EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of VC++/WIN32/MFC Questions #Next question

CSplitterWnd

CFrameWnd can have only one window frame. CSplitterWnd class can be used in CFrameWnd to create splitter views in main frame window.

CSplitterWnd::Create

To create a dynamic splitter window, call the Create member function.

virtual BOOL Create(
    CWnd* pParentWnd,  
    int nMaxRows,  
    int nMaxCols,  
    SIZE sizeMin,  
    CCreateContext* pContext,  
    DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | SPLS_DYNAMIC_SPLIT,  
    UINT nID = AFX_IDW_PANE_FIRST);

CSplitterWnd::CreateStatic

To create a static splitter window, call the CreateStatic member function.

virtual BOOL CreateStatic(
    CWnd* pParentWnd,  
    int nRows,  
    int nCols,  
    DWORD dwStyle = WS_CHILD | WS_VISIBLE,  
    UINT nID = AFX_IDW_PANE_FIRST);

CSplitterWnd::CreateView

Creates the panes for a static splitter window.
virtual BOOL CreateView(
    int row,  
    int col,  
    CRuntimeClass* pViewClass,  
    SIZE sizeInit,  
    CCreateContext* pContext);

CSplitterWnd::SetRowInfo

Call to set the specified row information.
void SetRowInfo(
    int row,  
    int cyIdeal,  
    int cyMin);

CSplitterWnd::SetColumnInfo

Call to set the specified column information.
void SetColumnInfo(
    int col,  
    int cxIdeal,  
    int cxMin);

CSplitterWnd::RecalcLayout

Call to redisplay the splitter window after adjusting row or column size.
virtual void RecalcLayout();

CSplitterWnd demo

This source code only shows CSplitterWnd part of CMainFrame source file. Rest of the code can be taken from our SDI doc/view demo code.

class CMainFrame : public CFrameWnd
{
protected:
  CMainFrame();
  DECLARE_DYNCREATE(CMainFrame)
public:
  virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
10    void OnSize(UINT nType, int cx, int cy) ;
11    virtual ~CMainFrame();
12 
13  protected:  /* control bar embedded members */
14    CStatusBar  m_wndStatusBar;
15    CToolBar    m_wndToolBar;
16    CSplitterWnd m_mainSplitter;
17 
18  protected:
19    BOOL m_bInitSplitter;
20    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
21 
22    DECLARE_MESSAGE_MAP()
23  };
24 
25  /* CMainFrame message handlers */
26  BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
27    ON_WM_CREATE()
28    ON_WM_SIZE()
29  END_MESSAGE_MAP()
30 
31  CMainFrame::CMainFrame()
32  {
33    m_bInitSplitter = false;
34  }
35  CMainFrame::~CMainFrame()
36  {
37  }
38 
39  int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
40  {
41    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
42      return -1;
43    
44    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
45      | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
46      !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
47    {
48      TRACE0("Failed to create toolbar ");
49      return -1;
50    }
51    if (!m_wndStatusBar.Create(this) ||
52      !m_wndStatusBar.SetIndicators(indicators,
53        sizeof(indicators)/sizeof(UINT)))
54    {
55      TRACE0("Failed to create status bar ");
56      return -1;
57    }
58    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
59    EnableDocking(CBRS_ALIGN_ANY);
60    DockControlBar(&m_wndToolBar);
61    return 0;
62  }
63  BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
64  {
65    if( !CFrameWnd::PreCreateWindow(cs) )
66      return FALSE;
67    return TRUE;
68  }
69  BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
70  {
71    /* calculate client size */
72    CRect cr;
73    GetWindowRect( &cr );
74    
75    /* Create the main splitter with 1 row and 2 columns */
76    if ( !m_mainSplitter.CreateStatic( this, 1, 2 ) )
77    {
78      MessageBox( "Error setting up m_mainSplitter", "ERROR", MB_OK | MB_ICONERROR );
79      return FALSE;
80    }
81 
82    /* The views for each pane must be created */
83    if ( !m_mainSplitter.CreateView( 0, 0, RUNTIME_CLASS(CSplitterDemoView),
84      CSize(cr.Width()/2, cr.Height()), pContext ) )
85    {
86      MessageBox( "Error setting up splitter view", "ERROR", MB_OK | MB_ICONERROR );
87      return FALSE;
88    }
89 
90    if ( !m_mainSplitter.CreateView( 0, 1, RUNTIME_CLASS(CSplitterDemoView),
91      CSize(cr.Width()/2, cr.Height()), pContext ) )
92    {
93      MessageBox( "Error setting up splitter view", "ERROR", MB_OK | MB_ICONERROR );
94      return FALSE;
95    }
96 
97    /* change flag to show splitter created */
98    m_bInitSplitter = true;
99 
100    /*return TRUE instead of the parent method since that would not show our window */
101    return TRUE;
102  }
103  void CMainFrame::OnSize(UINT nType, int cx, int cy) 
104  {
105    CFrameWnd::OnSize(nType, cx, cy);
106    
107    CRect cr;
108    GetWindowRect(&cr);
109 
110    if (m_bInitSplitter && nType != SIZE_MINIMIZED )
111    {
112      m_mainSplitter.SetRowInfo( 0, cy, 0 );
113      m_mainSplitter.SetColumnInfo( 0, cr.Width() / 2, 50);
114      m_mainSplitter.SetColumnInfo( 1, cr.Width() / 2, 50);
115      
116      m_mainSplitter.RecalcLayout();
117    }  
118  }

CSplitterWnd output

CSplitterWnd demo

You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

#Programming Windows, Fifth Edition (Developer Reference)
#Programming Applications for Microsoft Windows (Microsoft Programming Series)
#Programming Windows with MFC, Second Edition
#Visual C++ Programming
#Programming Microsoft Visual C++, Fifth Edition

* #1 webmaster Sun 27 Apr/2014 05:12:17(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.