mfc >> CSplitterWnd::For_Dummies()

by Looking » Sun, 23 Nov 2003 23:38:40 GMT


I lifted the following sample code from the text ractical Visual C++ which showed how to scratch build a simple static splitter on a Single
Document Interface. It executes flawlessly:

// *Start of Example

Step 1. Create an SDI Project
Project Name: SSplit
Base Class: CView

Step 2. Add a Class
Classname: CArtView
Base Class: CView

Step 3. Within Class 'CMainFrame' create a variable
Name: m_wndSplitter
Type: CSplitterWnd
Access: protected

Step 4. Add Message Override
Class Name: CMainFrame
Object ID: CMainFrame
Message: OnCreateClient

Step 5. Add the following to MainFrm.cpp
#include "SSplitView.h"
#include "ArtView.h"

Step 6. Add the following to SSplitView.h
// placed above, class CSSplitView : public CView
class CSSplitDoc;


Step 7. Edit OnCreateClient as follows:

{
if (!m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;

if (
!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSSplitView), CSize(100,
100), pContext)
||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CArtView), CSize(100, 100),
pContext)
)
{
m_wndSplitter.DestroyWindow();
return FALSE;
}

return TRUE;
}

// *Conclusion of Example

Following the above example, I created another routine SDI application. Only
this time, rather than following the above procedure, at step 5 on the
AppWizard, I chose Windows Explorer style project (rather than MFC
Standard).

When I viewed the executed programs in both situations above, the results
look identical (except for some toolbar items). If you look at
OnCreateClient, it is exactly the same in both cases. Yet somewhere within
both programs lies a more fundamental difference. For the life of me, I
cannot figure out where that difference is.

To explain why I am baffled, I am able to freely alter the book's example
code to create a horizontal static splitter instead of a vertical as
follows:

// *Start of Excerpt

if (!m_wndSplitter.CreateStatic(this, 2, 1)) // Changed from ...(this,
1, 2)...
return FALSE;

if (
!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSSplitView), CSize(100,
100), pContext)
||
!m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CArtView), CSize(100, 100),
pContext) // Changed from ...CreateView(0, 1, RUNTIME...

// * Conclusion of Excerpt


But when I attempt the same thing with the AppWizard generated code, I get
run time errors. I am assuming there must be some way to turn an AppWizard
generated Explorer style project from a vertical split into a horizontal
split. But I have no idea how.

Eventually I would like to move on to creating 'T' splits as well as working
with dynamic splitters, but I feel it is important to understand the above
before moving a head to bigger projects.


Similar Threads

1. CSplitterWnd crashes in release build after 2005 upgrade

Hi,

I have run into a problem that has me stopped dead!

I have an existing (and working!) VS 6 application which I have recently 
upgraded to VS 2005.  The application works without problems when run built 
for debug, but crashes below the CreateView() method of CSplitterWnd when 
built for release.  By turning on the debug switch with the "release" build 
(but keeping the release libraries), I was able to get a traceback which 
indicates that the access violation occurred in ntdll.dll.  The call stack 
looks like:

ntdll.dll!7c9012b4()
...
kernel32.dll!7c80e2c5()
kernel32.dll!7c80b53c()
rms.exe!CDllIsolationWrapperBase::GetModuleHandleA()   line198
rms.exe!CComCtlWrapper::GetProcAddress_InitCommonControlsEx()  line 241
rms.exe!AfxEndDeferRegisterClass() line 4497
rms.exe!CFormView::Create()  line 90
rms.exe!CSplitterWnd::CreateView()  line291
rms.exe!CMainFrame::OnCreateClient()  line 296
...

The RuntimeClass being instantiated in the CreateView() call is apparently 
valid (its data looks good in the debugger).  The crash happens right at 
startup during the CMainFrame::OnCreateClient() call, so  the app really 
hasn't had much opportunity to corrupt memory yet - it has only executed 
"boiler-plate" code so far  (besides - it works correctly in debug mode with 
or without the debugging heap turned on).  The application uses the 
multi-threaded, static-linked version of MFC.

The problem only occurs when built in VS 2005.  No problems in VS 6!

Any suggestions are welcome!

Thanks,

  --- leon gordon 


2. CSplitterWnd, more information, please I need your help for my examen, thanks in advance - Microsoft Visual C++/VC++