how to create 2 splitters in a window (using MFC)
-
Hello, I am a newbie to MFC programming in VC++. I can't seem to create more than one splitter in my MFC application.:omg: I need to create a window similar to windows explorer but on the right I want 2 panes not 1. So instead of the right pane I want 2 horizontal panes (one on top of the other). Ultimately what I want to do is: 1)display a directory tree in the left pane 2)display files and/or directories (of selected directory from tree) in the right-top pane. 3)display contents of selected file (from above pane) in right-bottom pane. So I can get the first vertical splitter - Visual Studio actually makes it for me cause in the application creation wizard, under visual interface features, for toolbars i selected "standard docking" with "browser style". But I can't seem to add another one. I would appreciate if anyone could tell me how to code for this second splitter and where to code this (what class and function). TraileR ParK LifE 4Ever >:{
-
Hello, I am a newbie to MFC programming in VC++. I can't seem to create more than one splitter in my MFC application.:omg: I need to create a window similar to windows explorer but on the right I want 2 panes not 1. So instead of the right pane I want 2 horizontal panes (one on top of the other). Ultimately what I want to do is: 1)display a directory tree in the left pane 2)display files and/or directories (of selected directory from tree) in the right-top pane. 3)display contents of selected file (from above pane) in right-bottom pane. So I can get the first vertical splitter - Visual Studio actually makes it for me cause in the application creation wizard, under visual interface features, for toolbars i selected "standard docking" with "browser style". But I can't seem to add another one. I would appreciate if anyone could tell me how to code for this second splitter and where to code this (what class and function). TraileR ParK LifE 4Ever >:{
Add another CSplitterWnd variable to your CMainFrame class, e.g. m_RightSplitter. Replace CMainFrame::OnCreateClient with code similar to:
// create splitter window
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}if( ! m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(100, 100), pContext) )
return(FALSE);
m_RightSplitter.CreateStatic( &m_wndSplitter, 2, 1, WS_CHILD | WS_VISIBLE, m_wndSplitter.IdFromRowCol(0,1) );
if( ! m_RightSplitter.CreateView(0, 0, RUNTIME_CLASS(CTopRightView), CSize(100, 100), pContext) ||
! m_RightSplitter.CreateView(1, 0, RUNTIME_CLASS(CBottomRightView), CSize(100, 100), pContext) )
{
return(FALSE);
} -
Add another CSplitterWnd variable to your CMainFrame class, e.g. m_RightSplitter. Replace CMainFrame::OnCreateClient with code similar to:
// create splitter window
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}if( ! m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(100, 100), pContext) )
return(FALSE);
m_RightSplitter.CreateStatic( &m_wndSplitter, 2, 1, WS_CHILD | WS_VISIBLE, m_wndSplitter.IdFromRowCol(0,1) );
if( ! m_RightSplitter.CreateView(0, 0, RUNTIME_CLASS(CTopRightView), CSize(100, 100), pContext) ||
! m_RightSplitter.CreateView(1, 0, RUNTIME_CLASS(CBottomRightView), CSize(100, 100), pContext) )
{
return(FALSE);
}Hi Bill, Thanks for the reply. When I try your code I get these errors : error: C2039: 'classCTopRightView': is not a member of 'CTopRightView' error: C2065: 'classCTopRightView': undeclared identifier <> I added CTopRightView and CBottomRightView as 'Generic C++ classes' (did not code them though - dont know how:sigh: ). I have no idea why its adding the word 'class' in front of the 2 class names.:confused: TraileR ParK LifE 4Ever >:{
-
Hi Bill, Thanks for the reply. When I try your code I get these errors : error: C2039: 'classCTopRightView': is not a member of 'CTopRightView' error: C2065: 'classCTopRightView': undeclared identifier <> I added CTopRightView and CBottomRightView as 'Generic C++ classes' (did not code them though - dont know how:sigh: ). I have no idea why its adding the word 'class' in front of the 2 class names.:confused: TraileR ParK LifE 4Ever >:{
They have to CWnd derived classes - most likely derived from CView. In addition they also have to have DECLARE_DYNCREATE in the class header file and IMPLEMENT_DYNCREATE in the class source file. If you look at the default CView classes created for the project you will see these lines. Use "MFC Class" to create the classes instead and derive them from CView. It will then put these lines in automatically for you. The "classCTopRightView" is a special member variable that MFC puts in for runtime class typing and dynamic creation. It uses the name "classCYOURCLASSNAMEHERE" as the member name. The above macros put these in for you.
-
They have to CWnd derived classes - most likely derived from CView. In addition they also have to have DECLARE_DYNCREATE in the class header file and IMPLEMENT_DYNCREATE in the class source file. If you look at the default CView classes created for the project you will see these lines. Use "MFC Class" to create the classes instead and derive them from CView. It will then put these lines in automatically for you. The "classCTopRightView" is a special member variable that MFC puts in for runtime class typing and dynamic creation. It uses the name "classCYOURCLASSNAMEHERE" as the member name. The above macros put these in for you.