Hidden Message Box (native dialogs)
AMCerasoli

Hi guys I was making another tutorial and realize that after creating a display the message box using al_show_native_message_box() appear behind the display application, making it impossible to the user to know what it's happening. Am I doing something wrong?

Well this is the example I was about to show:

#SelectExpand
1#include "allegro5/allegro.h" 2#include "allegro5/allegro_image.h" 3#include "allegro5/allegro_primitives.h" 4#include "allegro5/allegro_native_dialog.h" 5 6short m_box(const char* message = "No message given", 7 const char* content_title = "Error", 8 const char* title = "Error"){ 9 10 switch(al_show_native_message_box(NULL, title, content_title, 11 message, NULL, 12 ALLEGRO_MESSAGEBOX_ERROR)){ 13 14 case 0: return 0; // User pressed the Cancel button 15 case 1: return 1; // " " " OK " 16 case 2: return 2; // I don't understand what does this 17 18 } 19} 20 21ALLEGRO_BITMAP *make_err_ima(ALLEGRO_DISPLAY *T_disp){ 22 23 ALLEGRO_BITMAP *T_img = al_create_bitmap(32,32); 24 if(!T_img)return 0; 25 al_set_target_bitmap(T_img); 26 al_clear_to_color(al_map_rgb(255, 0, 0)); 27 al_draw_line( 0, 0, 32, 32, al_map_rgb(255, 255, 255), 1.5); 28 al_draw_line(32, 0, 0, 32, al_map_rgb(255, 255, 255), 1.5); 29 al_set_target_bitmap(al_get_backbuffer(T_disp)); 30 return T_img; 31 32} 33 34int main(){ 35 36 ALLEGRO_DISPLAY *display = NULL; 37 ALLEGRO_BITMAP *image = NULL; 38 39 if(!al_init()) { 40 m_box("Problems when initilizing Allegro"); 41 } 42 43 if(!al_init_image_addon()) { 44 m_box("Problems when initilizing the image addon"); 45 } 46 47 if(!al_init_primitives_addon()) { 48 m_box("Problems when initilizing the primitives addon"); 49 } 50 51 display = al_create_display(800,600); 52 53 if(!display){ 54 m_box("Problems when creating the display"); 55 } 56 //Since all this initializations are very necessary, there is no much we can do in case they fail 57 58 image = make_err_ima(display); 59 60 if(!image){ 61 m_box("Problems when creating the image"); 62 return 0; 63 } 64/* 65 al_draw_bitmap(image, 200, 200, 0); 66 67 al_flip_display(); 68 69 al_rest(2); 70*/ 71 al_destroy_bitmap(image); 72 73 return 0; 74}

Thanks!.

torhu

Try using al_get_current_display() as the first argument of al_show_native_message_box(), instead of NULL.

AMCerasoli

Thank you man!, you just solve it!. :D

tobing

Same for me, had the same problem. I thought it was some weird Windows thing...

AMCerasoli

Yes the thing is that even when I have seen that function (al_get_current_display()) in the past, I didn't have it in mind, I don't know why, in fact in my current game, there are a lot of "display" pointers going around... How stupid of me...

Anyway I finish another tut, if you want to check it to see if there are some errors and stuff... Showing a basic native GUI message box. It got bigger than I would like it to be, but wth...

torhu

The docs for that function is in the wrong section of the manual, too.

AMCerasoli

Yep, it should definitively be placed into the Display section.

Thread #608918. Printed from Allegro.cc