/* * Saving Files * ------------ * This program creates a window which asks you a question when * you try to close it. * * It demonstrates the use of the setclose function to handle * window closure, and also the dialog box functions askok and * askyesnocancel. The askfilename function is used to obtain * a file name from the user. */ #include void close_it(window w) { char *filename = NULL; int result = askyesnocancel("Save changes?"); if (result == YES) { filename = askfilename("Save the file as:", "untitled.txt"); /* save the file somehow */ if (filename != NULL) printf("Saving file %s ...\n", filename); askok("The file was sucessfully saved."); } else if (result == CANCEL) return; hide(w); } void main(void) { window w; w = newwindow("Text Editor", rect(0,0,300,250), StandardWindow); setclose(w, close_it); show(w); mainloop(); }