Subversion Repositories Games.Chess Giants

Rev

Rev 1 | Rev 124 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.    _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new thread to display the dialog box
  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.  
  44.    // display the dialog box
  45.    if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
  46.       is_dialogbox_quit_validated = true;
  47.  
  48.    return; // _endthread() implied
  49. }
  50.  
  51.  
  52. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
  53. {
  54.    // message handler for the dialog box
  55.  
  56.    unsigned short wParam_hiword;
  57.    unsigned short wParam_loword;
  58.  
  59.    // filter out the commonly used message values
  60.    wParam_hiword = HIWORD (wParam);
  61.    wParam_loword = LOWORD (wParam);
  62.  
  63.    // have we just fired up this window ?
  64.    if (message == WM_INITDIALOG)
  65.    {
  66.       // center the window
  67.       CenterWindow (hWnd, hMainWnd);
  68.  
  69.       // set dialog icons (small one for title bar & big one for task manager)
  70.       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  71.       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  72.  
  73.       // set window title and control texts
  74.       SetWindowText (hWnd, LOCALIZE (L"Quit_Title"));
  75.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_QUIT_QUESTION), LOCALIZE (L"Quit_Question"));
  76.       SetWindowText (GetDlgItem (hWnd, BUTTON_GIVEUPANDQUIT), LOCALIZE (L"Quit_GiveUpAndQuit"));
  77.       SetWindowText (GetDlgItem (hWnd, BUTTON_BACKTOGAME), LOCALIZE (L"Quit_BackToGame"));
  78.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_QUIT_STATUSBAR), LOCALIZE (L"Quit_StatusBar"));
  79.  
  80.       // play the "question" system sound
  81.       PlaySound ((LPCWSTR) SND_ALIAS_SYSTEMASTERISK, NULL, SND_ALIAS_ID | SND_ASYNC);
  82.  
  83.       // convert the status bar message to a hyperlink
  84.       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_QUIT_STATUSBAR));
  85.    }
  86.  
  87.    // else did we click the close button on the title bar ?
  88.    else if (message == WM_CLOSE)
  89.       EndDialog (hWnd, 0); // close the dialog box
  90.  
  91.    // else did we take action on one of the controls ?
  92.    else if (message == WM_COMMAND)
  93.    {
  94.       // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
  95.       if (wParam_loword == IDCANCEL)
  96.          EndDialog (hWnd, 0); // close the dialog box
  97.  
  98.       // else was it the quit button ?
  99.       else if (wParam_loword == BUTTON_GIVEUPANDQUIT)
  100.          EndDialog (hWnd, 1); // close the dialog box and return a success value
  101.  
  102.       // else was it the back to game button ?
  103.       else if (wParam_loword == BUTTON_BACKTOGAME)
  104.          EndDialog (hWnd, 0); // close the dialog box
  105.  
  106.       // else was it the status bar hyperlink ?
  107.       else if (wParam_loword == STATICTEXT_QUIT_STATUSBAR)
  108.          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
  109.    }
  110.  
  111.    // call the default dialog message processing function to keep things going
  112.    return (false);
  113. }
  114.