I'm trying to do a MFC wizard that allows the user to enter the number of rows and columns of a game platform and then go to the next screen where he or she can edit the tiles contained within the platform. However, there's an access violation occurring within the MFC's CWnd's WndProc durring the call to DoModal, I think.
Here's the code I think you will need to understand. Platform2 is just an empty dialog with a bitmap since it has not been implemented yet.
Code:
/////////////////////////////////////////////////////
///
/// Result of Map=>Platform=>Add
/////////////////////////////////////////////////////
void CMapEditorDoc::OnPackageAdd()
{
CPropertySheet dlg("Add Platform");
PlatformPage1 page1;
PlatformPage2 page2;
dlg.AddPage(&page1);
dlg.AddPage(&page2);
dlg.SetWizardMode();
dlg.DoModal();
}
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "afxwin.h"
/////////////////////////////////////////////////
/// PlatformPage1.h
///
/// PlatformPage1 dialog
///
/// Dialog containing two textboxes for the number of rows
/// and columns
/////////////////////////////////////////////////
class PlatformPage1 : public CPropertyPage
{
DECLARE_DYNAMIC(PlatformPage1)
public:
PlatformPage1();
virtual ~PlatformPage1();
// Dialog Data
enum { IDD = IDD_PLATFORM1 };
int getNumRow() const {
return m_row;
}
int getNumCol() const {
return m_col;
}
enum {
HORIZ = 0, VERT = 1
};
int getHV() const {
return m_hvradio;
}
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
private:
CEdit m_rowEdit;
CEdit m_colEdit;
int m_hvradio;
int m_row;
int m_col;
public:
virtual BOOL OnSetActive();
};
///////////////////////////////////////////////////////////////////////////////
// PlatformPage1.cpp : implementation file
//
#include "stdafx.h"
#include "MapEditor.h"
#include "PlatformPage1.h"
#include ".\platformpage1.h"
// PlatformPage1 dialog
IMPLEMENT_DYNAMIC(PlatformPage1, CPropertyPage)
PlatformPage1::PlatformPage1()
: CPropertyPage(PlatformPage1::IDD)
, m_hvradio(1)
, m_row(1)
, m_col(4)
{
}
PlatformPage1::~PlatformPage1()
{
}
void PlatformPage1::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, m_rowEdit);
DDX_Control(pDX, IDC_EDIT2, m_colEdit);
DDX_Text(pDX, IDC_EDIT1, m_row);
DDX_Text(pDX, IDC_EDIT2, m_col);
DDX_Radio(pDX, IDC_RADIO1, m_hvradio);
DDV_MinMaxInt(pDX, m_row, 1, 5);
DDV_MinMaxInt(pDX, m_col, 1, 8);
}
BEGIN_MESSAGE_MAP(PlatformPage1, CPropertyPage)
END_MESSAGE_MAP()
BOOL PlatformPage1::OnSetActive()
{
CPropertySheet* parent = (CPropertySheet*)GetParent();
//parent->SetWizardButtons(PSWIZB_NEXT | PSWIZB_DISABLEDFINISH);
return CPropertyPage::OnSetActive();
}
/////////////////////////////////////////////////////////////////////////////
// Platform2.h
////////////////////////
#pragma once
// PlatformPage2 dialog
class PlatformPage2 : public CPropertyPage
{
DECLARE_DYNAMIC(PlatformPage2)
public:
PlatformPage2();
virtual ~PlatformPage2();
// Dialog Data
enum { IDD = IDD_PLATFORM2 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
virtual BOOL OnSetActive();
};
///////////////////////////////////////////////////////////////////////////////
/// Platform2.cpp
/////////////////////////
// PlatformPage2.cpp : implementation file
//
#include "stdafx.h"
#include "MapEditor.h"
#include "PlatformPage2.h"
#include ".\platformpage2.h"
// PlatformPage2 dialog
IMPLEMENT_DYNAMIC(PlatformPage2, CPropertyPage)
PlatformPage2::PlatformPage2()
: CPropertyPage(PlatformPage2::IDD)
{
}
PlatformPage2::~PlatformPage2()
{
}
void PlatformPage2::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(PlatformPage2, CPropertyPage)
END_MESSAGE_MAP()
// PlatformPage2 message handlers
BOOL PlatformPage2::OnSetActive()
{
CPropertySheet* parent = (CPropertySheet*)GetParent();
parent->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK | PSWIZB_FINISH);
return CPropertyPage::OnSetActive();
}