Problem with MFC Wizard

This is a discussion on Problem with MFC Wizard within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to do a MFC wizard that allows the user to enter the number of rows and columns of ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    470

    Problem with MFC Wizard

    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();
    }
    Last edited by okinrus; 04-10-2004 at 05:57 AM.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    I think I must have overreacted a little bit. Microsoft's documentation for DoModal says
    "The first time a property page is created from its corresponding dialog resource, it may cause a first-chance exception. This is a result of the property page changing the style of the dialog resource to the required style prior to creating the page. Because resources are generally read-only, this causes an exception. The exception is handled by the system, and a copy of the modified resource is made automatically by the system. The first-chance exception can thus be ignored."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating and Empty MFC project in Visual Studio?
    By Swerve in forum Windows Programming
    Replies: 7
    Last Post: 11-01-2008, 05:43 PM
  2. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 08:11 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. MFC Assertion Failure
    By maxthecat in forum Windows Programming
    Replies: 5
    Last Post: 08-01-2002, 10:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21