Search code examples
c++linuxwxwidgetsx11messagebox

(C++) MessageBox for Linux like in MS Windows


I need to implement a simple graphical message box for a Linux (SDL) application similar to the Windows MessageBox in C++ (gcc/g++ 4.4.0). All it needs to do is to display a caption, a message and an ok or close button and to return to the calling function when that button is clicked.

SDL just uses X(11) to open a window for (OpenGL) rendering.

I have looked through a similar thread regarding a GTK implementation, but that implementation doesn't seem to work properly.

I have also tried wxWidgets' wxMessageBox function, but compiling the headers makes the compiler throw error messages about syntax errors in include/c++/4.4.0/bits/stl_algobase.h (gcc 4.4.0 32 bits on openSuSE 11.1 32 bits). Using wxWidgets also means having to link a ton of libraries, adding STL to my app (Which it doesn't need otherwise) and who knows what else, so I do not want to use wxWidgets.

X11/motif (openmotif) has what I need (XmCreate{Error|Warning|InfoDialog), but these need a parent widget (e.g. top level window) which I don't have and do not accept a NULL parameter for these.

So I am stumped right now. Is there a simple way to do what I want? Or at least a halfway simple/easy/straightforward one? If yes, which one (giving as many details as possible would be highly appreciated).


Solution

  • In SDL2, you can now show message boxes:

    http://wiki.libsdl.org/SDL_ShowSimpleMessageBox

    int SDL_ShowSimpleMessageBox(Uint32      flags,
                                 const char* title,
                                 const char* message,
                                 SDL_Window* window)
    

    http://wiki.libsdl.org/SDL_ShowMessageBox

    int SDL_ShowMessageBox(const SDL_MessageBoxData* messageboxdata,
                           int*                      buttonid)