Question

I have one parent dialog , this dialog have menu , in this menu (Help->about).
when I click on the about selection, show about DialogBox.
I want if I click on Ok or close(X) button, close this dialog box only not the main dialog box.

This my attempts:

// ------------- Main dialog function
BOOL CALLBACK DlgFunc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp){
    switch(msg){
    case WM_COMMAND:
        switch(LOWORD(wp)){
        case IDM_HABOUT: // Here, I set when I click on help selection in the menu creates (about dialogbox)
            DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_AboutDlg), hwnd, AboutDlgFunc);
            break;
        }
        break;
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return false;
    }
    return true;
}


// ------------- About dialog function
BOOL CALLBACK AboutDlgFunc(HWND HabutWnd, UINT msg, WPARAM wp, LPARAM lp){
    switch(msg){
    case WM_COMMAND:
        if(LOWORD(wp) == IDOK)
            EndDialog(HabutWnd,0);
        break;
    case WM_CLOSE:
        EndDialog(HabutWnd,0);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return false;
    }
    return true;
}
Was it helpful?

Solution

Don't call PostQuitMessage in WM_DESTROY inside AboutDlgFunc. This essentially causes the entire program to quit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top