【问题标题】:mfc Assertion failure when trying to create a property sheet尝试创建属性表时 mfc 断言失败
【发布时间】:2013-10-08 21:22:45
【问题描述】:

每当我尝试创建属性表时,我都会收到“调试断言失败”,这是我的第一个属性表,我从“MFC Programming from the ground up”复制它。

这是属性表类:

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);
    }
};

我在主窗口中声明了属性表变量:

class CMainWin : public CFrameWnd
{
    CSamplePropSheet m_PropSheet;

public:
    CMainWin();

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

    DECLARE_MESSAGE_MAP()
};

然后我在这里打电话:

afx_msg void CMainWin::OnActivate()
{

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

}

当错误弹出时,它指向这一段代码:

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);
 }

错过了什么吗?程序菜单选项的其余部分都可以使用,除了用于显示属性表的激活按钮。

【问题讨论】:

    标签: c++ mfc assertions


    【解决方案1】:

    您似乎对属性页 page1page2page3 错误地使用了 Construct 方法。您可能假设在此语句中Construct("PropDialog1", 0);“PropDialog1”是页面的标题。但是,它是资源模板的名称。请阅读here 了解如何使用资源模板。

    我建议你使用不同的 Construct 方法重载:

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

    使用此重载,您可以将与属性页关联的对话框资源的 ID 指定为第一个参数,并将页面标题的字符串资源 ID 指定为第二个参数。例如:

    page1.Construct(IDD_PROP_PAGE1, IDS_PAGE1_CAPTION);
    

    【讨论】:

    • 我不知道为什么,但由于某种原因,资源模板的名称在我将名称从“PropDialog1”缩短为“PropD1”之前也不起作用,现在程序可以工作了.感谢您的帮助!
    猜你喜欢
    • 2015-06-30
    • 2015-09-24
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多