Tuesday, 25 February 2014

Allegro Message Boxes

To start using message boxes in Allegro 5 you'll need to include this file:

#include<allegro5\allegro_native_dialog.h>

This will allow you to use boxes that match your operating system.

The following function sets up the message box.  Using display as the first argument will place the window in front of the display. Leaving it as NULL will leave the message box behind the display. The second argument is the box title and the third is the message heading that will display inside the box. Forth argument is where you put your message.

al_show_native_message_box(display, "Error Message", "Error", "Could not initialize Allegro 5", NULL, ALLEGRO_MESSAGEBOX_ERROR);

The last argument represents the type of message box. The following is a list of available options.

ALLEGRO_MESSAGEBOX_WARN          
ALLEGRO_MESSAGEBOX_ERROR          
ALLEGRO_MESSAGEBOX_OK_CANCEL      
ALLEGRO_MESSAGEBOX_YES_NO      
ALLEGRO_MESSAGEBOX_QUESTION

You can use two options at once for example ALLEGRO_MESSAGEBOX_WARN | ALLEGRO_MESSAGEBOX_YES_NO.

The al_show_native_message_box function returns an int that represents which answer the user chose. To access it allocate a variable to it.

int answer = al_show_native_message_box(display, "Error Message", "Error", "Could not initialize Allegro 5", NULL, ALLEGRO_MESSAGEBOX_ERROR);

If the answer is no the return value will be 0. If yes then 1.

No comments:

Post a Comment