Microsoft.Xna.Framework.Input.... MessageBox?

I want to do system-message style errors in my game (mostly just for my own debugging). I don’t want to tie to windows platform so I don’t want to use Winforms MessageBox. However, I see in the Monogame documentation that XNA includes a MessageBox class:

https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.MessageBox.html

My version of XNA does not seem to have it. I might be slightly outdated as I haven’t worked on my games in the last half-year. Is this a new feature? Or is this an old feature that was removed? I’m just curious when this was added / if it really exists, as I can’t find much info on it and it doesn’t seem to be in my XNA.

You didn’t mention which platform you’re compiling against, but for DesktopGL we can see that it’s excluded from compilation, probably because there’s no good cross platform way to invoke GUI https://github.com/MonoGame/MonoGame/blob/develop/MonoGame.Framework/MonoGame.Framework.DesktopGL.csproj#L42

I bet if you try with WindowsDX it’ll show up

OK that might be why, I’m compiling for “Any CPU” so it’s probably excluded. Sounds like l just need to roll my own instead. Darn, got my hopes up lol

Yeah it’s working in WindowsDX but not implemented in DesktopGL, which is strange when DesktopGL uses SDL2 which could use ShowSimpleMessageBox (SDL2/SDL_ShowSimpleMessageBox - SDL Wiki).

If you build from source you can add the following to get this function working:

SDL2.cs Init

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void d_sdl_showSimpleMessageBox(UInt32 flags, IntPtr title, IntPtr message, IntPtr window);
public static d_sdl_showSimpleMessageBox SDL_ShowSimpleMessageBox = FuncLoader.LoadFunction<d_sdl_showSimpleMessageBox>(NativeLibrary, "SDL_ShowSimpleMessageBox");

SDLGameWindow.cs

public unsafe override void ShowSimpleMessageBox(int iconType, string title, string message)
{
    byte[] titleBytes= Encoding.UTF8.GetBytes(title);
    byte[] messageBytes = Encoding.UTF8.GetBytes(message);
    fixed (byte* ptrTitleBytes = titleBytes)
    {
        fixed (byte* ptrMessageBytes = messageBytes)
        {
            Sdl.Window.SDL_ShowSimpleMessageBox((UInt32)iconType, (IntPtr)ptrTitleBytes, (IntPtr)ptrMessageBytes, Handle);
        }
    }
}

GameWindow.cs

public abstract void ShowSimpleMessageBox(int iconType, string title, string message);

The correct way would be to implement this through Input.MessageBox.Show.PlatformShow, but this is a quick workaround.

2 Likes

Awesome, thank you!