Subversion Repositories Games.Chess Giants

Rev

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

  1. // dialog_endgame.cpp
  2.  
  3. #include "../common.h"
  4.  
  5.  
  6. // dialog template
  7. #define THIS_DIALOG DIALOG_ENDGAME
  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_EndGame (void)
  16. {
  17.    // helper function to fire up the modeless dialog box
  18.  
  19.    _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one
  20.  
  21.    return; // return as soon as the thread is fired up
  22. }
  23.  
  24.  
  25. void DialogBox_EndGame_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_endgame_validated = false;
  31.  
  32.    return; // finished
  33. }
  34.  
  35.  
  36. static void StartThread_ThisDialog (void *thread_parms)
  37. {
  38.    // this function runs in a separate thread, for that's the only way (seemingly)
  39.    // to implement a non-modal message box using the Common Controls library.
  40.  
  41.    // display the dialog box
  42.    if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
  43.       is_dialogbox_endgame_validated = true;
  44.  
  45.    the_board.reevaluate = true; // refresh the GUI buttons if needed
  46.    return; // _endthread() implied
  47. }
  48.  
  49.  
  50. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
  51. {
  52.    // message handler for the dialog box
  53.  
  54.    unsigned short wParam_hiword;
  55.    unsigned short wParam_loword;
  56.  
  57.    // filter out the commonly used message values
  58.    wParam_hiword = HIWORD (wParam);
  59.    wParam_loword = LOWORD (wParam);
  60.  
  61.    // have we just fired up this window ?
  62.    if (message == WM_INITDIALOG)
  63.    {
  64.       // center the window
  65.       CenterWindow (hWnd, hMainWnd);
  66.  
  67.       // set dialog icons (small one for title bar & big one for task manager)
  68.       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  69.       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  70.  
  71.       // set window title and control texts
  72.       SetWindowText (hWnd, LOCALIZE (L"EndGame_Title"));
  73.       SetWindowText (GetDlgItem (hWnd, BUTTON_OK), LOCALIZE (L"Button_OK"));
  74.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_ENDGAME_STATUSBAR), LOCALIZE (L"EndGame_StatusBar"));
  75.  
  76.       // set the right message
  77.       if (the_board.game_state == STATE_WHITEWIN_CHECKMATE)
  78.       {
  79.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_CheckMate"));
  80.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_WhiteWins"));
  81.       }
  82.       else if (the_board.game_state == STATE_BLACKWIN_CHECKMATE)
  83.       {
  84.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_CheckMate"));
  85.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_BlackWins"));
  86.       }
  87.       else if (the_board.game_state == STATE_WHITEWIN_RESIGNORFORFEIT)
  88.       {
  89.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Resign"));
  90.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_WhiteWins"));
  91.       }
  92.       else if (the_board.game_state == STATE_BLACKWIN_RESIGNORFORFEIT)
  93.       {
  94.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Resign"));
  95.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_BlackWins"));
  96.       }
  97.       else if (the_board.game_state == STATE_DRAW_STALEMATE)
  98.       {
  99.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_StaleMate"));
  100.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame"));
  101.       }
  102.       else if (the_board.game_state == STATE_DRAW_AGREEMENT)
  103.       {
  104.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Agreement"));
  105.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame"));
  106.       }
  107.       else if (the_board.game_state == STATE_DRAW_OTHER)
  108.       {
  109.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_DrawGame"));
  110.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), L""); // TODO: display something better
  111.       }
  112.       else if (the_board.game_state == STATE_ADJOURNED)
  113.       {
  114.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Adjourned"));
  115.          Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), L"");
  116.       }
  117.  
  118.       // convert the status bar message to a hyperlink
  119.       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_ENDGAME_STATUSBAR));
  120.    }
  121.  
  122.    // else did we click the close button on the title bar ?
  123.    else if (message == WM_CLOSE)
  124.       EndDialog (hWnd, 0); // close the dialog box
  125.  
  126.    // else did we take action on one of the controls ?
  127.    else if (message == WM_COMMAND)
  128.    {
  129.       // was it the OK button ?
  130.       if (wParam_loword == BUTTON_OK)
  131.          EndDialog (hWnd, 1); // close the dialog box and return OK
  132.  
  133.       // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
  134.       else if (wParam_loword == IDCANCEL)
  135.          EndDialog (hWnd, 0); // close the dialog box
  136.  
  137.       // else was it the status bar hyperlink ?
  138.       else if (wParam_loword == STATICTEXT_ENDGAME_STATUSBAR)
  139.          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
  140.    }
  141.  
  142.    // call the default dialog message processing function to keep things going
  143.    return (false);
  144. }
  145.