SDL offers a simple message box API, which is useful for simple alerts, such as informing the user when something fatal happens at startup without the need to build a UI for it (or informing the user before your UI is ready).
These message boxes are native system dialogs where possible.
There is both a customizable function (MessageBox.Show()) that offers lots of options for what to display and reports on what choice the user made, and also a much-simplified version (ShowSimpleMessageBox()), merely takes a text message and title, and waits until the user presses a single "OK" UI button. Often, this is all that is necessary.
| void SDL::MessageBox::Show |
( |
int * | buttonid | ) |
const |
|
inline |
Create a modal message box.
If your needs aren't complex, it might be easier to use ShowSimpleMessageBox.
This function should be called on the thread that created the parent window, or on the main thread if the messagebox has no parent. It will block execution of that thread until the user clicks a button or closes the messagebox.
This function may be called at any time, even before Init(). This makes it useful for reporting errors like a failure to create a renderer or OpenGL context.
On X11, SDL rolls its own dialog box with X11 primitives instead of a formal toolkit like GTK+ or Qt.
Note that if Init() would fail because there isn't any available video target, this function is likely to fail for the same reasons. If this is a concern, check the return value from this function and fall back to writing to stderr if you can.
- Parameters
-
| buttonid | the pointer to which user id of hit button should be copied. |
- Exceptions
-
- Thread safety:
- This function should only be called on the main thread.
- Since
- This function is available since SDL 3.2.0.
- See also
- ShowSimpleMessageBox
| void SDL::ShowMessageBox |
( |
const MessageBoxRaw & | messageboxdata, |
|
|
int * | buttonid ) |
|
inline |
Create a modal message box.
If your needs aren't complex, it might be easier to use ShowSimpleMessageBox.
This function should be called on the thread that created the parent window, or on the main thread if the messagebox has no parent. It will block execution of that thread until the user clicks a button or closes the messagebox.
This function may be called at any time, even before Init(). This makes it useful for reporting errors like a failure to create a renderer or OpenGL context.
On X11, SDL rolls its own dialog box with X11 primitives instead of a formal toolkit like GTK+ or Qt.
Note that if Init() would fail because there isn't any available video target, this function is likely to fail for the same reasons. If this is a concern, check the return value from this function and fall back to writing to stderr if you can.
- Parameters
-
| messageboxdata | the MessageBox structure with title, text and other options. |
| buttonid | the pointer to which user id of hit button should be copied. |
- Exceptions
-
- Thread safety:
- This function should only be called on the main thread.
- Since
- This function is available since SDL 3.2.0.
- See also
- ShowSimpleMessageBox
Display a simple modal message box.
If your needs aren't complex, this function is preferred over MessageBox.Show.
flags may be any of the following:
This function should be called on the thread that created the parent window, or on the main thread if the messagebox has no parent. It will block execution of that thread until the user clicks a button or closes the messagebox.
This function may be called at any time, even before Init(). This makes it useful for reporting errors like a failure to create a renderer or OpenGL context.
On X11, SDL rolls its own dialog box with X11 primitives instead of a formal toolkit like GTK+ or Qt.
Note that if Init() would fail because there isn't any available video target, this function is likely to fail for the same reasons. If this is a concern, check the return value from this function and fall back to writing to stderr if you can.
- Parameters
-
| flags | an MessageBoxFlags value. |
| title | UTF-8 title text. |
| message | UTF-8 message text. |
| window | the parent window, or nullptr for no parent. |
- Exceptions
-
- Thread safety:
- This function should only be called on the main thread.
- Since
- This function is available since SDL 3.2.0.
- See also
- MessageBox.Show