DefWindowProc() issue

淺唱寂寞╮ 提交于 2020-01-04 06:55:28

问题


VS2008, c++, mfc I have to handle messages from the child windows in the parent window. In fact i want to handle only ON_BN_CLICKED messages and then make some ather actions. As i understood i have to redefine WindowProc():

LRESULT CDLauncherDlg::WindowProc(UINT mes, WPARAM wp, LPARAM lp)
{
    HWND hWnd = this->m_hWnd;
    switch (mes){
        case WM_COMMAND:
            if((LOWORD(wp)==IDC_BUTTON4)&& (HIWORD(wp) == BN_CLICKED))
            {
                MessageBox("Button pressed.", "", 0);
            }
        break;
    }
    return DefWindowProc(mes, wp, lp);
}

Unfortunatelly, after pressing Cancel button DefWindowProc() does nothing and i can't close the application. What's the problem?


回答1:


The final answer was to replace

return DefWindowProc(mes, wp, lp);

with

return CDialog::WindowProc(mes, wp, lp); 



回答2:


Your code snippet doesn't indicate you're handling a WM_CLOSE message, or that you're explicitly calling DestroyWindow() when IDC_BUTTON4 is clicked. If this is a child window, and you want to terminate the application, you could call DestroyWindow() and then somewhere later PostQuitMessage().

If your snippet here is the windowproc for your parent window, and the handling of IDC_BUTTON4 is the parent window receiving the original message that you handled in the child and passed to the parent, simply call PostQuitMessage() where you've put the call to MessageBox().



来源:https://stackoverflow.com/questions/8204965/defwindowproc-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!