Rev 19 | Rev 124 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | // dialog_quit.cpp |
| 2 | |||
| 3 | #include "../common.h" |
||
| 4 | |||
| 5 | |||
| 6 | // dialog template |
||
| 7 | #define THIS_DIALOG DIALOG_QUIT |
||
| 8 | |||
| 9 | |||
| 10 | // prototypes of local functions |
||
| 11 | static void StartThread_ThisDialog (void *thread_parms); |
||
| 12 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
| 13 | |||
| 14 | |||
| 15 | void DialogBox_Quit (void) |
||
| 16 | { |
||
| 17 | // helper function to fire up the modeless dialog box |
||
| 18 | |||
| 19 | pmbaty | 19 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new thread to display the dialog box |
| 1 | pmbaty | 20 | |
| 21 | return; // return as soon as the thread is fired up |
||
| 22 | } |
||
| 23 | |||
| 24 | |||
| 25 | void DialogBox_Quit_Validated (void) |
||
| 26 | { |
||
| 27 | // callback function called by the main game thread when the dialog box is validated |
||
| 28 | |||
| 29 | // remember this callback is no longer to be called |
||
| 30 | is_dialogbox_quit_validated = false; |
||
| 31 | |||
| 32 | // destroy the main window, which in turn will raise the "terminate_everything" global flag |
||
| 33 | DestroyWindow (hMainWnd); |
||
| 34 | |||
| 35 | return; // finished, we're now quitting the program |
||
| 36 | } |
||
| 37 | |||
| 38 | |||
| 39 | static void StartThread_ThisDialog (void *thread_parms) |
||
| 40 | { |
||
| 41 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
| 42 | // to implement a non-modal message box using the Common Controls library. |
||
| 43 | |||
| 119 | pmbaty | 44 | int retval; |
| 1 | pmbaty | 45 | |
| 119 | pmbaty | 46 | // display the dialog box and grab its return value |
| 47 | retval = DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog); |
||
| 48 | if (retval == 1) |
||
| 49 | is_dialogbox_quit_validated = true; // if we simply want to quit, flag the quit dialog box as confirmed |
||
| 50 | else if (retval == 2) |
||
| 51 | DialogBox_Save (true); // else if we want to save THEN quit, fire up the save dialog box first (and tell it to raise the quit confirmation flag after it returns) |
||
| 52 | |||
| 1 | pmbaty | 53 | return; // _endthread() implied |
| 54 | } |
||
| 55 | |||
| 56 | |||
| 57 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
| 58 | { |
||
| 59 | // message handler for the dialog box |
||
| 60 | |||
| 61 | unsigned short wParam_hiword; |
||
| 62 | unsigned short wParam_loword; |
||
| 63 | |||
| 64 | // filter out the commonly used message values |
||
| 65 | wParam_hiword = HIWORD (wParam); |
||
| 66 | wParam_loword = LOWORD (wParam); |
||
| 67 | |||
| 68 | // have we just fired up this window ? |
||
| 69 | if (message == WM_INITDIALOG) |
||
| 70 | { |
||
| 71 | // center the window |
||
| 72 | CenterWindow (hWnd, hMainWnd); |
||
| 73 | |||
| 74 | // set dialog icons (small one for title bar & big one for task manager) |
||
| 75 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 76 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
| 77 | |||
| 78 | // set window title and control texts |
||
| 79 | SetWindowText (hWnd, LOCALIZE (L"Quit_Title")); |
||
| 119 | pmbaty | 80 | |
| 81 | // are we online AND has a game started, or are we playing locally in which case it is acceptable to simply quit now ? |
||
| 82 | if ((Player_FindByType (PLAYER_INTERNET) != NULL) && (the_board.move_count > 1)) |
||
| 83 | { |
||
| 84 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_QUIT_QUESTION), LOCALIZE (L"Quit_OnlineQuestion")); |
||
| 85 | SetWindowText (GetDlgItem (hWnd, BUTTON_GIVEUPANDQUIT), LOCALIZE (L"Quit_GiveUpAndQuit")); |
||
| 86 | SetWindowText (GetDlgItem (hWnd, BUTTON_BACKTOGAME), LOCALIZE (L"Quit_BackToGame")); |
||
| 87 | } |
||
| 88 | else |
||
| 89 | { |
||
| 90 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_QUIT_QUESTION), LOCALIZE (L"Quit_OfflineQuestion")); |
||
| 91 | SetWindowText (GetDlgItem (hWnd, BUTTON_GIVEUPANDQUIT), LOCALIZE (L"Quit_SaveAndQuit")); |
||
| 92 | SetWindowText (GetDlgItem (hWnd, BUTTON_BACKTOGAME), LOCALIZE (L"Quit_SimplyQuit")); |
||
| 93 | } |
||
| 1 | pmbaty | 94 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_QUIT_STATUSBAR), LOCALIZE (L"Quit_StatusBar")); |
| 95 | |||
| 19 | pmbaty | 96 | // play the "question" system sound |
| 97 | PlaySound ((LPCWSTR) SND_ALIAS_SYSTEMASTERISK, NULL, SND_ALIAS_ID | SND_ASYNC); |
||
| 98 | |||
| 1 | pmbaty | 99 | // convert the status bar message to a hyperlink |
| 100 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_QUIT_STATUSBAR)); |
||
| 101 | } |
||
| 102 | |||
| 103 | // else did we click the close button on the title bar ? |
||
| 104 | else if (message == WM_CLOSE) |
||
| 105 | EndDialog (hWnd, 0); // close the dialog box |
||
| 106 | |||
| 107 | // else did we take action on one of the controls ? |
||
| 108 | else if (message == WM_COMMAND) |
||
| 109 | { |
||
| 110 | // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
| 111 | if (wParam_loword == IDCANCEL) |
||
| 112 | EndDialog (hWnd, 0); // close the dialog box |
||
| 113 | |||
| 119 | pmbaty | 114 | // else was it the "give up and quit" or "save and quit" button ? |
| 1 | pmbaty | 115 | else if (wParam_loword == BUTTON_GIVEUPANDQUIT) |
| 119 | pmbaty | 116 | { |
| 117 | // are we online AND has a game started, or are we playing locally ? |
||
| 118 | if ((Player_FindByType (PLAYER_INTERNET) != NULL) && (the_board.move_count > 1)) |
||
| 119 | EndDialog (hWnd, 1); // when playing remotely, button is labeled "give up and quit" --> close the dialog box and return a value that tells to quit |
||
| 120 | else |
||
| 121 | EndDialog (hWnd, 2); // when playing locally, button is labeled "save and quit" --> close the dialog box and return a value that tells to display a "save" dialog box |
||
| 122 | } |
||
| 1 | pmbaty | 123 | |
| 119 | pmbaty | 124 | // else was it the "back to game" or "simply quit" button ? |
| 1 | pmbaty | 125 | else if (wParam_loword == BUTTON_BACKTOGAME) |
| 119 | pmbaty | 126 | { |
| 127 | // are we online AND has a game started, or are we playing locally ? |
||
| 128 | if ((Player_FindByType (PLAYER_INTERNET) != NULL) && (the_board.move_count > 1)) |
||
| 129 | EndDialog (hWnd, 0); // when playing remotely, button is labeled "back to game" --> close the dialog box and return a value that tells to do nothing |
||
| 130 | else |
||
| 131 | EndDialog (hWnd, 1); // when playing locally, button is labeled "just quit" --> close the dialog box and return a value that tells to quit |
||
| 132 | } |
||
| 1 | pmbaty | 133 | |
| 134 | // else was it the status bar hyperlink ? |
||
| 135 | else if (wParam_loword == STATICTEXT_QUIT_STATUSBAR) |
||
| 136 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
| 137 | } |
||
| 138 | |||
| 139 | // call the default dialog message processing function to keep things going |
||
| 140 | return (false); |
||
| 141 | } |