# Saving Files

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

    App *app;

    void close_it(Window *w)
    {
      char *filename = NULL;
      int result = ask_yes_no_cancel(app, "Confirm Save", "Save changes?");

      if (result == YES) {
        filename = ask_file_save(app, "Save File As",
                                 "Save the file as:", "untitled.txt");
        /* save the file somehow */
        ask_ok(app, "File Saved", "The file was sucessfully saved.");
      }
      else if (result == CANCEL)
         return;

      hide_window(w);
    }

    int main(int argc, char *argv[])
    {
      Window *w;

      app = new_app(argc, argv);
      w = newwindow(app, rect(0,0,300,250),
                    "Text Editor", STANDARD_WINDOW);
      setclose(w, close_it);
      show_window(w);
      main_loop(app);
      return 0;
    }

Notes:

- Dialog windows can be used to ask the user questions.
- The dialog functions typically start with `ask_`
- Here, when the window is closed, the call-back is called. It uses some dialog windows to ask if the user wants to save the file, and if so, asks for the file name.