Skip to main content
gamedev.net
🔒 Locked

SDL and MessageBoxes

Started by TheNobleOne 8 replies 1k views
Original Post
TheNobleOne
TheNobleOne
Ok I am making a 2D Isometric engine. I am using SDL for windowing and OpenGL for rendering. My problem is that I want to implement MessageBoxes to my windowing piece of the engine. I was wondering if there was a way I can do a message box with SDL or do I have to use Win32? I would much prefer to avoid Win32 because of portability issues of doing so.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Spudder
Spudder
There's no way of creating message boxes directly from SDL, what you can do instead is create a function PrintError(const string &Error) or something like that, inside the function you could use something like this:

void PrintError(const string &Error){ #ifdef WIN32     //use message box #else   //use cout/cerr instead}


This hides away all the Win32 specific stuff inside a function to make the code a little cleaner instead of loads of #ifdefs.
samuraicrow
samuraicrow
I think it's possible to open a second window using SDL but you may need a derived C++ library called HXRender
TheNobleOne
TheNobleOne
Quote:
Original post by Spudder
There's no way of creating message boxes directly from SDL, what you can do instead is create a function PrintError(const string &Error) or something like that, inside the function you could use something like this:

void PrintError(const string &Error){ #ifdef WIN32     //use message box #else   //use cout/cerr instead}


This hides away all the Win32 specific stuff inside a function to make the code a little cleaner instead of loads of #ifdefs.


I think this will work.

My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Spudder
Spudder
Quote:
Original post by samuraicrow
I think it's possible to open a second window using SDL but you may need a derived C++ library called HXRender


AFAIK you can't create multiple windows in SDL. HxRender is a completely different library which provides some functionality for using SDL with OpenGL. I haven't really looked into any GUI libraries for SDL so I'm not sure if any do exist but this could be one approach, but for a simple message box it might be overkill.

TheNobleOne
TheNobleOne
Is there a way I can check to see what os is in use so I know whether or not to include they windows header file. Because if I include the windows header file and it does not exist it will not link and compile correct.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Spudder
Spudder
You can use #ifdef WIN32 to check to see if you compiling on windows, something like this:

#ifdef WIN32#include <windows.h>#endif


That'll prevent the compiler from tryin to include windows.h on non win32 platforms as WIN32 will only be defined on Windows (obviously).
TheNobleOne
TheNobleOne
Ok thanks a bunch that should do the trick then.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Kylotan
Kylotan
There are a few SDL gui libraries available. You may wish to consider using one, so that you get their message box capabilities across all your platforms.
TheNobleOne
TheNobleOne
Well I will eventually maybe look for refinements on my window manager for my Engine however, for now error pushing into the linux console on linux will work for now. If worse comes to worse I could alwasy use GTK or something for the message box on linux. But my window manager is working :D it is compiled and tested and works wonderfully. I however, need to learn some more about isometrics as my engine is going to be 2D isometric.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.