Windows MessageBox ignoring WM_CLOSE

前端 未结 2 1990
别跟我提以往
别跟我提以往 2021-01-21 08:53

We\'ve got a legacy C Windows application which pops up a modal window via the MessageBox call when a fatal connection error occurs. Our network engineers may be running many of

2条回答
  •  轮回少年
    2021-01-21 09:28

    The modal dialogue 's message loop should catch WM_QUIT and in response call EndDialog() and pass on the WM_QUIT message to the application's main window using PostMessage().


    Update:

    The approach as proposed above would work, if a WM_QUIT would be sent to the modal dialogue ... - but at least on my current win7 machine this isn't the case.

    Moreover it is the case that the main window receives a WM_SYSCOMMAND with wParam set to SC_CLOSE and somehow the default message handler does ignore it (which might due to the modal dialogue box's styles...? I did not investigated this further.).

    However, adding the following branch to the main window's message loop's switch should do the work of ending the application under the conditions describe by the OP:

      ...
    
      case WM_SYSCOMMAND:
        if (SC_CLOSE == wParam)
        {
          PostQuitMessage();
        }
    
        return DefWindowProc(...);
       
      ...
    

提交回复
热议问题