ATL DoModal()提出了一个断言

时间:2016-01-23 19:01:09

标签: c++ mfc atl

我目前正在尝试在我的应用程序中创建一个模态对话框,如下所示:

RedditRefresherLoginDialog loginDialog;
loginDialog.DoModal();

但是,只要我的代码到达DoModal(),我总会得到一个断言:

Debug assertion failed:
atlwin.h
Line: 3191
Expression: 0

我的Dialog类看起来像这样:

class RedditRefresherLoginDialog : public CDialogImpl<RedditRefresherLoginDialog>, public CWinDataExchange<RedditRefresherLoginDialog>
{
public:

    RedditRefresherLoginDialog();
    ~RedditRefresherLoginDialog();

    enum { IDD = IDD_REDDITREFRESHERLOGINDIALOG };

    BEGIN_MSG_MAP_EX(RedditRefresherLoginDialog)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInit)

        COMMAND_ID_HANDLER_EX(IDC_EXIT, OnExitButtonClick)
    END_MSG_MAP()

    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnInit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

private:

    void OnExitButtonClick(UINT uCode, int nCtrlID, HWND hwndCtrl);
};

断言是在atlwin.h,~CWindowImplRoot()解构函数中引起的。

    if(m_hWnd != NULL)  // should be cleared in WindowProc
    {
        ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Object deleted before window was destroyed\n"));
        ATLASSERT(FALSE);
    }

由于在CWindowImpl中遇到了断言,我试图从public CWindowImpl<RedditRefresherLoginDialog>添加继承并删除CDialogImpl,但是,DoModal不再起作用了。

有谁知道如何解决这个问题?

0 个答案:

没有答案