• 10
• 12
• 12
• 14
• 15

# CSplitterWnd CreateStatic() fails

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I've never posted here, but I've found a lot of articles and forum threads that have helped me a lot in the past, so I figured this is probably the best place to look for help. I'm trying to make a level editor using MFC and some Render Engine. I got it all working nicely, I split my mainForm into 3 Panes, and I split the middle Pane into another 4. I created those panes with these lines of code
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
mMainSplitter.CreateStatic(this, 1, 3);
mMainSplitter.CreateView(0, 0, RUNTIME_CLASS(EditorBrowserPanel), CSize(width,height), pContext);
mViewSplitter.CreateStatic(&mMainSplitter, 2, 2, WS_CHILD | WS_VISIBLE, mMainSplitter.IdFromRowCol(0, 1));
mViewSplitter.CreateView(0, 0, RUNTIME_CLASS(CTimeEDView), CSize(width, height), pContext);
mViewSplitter.CreateView(0, 1, RUNTIME_CLASS(CTimeEDView), CSize(width, height), pContext);
mViewSplitter.CreateView(1, 0, RUNTIME_CLASS(CTimeEDView), CSize(width, height), pContext);
mViewSplitter.CreateView(1, 1, RUNTIME_CLASS(CTimeEDView), CSize(width, height), pContext);
}


I managed to get 3 orthographic views and 1 perspective view working perfectly, by supplying the HWND of the 4 Panes to the Render Engine. After that I decided to do it a little different. Instead of having CTimeEDView as a runtime class for the 4 viewports, I wanted to have another CFormView (EditorView), which would split it into a smaller menu (EditorViewMenu) and the old CTimeEDView. So here's the code I wrote that would be the new runtime class for the 4 windows, to split the form into panes.
BOOL EditorView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwstyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
if ( !mSplitter.CreateStatic(pParentWnd, 2, 1, dwstyle, nID))
{
MessageBox( "1.1 Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR );
return FALSE;
}

CRect cr;
GetClientRect(&cr);

{
MessageBox( "2.1 Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR );
return FALSE;
}

if ( !mSplitter.CreateView(1, 0, RUNTIME_CLASS(CTimeEDView), CSize(rect.right - rect.left, ((rect.bottom-rect.top) - EDITOR_VIEW_MENU)), pContext) )
{
MessageBox( "3.1 Error setting up splitter frames!", "Init Error!", MB_OK | MB_ICONERROR );
return FALSE;
}

return CFormView::Create(lpszClassName, lpszWindowName, dwstyle, rect, pParentWnd, nID, pContext);
}


The first problem I encountered, was finding the right function to put this in. Since CFormView doesn't have a message "OnCreateClient", I used Create() instead. I don't know if I did the right thing here, but at least it supplied me with the correct parameters. Next up was mSplitter.CreateStatic(pParentWnd, 2, 1, dwstyle, nID) I thought I should supply "this" as a parent for the Splitter, but it returned 0 when I tried that (it gave me the message box), so I used pParentWnd, which did seem to work. nID was also a complete mystery to me, so I don't know if I did the right thing there. I also made sure that the classes were dynamically created (whatever that may mean), so there are no errors there. Well it compiles correctly, but when I run it, I get this thrown at me
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: C:\Cplusplus\ogrenew\Samples\Common\bin\Debug\Time\TimeED.exe
File: f:\vs70builds\3077\vc\MFCATL\ship\atlmfc\include\afxwin2.inl
Line: 282

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
---------------------------
Abort   Retry   Ignore
---------------------------


and when I debug, it will point towards this line as the cause of it.
	if ( !mSplitter.CreateStatic(pParentWnd, 2, 1, dwstyle, nID))

On an (unimportant) sidenote, I wrote the CFormView derived classes like I wrote the ones that did work
	EditorMenuPanel();

virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
virtual void DoDataExchange(CDataExchange* pDX);

DECLARE_MESSAGE_MAP()

#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif


Can anybody help me with this? Thanks.