In this example, a WM_CLOSE message is received. If the fChanges flag is set, the application calls a function to determine if the user wants to save the changes before exiting. This function (called QuerySaveFile in this example) asks the user if he wants to save the changes. If the user selects OK, the changes are saved. If the user selects cancel, the function returns this value and the application continues normal execution. Otherwise, it posts a WM_QUIT message to terminate the application.

case WM_CLOSE:
    if (fChanges) {             /* changes have not been saved */
        if (QuerySaveFile(hwnd) == MB_CANCEL) {
            return (0L);        /* do not exit after all       */
        }
    }
    WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
    return (0L);


[Back] [Next]