SDL2: SDL_ShowMessageBox does not behave as expected


#1

Hello everyone,

I’m trying to use the SDL_ShowMessageBox function but it does not behave as described in the documentation.
I’m using SDL2 and programming on W10pro.

Hereafter is a simple code allowing to highlight my concern.

int main(int argc, char argv[])
{
SDL_Window
myWindow = NULL;
SDL_Init(SDL_INIT_VIDEO);
myWindow = SDL_CreateWindow(“Message box test”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 600, 400, SDL_WINDOW_RESIZABLE);
const SDL_MessageBoxButtonData buttons[] = {
{ 0, 0, “button 0” },
{ 0, 1, “button 1” },
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 2, “button 2” },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 3, “button 3” },
};
const SDL_MessageBoxColorScheme colorScheme = {
{
{ 255, 0, 0 },
{ 0, 255, 0 },
{ 255, 255, 0 },
{ 0, 0, 255 },
{ 255, 0, 255 }
}
};
const SDL_MessageBoxData messageboxdata = {
SDL_MESSAGEBOX_WARNING,
myWindow,
“Attention”,
“Hello”,
SDL_arraysize(buttons),
buttons,
&colorScheme
};
int buttonid;
SDL_ShowMessageBox(&messageboxdata, &buttonid);
SDL_Log(“buttonid: %d”,buttonid);
SDL_DestroyWindow(myWindow);
SDL_Quit();
return EXIT_SUCCESS;}

The first problem I see is that the color scheme does not seem to be applied. The message box remains with the system default color.

The second problem is that it looks like the function does not care about the MessageBoxButtonData flags like the SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT flag for example. It looks like the button defined at the second element of the SDL_MessageBoxButtonData structure is always considered as the return default button.
Here after is a screen capture of what is displayed on my system. It clearly show that the user defined color scheme is not applied and the the default button is button 1 which is also confirmed by SDL_Log when I hit the return key.
button
Button1_1

Is there something wrong in my code preventing the function to behave as documented?

Thanks.


#2

Can confirm that I could not get colored message boxes to work on Windows either. They do work on Linux for me though.


#3

Hello sebshady,

Following your answer, i also tried to compile the code on Linux and indeed, on Linux, it runs as expected. Not only the color is respected but also the buttons are displayed in the reverse order (button 0 on the left and button 3 on the right) which make that the default button for the return key is button 2 as required by the code.

So, I guess this is a bug on Window and that there is currently no solution to fix it.