2

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?

c4pQ
  • 884
  • 8
  • 28

2 Answers2

1

The final answer was to replace

return DefWindowProc(mes, wp, lp);

with

return CDialog::WindowProc(mes, wp, lp); 
c4pQ
  • 884
  • 8
  • 28
0

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().

Christopher
  • 764
  • 4
  • 6
  • Thank you for your help, but i finally just wrote next: return CDialog::WindowProc(mes, wp, lp); – c4pQ Nov 22 '11 at 10:10