How to capture the close event of a MessageBox


I have the doubt to know if the event Close of a MessageBox can be captured.

Clearly the application runs on windows



Now it's working, that is, it jumps a MessageBox on the screen but I would like to be able to call another function when the user closes it or gives OK .

asked by WhySoBizarreCode 16.04.2018 в 23:05

1 answer


According to the documentation , MessageBox returns a int that can have the following values:

  • IDABORT: The abort button has been pressed
  • IDCANCEL: The cancel button or the ESC key has been pressed
  • IDCONTINUE: The continue button has been pressed
  • IDIGNORE: The ignore button has been pressed
  • IDNO: The no button has been pressed
  • IDOK: The ok button has been pressed
  • IDRETRY: The Retry button has been pressed
  • IDTRYAGAIN: The button has been pressed to try again
  • IDYES: The yes button has been pressed

In any case, the call is blocking, that is, the thread does not leave the function until the modal window has been closed, so to execute something when the window closes it is enough to put the code just after the call to the function:

std::cerr << "Se acaba de cerrar la ventana modal";

If, on the other hand, you want to act according to the button pressed by the user:

int res = MessageBox(0,"Title","description",1);

switch( res )
  case IDCANCEL:
    /* ... El usuario presiona cancelar o ESC ... */

  case IDOK:
    /* ... El usuario presiona el boton OK ... */
answered by 17.04.2018 / 00:01