Domanda

I get a "Debug Assertion failed" whenever I try to create a property sheet, this it my first one and I'm copying it from "MFC Programming from the ground up".

Here is the Property sheet class:

class CSamplePropSheet : public CPropertySheet
{
    CPropDialog1 page1; //first page
    CPropDialog2 page2; //second page
    CPropDialog3 page3; //third page

public:
    CSamplePropSheet() : CPropertySheet(){
        Construct("Sample Property Sheet", this);

        page1.Construct("PropDialog1", 0);
        page2.Construct("PropDialog2", 0);
        page3.Construct("PropDialog3", 0);
        AddPage(&page1);
        AddPage(&page2);
        AddPage(&page3);
    }
};

I have the Property Sheet variable declared in my main window here:

class CMainWin : public CFrameWnd
{
    CSamplePropSheet m_PropSheet;

public:
    CMainWin();

    afx_msg void OnActivate();
    afx_msg void OnExit();
    afx_msg void OnHelp();

    DECLARE_MESSAGE_MAP()
};

Then I make the call here:

afx_msg void CMainWin::OnActivate()
{

    m_PropSheet.DoModal(); //activate modal property sheet

}

When the error pops up, it points to this section of code:

int AFXAPI AfxMessageBox(UINT nIDPrompt, UINT nType, UINT nIDHelp)
{
    CString string;
    if (!string.LoadString(nIDPrompt))
    {
        TRACE(traceAppMsg, 0, "Error: failed to load message box prompt string 0x%04x.\n",
                nIDPrompt);
         ASSERT(FALSE);
     }
    if (nIDHelp == (UINT)-1)
        nIDHelp = nIDPrompt;
     return AfxMessageBox(string, nType, nIDHelp);
 }

Did miss something? The rest of the program menu options work, except for the Activate button to bring up the property sheet.

È stato utile?

Soluzione

It looks like you are using the Construct method for the property pages page1, page2 and page3 incorrectly. You probably assumed that in this statement Construct("PropDialog1", 0); "PropDialog1" is a caption of the page. However, it is a name of a resource template. Please read here on how to use resource templates.

I recommend you use a different Construct method overload:

void Construct( 
   UINT nIDTemplate, 
   UINT nIDCaption = 0  
); 

With this overload, you could specify the ID of the dialog resource associated with the property page as a first parameter and the String Resource ID of the caption of the page as a second parameter. E.g.:

page1.Construct(IDD_PROP_PAGE1, IDS_PAGE1_CAPTION);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top