# Using Menus

    #include <stdio.h>
    #include "graphapp.h"

    #define NUM_COLOURS 5

    char *colour_name[NUM_COLOURS] = {
      "White", "Black", "Red", "Green", "Blue"
    };
    Colour colour[NUM_COLOURS] = {
      WHITE, BLACK, RED, GREEN, BLUE
    };
    MenuItem *item[NUM_COLOURS];
    Colour which_colour;
    Window *w;

    void draw_window(Window *w, Graphics *g)
    {
      Rect r = get_window_area(w);
      set_colour(g, which_colour);
      fill_rect(g, r);
    }

    void change_colour(MenuItem *m)
    {
      int i, value;

      value = get_menu_item_value(m);

      /* uncheck all items in the menu */
      for (i=0; i < NUM_COLOURS; i++)
        uncheck_menu_item(item[i]);

      /* check this menu item */
      check_menu_item(m);
      which_colour = colour[value];

      /* redraw the window */
      redraw_window(w);
    }

    void quit(MenuItem *m)
    {
      exit(0);
    }