Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

rick_appleton

MFC trouble

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been following this tutorial to learn a few things about MFC in combination with OpenGL: here and I haven't been able to get it running. In the post discussing the article many others have had problems, but none have had the same problem I have. You can download my project from here and here is the code I added:
	if ( !m_mainSplitter.CreateStatic( this, 1, 2 ) )
	{
		MessageBox( "Error setting up splitter frames!", "Init Error!",
			MB_OK | MB_ICONERROR );
		return FALSE;
	}

	// Create the views for each pane in the main

	// splitter. Static splitters must have each

	// pane filled immediately after creation before

	// they are displayed.

	CRect cr;	// client rectangle -

				// used to calculate client sizes


	GetClientRect( &cr );

	// Create the information bar view with a

	// CInfoPannel class.

	if ( !m_mainSplitter.CreateView( 0, 1, RUNTIME_CLASS(CView),
		CSize( INFOBAR_SIZE, cr.Height() ), pContext ) )
	{
		MessageBox( "Error setting up splitter frames!", "Init Error!",
			MB_OK | MB_ICONERROR );
		return FALSE;
	}

	// Setup a pointer to the viewport splitter to be

	// used later by the information bar to change

	// viewports.

	//((CView*)(m_mainSplitter.GetPane( 0, 1 )))->m_viewports = &m_viewportSplitter;


	// Create a new splitter to be nested in the first

	// row, first column of the main splitter.


	// This splitter seperates the viewports into their

	// respective frames. Again we make it static.


	if ( !m_viewportSplitter.CreateStatic( &m_mainSplitter, 2, 2, WS_CHILD | WS_VISIBLE,
		m_mainSplitter.IdFromRowCol( 0, 0 ) ) )
	{
		MessageBox( "Error setting up splitter frames!", "Init Error!",
			MB_OK | MB_ICONERROR );
		return FALSE;
	}

	// Create the views for each pane in the viewport

	// splitter.


	// Top viewport

	if ( !m_viewportSplitter.CreateView( 0, 0, RUNTIME_CLASS(CView),
		CSize( ( cr.Width() - INFOBAR_SIZE ) / 2, cr.Height() / 2 ), pContext ) )
	{
		MessageBox( "Error setting up splitter frames!", "Init Error!",
			MB_OK | MB_ICONERROR );
		return FALSE;
	}

	// Front viewport

	if ( !m_viewportSplitter.CreateView( 0, 1, RUNTIME_CLASS(CView),
		CSize( ( cr.Width() - INFOBAR_SIZE ) / 2, cr.Height() / 2 ), pContext ) )
	{
		MessageBox( "Error setting up splitter frames!", "Init Error!",
			MB_OK | MB_ICONERROR );
		return FALSE;
	}

	// Side viewport

	if ( !m_viewportSplitter.CreateView( 1, 0, RUNTIME_CLASS(CView),
		CSize( ( cr.Width() - INFOBAR_SIZE ) / 2, cr.Height() / 2 ), pContext ) )
	{
		MessageBox( "Error setting up splitter frames!", "Init Error!",
			MB_OK | MB_ICONERROR );
		return FALSE;
	}

	// Perspective viewport

	if ( !m_viewportSplitter.CreateView( 1, 1, RUNTIME_CLASS(CView),
		CSize( ( cr.Width() - INFOBAR_SIZE ) / 2, cr.Height() / 2 ), pContext ) )
	{
		MessageBox( "Error setting up splitter frames!", "Init Error!",
			MB_OK | MB_ICONERROR );
		return FALSE;
	}
this is basically copy-pasted from the provided source code, and altered to work. At least I thought so. The program compiles fine, but stumples over the first CreateView. Could anyone help me out? [edited by - rick_appleton on August 18, 2003 11:18:22 AM]

Share this post


Link to post
Share on other sites
Advertisement
Well, looking through your code, there doesn't seem to be anything wrong (although I haven't been using MFC that long either). Anyway, here's the code from my level editor which sets up the views for the splitter. Try pasting this and see if it works:


// Create a pair of static window splitters...

m_wndSplitter1.CreateStatic(this, 1, 2);
m_wndSplitter1.CreateView(0, 1, RUNTIME_CLASS(CTexWnd), CSize(0, 160), pContext);
m_wndSplitter2.CreateStatic(&m_wndSplitter1, 2, 2, WS_CHILD | WS_VISIBLE, m_wndSplitter1.IdFromRowCol(0, 0));
m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(C2DWnd), CSize(128, 128), pContext);
m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(C2DWnd), CSize(128, 0), pContext);
m_wndSplitter2.CreateView(0, 1, RUNTIME_CLASS(C2DWnd), CSize(0, 128), pContext);
m_wndSplitter2.CreateView(1, 1, RUNTIME_CLASS(C3DWnd), CSize(0, 0), pContext);

// Get references to the new views...

m_wndRight = (C2DWnd *)m_wndSplitter2.GetPane(0, 0);
m_wndTop = (C2DWnd *)m_wndSplitter2.GetPane(0, 1);
m_wndFront = (C2DWnd *)m_wndSplitter2.GetPane(1, 0);
m_wnd3D = (C3DWnd *)m_wndSplitter2.GetPane(1, 1);
m_wndTex = (CTexWnd *)m_wndSplitter1.GetPane(0, 1);
This code creates two splitters: one with two panes and one with four panes. The four-pane one is nested inside the first pane of the two-pane splitter. The C2DWnd, C3DWnd and CTexWnd classes are simple MFC classes, derived from CWnd. They handle 2D views, 3D views and texture views respectively. My main window is a CFrameWnd, and the splitters are created in CMainFrame::OnCreateContext(), like they should be. Anyway hope this helps...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on August 19, 2003 7:29:32 AM]

Share this post


Link to post
Share on other sites
Well, I''ve found out what the trouble was. Apparently MFC doesn''t like you using the standard CView class in the splitter windows. If you create a derived view (basic classwizard, add nothing by yourself), and use that to create the views, it does work. Odd, but there it is.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!