/* * Save Text * --------- * This program lets the user type some text into a textbox, * and save the text into a file when the window is closed. */ #include /** TextEditor application variables: **/ textbox user_text; // Textbox control to hold user's text. /** This function is called when the user closes the window. ** It saves the text from the textbox to a file. **/ void closeWindow(window w) { FILE *file = fopen("saved.txt", "w"); if (file != NULL) { fprintf(file, "%s", gettext(user_text)); fclose(file); } hide(w); } /** The main function is the starting point of the ** application. Here, the windows and controls are ** created, then mainloop is called to handle events. **/ void main(void) { // Create and show the application window. window w = newwindow("Text Editor", rect(50,50,400,200), StandardWindow); show(w); // Tell the window what to do if closed. setclose(w, closeWindow); // Create the textbox and add it to the window. user_text = newtextbox("", rect(10,10,380,180)); // Allow GraphApp to handle all events. mainloop(); }