在自定义控件内创建子按钮窗口后崩溃

时间:2013-11-03 16:35:42

标签: c++ winapi mfc windows-messages

我有一个MFC应用程序,它显示一个包含自定义控件的简单对话框,自定义创建动态控件窗口。在创建自定义控件的第一个子节点之后,应用程序在堆栈溢出后崩溃

这是崩溃后的调用堆栈

    Amn80Lib1.dll!TPXBitButton::GetThisMessageMap() Line 1627   C++
    Amn80Lib1.dll!TPXBitButton::GetMessageMap() Line 1627   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2181    C++
    mfc100d.dll!CWnd::ReflectChildNotify(unsigned int uMsg, unsigned int wParam, long lParam, long * pResult) Line 3408 C++
>   mfc100d.dll!CWnd::OnChildNotify(unsigned int uMsg, unsigned int wParam, long lParam, long * pResult) Line 3387  C++
    mfc100d.dll!CButton::OnChildNotify(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 91  C++
    mfc100d.dll!CWnd::SendChildNotifyLastMsg(long * pResult) Line 3327  C++
    mfc100d.dll!CWnd::ReflectLastMsg(HWND__ * hWndChild, long * pResult) Line 3365  C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3463   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]    
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    user32.dll!75d1c4e7()   Unknown
    user32.dll!75d1c5e7()   Unknown
    user32.dll!75d1c590()   Unknown
    user32.dll!75d11b31()   Unknown
    user32.dll!75d32bee()   Unknown
    mfc100d.dll!CWnd::DefWindowProcA(unsigned int nMsg, unsigned int wParam, long lParam) Line 1089 C++
    mfc100d.dll!CWnd::Default() Line 291    C++
    mfc100d.dll!CWnd::OnParentNotify(unsigned int message, long lParam) Line 3468   C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2435    C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2087  C++
    Amn80Lib1.dll!TControl::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 29  C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 257    C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 420 C++
    The maximum number of stack frames supported by Visual Studio has been exceeded.    

始终发送的消息是528,这是0x210 = WM_PARENTNOTIFY wParam = 77594625,lParam = 3409408

我不知道是什么原因,以及如何阻止它,我搜索了孩子,如果他们中的任何一个向父母发送任何消息,但是没有消息,对话框没有显示,但它是窗口句柄已创建,自定义控件也有一个句柄,它的第一个孩子有一个句柄,然后我们陷入崩溃,其他孩子没有机会被创建。我跟踪了执行情况,并在调用对话框中自定义控件的子进程的create方法后发生了崩溃。 自定义控件是一个数据库导航控件,其中包含用于输入记录编号的下一个,上一个,新编辑的按钮,此自定义控件继承自从CWnd继承的TControl。其中的按钮继承自继承自CButton的TButton。

更新


问题如下:

当我注册自定义控件窗口类时,我将windowproc设置为MFC windowProc,当MFC proc没有找到任何方法来吃消息时,它调用了窗口的默认proc,这是MFC windowPoc导致的打开递归,我通过将窗口proc设置为默认值来修复它,如下面的

WNDCLASS wndClass;
//fill the window class data
wndClass.lpfnWndProc = ::DefWindowProc;//AfxWndProc;//this fixed it

解决了我的问题

1 个答案:

答案 0 :(得分:0)

我更新了答案以包含该问题的解决方案,但是为了回应@Michael Walz我添加了这个答案的解决方案


当我注册自定义控件窗口类时,我将windowproc设置为MFC windowProc,当MFC proc没有找到任何方法来吃消息时,它调用了窗口的默认proc,这是MFC windowPoc导致的打开递归,我通过将窗口proc设置为默认值来修复它,如下面的

WNDCLASS wndClass;
//fill the window class data
wndClass.lpfnWndProc = ::DefWindowProc;//AfxWndProc;//this fixed it
that fixed my problem