test/testmessage.c
changeset 7456 193c9a1723ad
parent 7088 664d8532219b
child 7458 648067e9073a
equal deleted inserted replaced
7455:0a988affc7e7 7456:193c9a1723ad
    92     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    92     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    93         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    93         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    94         return (1);
    94         return (1);
    95     }
    95     }
    96 
    96 
       
    97 #if 0
    97     success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
    98     success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
    98                 "Simple MessageBox",
    99                 "Simple MessageBox",
    99                 "This is a simple error MessageBox",
   100                 "This is a simple error MessageBox",
   100                 NULL);
   101                 NULL);
   101     if (success == -1) {
   102     if (success == -1) {
   132         quit(1);
   133         quit(1);
   133     }
   134     }
   134 
   135 
   135     button_messagebox(NULL);
   136     button_messagebox(NULL);
   136 
   137 
   137     /* Technically this isn't a supported operation for the API, but it doesn't
   138     /* Test showing a message box from a background thread */
   138      * hurt for it to work.
       
   139      */
       
   140     {
   139     {
   141         int status = 0;
   140         int status = 0;
   142         SDL_Event event;
   141         SDL_Event event;
   143         intptr_t eventNumber = SDL_RegisterEvents(1);
   142         intptr_t eventNumber = SDL_RegisterEvents(1);
   144         SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber);
   143         SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber);
   152 
   151 
   153         SDL_WaitThread(thread, &status);
   152         SDL_WaitThread(thread, &status);
   154 
   153 
   155         printf("Message box thread return %i\n", status);
   154         printf("Message box thread return %i\n", status);
   156     }
   155     }
       
   156 #endif
       
   157 
       
   158     /* Test showing a message box with a parent window */
       
   159     {
       
   160         SDL_Event event;
       
   161         SDL_Window *window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
       
   162 
       
   163         success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
       
   164                     "Simple MessageBox",
       
   165                     "This is a simple error MessageBox with a parent window",
       
   166                     window);
       
   167         if (success == -1) {
       
   168             printf("Error Presenting MessageBox: %s\n", SDL_GetError());
       
   169             quit(1);
       
   170         }
       
   171 
       
   172         while (SDL_WaitEvent(&event))
       
   173         {
       
   174             if (event.type == SDL_QUIT || event.type == SDL_KEYUP) {
       
   175                 break;
       
   176             }
       
   177         }
       
   178     }
   157 
   179 
   158     SDL_Quit();
   180     SDL_Quit();
   159     return (0);
   181     return (0);
   160 }
   182 }