test/testmessage.c
changeset 6614 92925281e7ca
child 6722 37283d4416e0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testmessage.c	Tue Oct 30 10:11:25 2012 -0700
     1.3 @@ -0,0 +1,86 @@
     1.4 +/*
     1.5 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     1.6 +
     1.7 +  This software is provided 'as-is', without any express or implied
     1.8 +  warranty.  In no event will the authors be held liable for any damages
     1.9 +  arising from the use of this software.
    1.10 +
    1.11 +  Permission is granted to anyone to use this software for any purpose,
    1.12 +  including commercial applications, and to alter it and redistribute it
    1.13 +  freely.
    1.14 +*/
    1.15 +
    1.16 +/* Simple test of the SDL MessageBox API*/
    1.17 +
    1.18 +#include <stdio.h>
    1.19 +#include <stdlib.h>
    1.20 +#include <signal.h>
    1.21 +
    1.22 +#include "SDL.h"
    1.23 +#include "SDL_thread.h"
    1.24 +
    1.25 +static int alive = 0;
    1.26 +
    1.27 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.28 +static void
    1.29 +quit(int rc)
    1.30 +{
    1.31 +    SDL_Quit();
    1.32 +    exit(rc);
    1.33 +}
    1.34 +
    1.35 +int
    1.36 +main(int argc, char *argv[])
    1.37 +{
    1.38 +    int success;
    1.39 +
    1.40 +    /* Load the SDL library */
    1.41 +    if (SDL_Init(0) < 0) {
    1.42 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.43 +        return (1);
    1.44 +    }
    1.45 +
    1.46 +    success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
    1.47 +                "Simple MessageBox",
    1.48 +                "This is a simple error MessageBox",
    1.49 +                NULL);
    1.50 +    if (success == -1) {
    1.51 +        printf("Error Presenting MessageBox: %s\n", SDL_GetError());
    1.52 +        quit(1);
    1.53 +    }
    1.54 +
    1.55 +    {
    1.56 +        const SDL_MessageBoxButtonData buttons[] = {
    1.57 +            {
    1.58 +                SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
    1.59 +                0,
    1.60 +                "OK"
    1.61 +            },{
    1.62 +                SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
    1.63 +                1,
    1.64 +                "Cancel"
    1.65 +            },
    1.66 +        };
    1.67 +
    1.68 +        SDL_MessageBoxData data = {
    1.69 +            SDL_MESSAGEBOX_INFORMATION,
    1.70 +            NULL, // no parent window
    1.71 +            "Custom MessageBox",
    1.72 +            "This is a custom messagebox",
    1.73 +            2,
    1.74 +            buttons,
    1.75 +            NULL // Default color scheme
    1.76 +        };
    1.77 +
    1.78 +        int button = -1;
    1.79 +        success = SDL_ShowMessageBox(&data, &button);
    1.80 +        if (success == -1) {
    1.81 +            printf("Error Presenting MessageBox: %s\n", SDL_GetError());
    1.82 +            quit(2);
    1.83 +        }
    1.84 +        printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
    1.85 +    }
    1.86 +
    1.87 +    SDL_Quit();
    1.88 +    return (0);
    1.89 +}