-4

I want to show multiple windows at once.

for(int i=0; i < 5; i++)
  {
    Sleep(10);
    MessageBox(NULL, "Some information", NULL, MB_OK);
  }

It's showing them one after another, but I want to show them all at one time

(Sorry for my English)

Thanks!

dawidsk12345
  • 67
  • 1
  • 8
  • The reason for this is `MessageBox` is a modal dialog, – drescherjm Aug 02 '19 at 20:15
  • Related if not a duplicate: https://stackoverflow.com/questions/3556089/is-there-any-way-to-have-async-messagebox – drescherjm Aug 02 '19 at 20:16
  • `MessageBox(NULL, "Some information", NULL, MB_OK | MB_TASKMODAL);` – Tony J Aug 02 '19 at 20:18
  • 2
    You can create multiple threads (not recommended), are you creating a joke/virus app? – Michael Chourdakis Aug 02 '19 at 20:20
  • Joke app for sister xD – dawidsk12345 Aug 02 '19 at 20:23
  • This may help with the threads: https://stackoverflow.com/questions/8617450/how-do-you-create-a-message-box-thread – drescherjm Aug 02 '19 at 20:37
  • Multi threads are working with `MessageBoxA(NULL, "Some text", NULL, MB_ICONERROR);` but not with `MessageBoxA(NULL, "Some text", NULL, MB_ICONERROR | MB_TOPMOST);` .Is it possible to fix that? – dawidsk12345 Aug 03 '19 at 10:31
  • Straight from the [documentation](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox): *"Displays a modal dialog box that contains a system icon, a set of buttons, and a brief application-specific message, such as status or error information. **The message box returns an integer value that indicates which button the user clicked.**"* – IInspectable Aug 03 '19 at 14:46

1 Answers1

4

MessageBox is a modal dialog, the function does not return until the dialog has been closed. Multiple MessageBoxs can only be created if you have multiple threads in your process. MessageBox is a special version of DialogBox.

You can use CreateDialog to create modeless dialogs but you should not show many dialogs to the user at the same time. I would recommend that you create a single dialog with a ListView if you need to display many "events" to the user at the same time.

Anders
  • 97,548
  • 12
  • 110
  • 164