Subversion Repositories Games.Chess Giants

Rev

Rev 124 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // dialog_renamesides.cpp
  2.  
  3. #include "../common.h"
  4.  
  5.  
  6. // dialog template
  7. #define THIS_DIALOG DIALOG_RENAMESIDES
  8.  
  9.  
  10. // global variables
  11. static wchar_t black_name[64];
  12. static wchar_t white_name[64];
  13.  
  14.  
  15. // prototypes of local functions
  16. static void StartThread_ThisDialog (void *thread_parms);
  17. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam);
  18.  
  19.  
  20. void DialogBox_RenameSides (void)
  21. {
  22.    // helper function to fire up the modeless dialog box
  23.  
  24.    is_dialogbox_displayed = true;
  25.    _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new message box thread
  26.  
  27.    return; // return as soon as the thread is fired up
  28. }
  29.  
  30.  
  31. void DialogBox_RenameSides_Validated (void)
  32. {
  33.    // callback function called by the main game thread when the dialog box is validated
  34.  
  35.    // set the player's names
  36.    wcscpy_s (the_board.players[COLOR_BLACK].name, WCHAR_SIZEOF (the_board.players[COLOR_BLACK].name), black_name);
  37.    wcscpy_s (the_board.players[COLOR_WHITE].name, WCHAR_SIZEOF (the_board.players[COLOR_WHITE].name), white_name);
  38.    the_board.reevaluate = true; // and reevaluate the game's state
  39.  
  40.    // remember this callback is no longer to be called
  41.    is_dialogbox_renamesides_validated = false;
  42.  
  43.    return; // finished
  44. }
  45.  
  46.  
  47. static void StartThread_ThisDialog (void *thread_parms)
  48. {
  49.    // this function runs in a separate thread, for that's the only way (seemingly)
  50.    // to implement a non-modal message box using the Common Controls library.
  51.  
  52.    // display the dialog box
  53.    if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
  54.       is_dialogbox_renamesides_validated = true;
  55.    is_dialogbox_displayed = false;
  56.  
  57.    the_board.reevaluate = true; // refresh the GUI buttons if needed
  58.    return; // _endthread() implied
  59. }
  60.  
  61.  
  62. static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
  63. {
  64.    unsigned short wParam_hiword;
  65.    unsigned short wParam_loword;
  66.  
  67.    // filter out the commonly used message values
  68.    wParam_hiword = HIWORD (wParam);
  69.    wParam_loword = LOWORD (wParam);
  70.  
  71.    // have we just fired up this window ?
  72.    if (message == WM_INITDIALOG)
  73.    {
  74.       // center the window
  75.       CenterWindow (hWnd, hMainWnd);
  76.  
  77.       // set dialog icons (small one for title bar & big one for task manager)
  78.       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  79.       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  80.  
  81.       // set window title and control texts
  82.       SetWindowText (hWnd, LOCALIZE (L"Menu_ChessboardRenameSides"));
  83.       SetDlgItemText (hWnd, BUTTON_OK, LOCALIZE (L"Button_OK"));
  84.       SetDlgItemText (hWnd, STATICTEXT_RENAMESIDES_STATUSBAR, LOCALIZE (L"GoToMove_StatusBar"));
  85.  
  86.       // set the player's names
  87.       SetDlgItemText (hWnd, EDITBOX_BLACKNAME, the_board.players[COLOR_BLACK].name); // get black player name
  88.       SetDlgItemText (hWnd, EDITBOX_WHITENAME, the_board.players[COLOR_WHITE].name); // get white player name
  89.  
  90.       // convert the status bar message to a hyperlink
  91.       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_RENAMESIDES_STATUSBAR));
  92.    }
  93.  
  94.    // else did we take action on one of the controls ?
  95.    else if (message == WM_COMMAND)
  96.    {
  97.       // was it the OK button ?
  98.       if (wParam_loword == BUTTON_OK)
  99.       {
  100.          GetDlgItemText (hWnd, EDITBOX_BLACKNAME, black_name, WCHAR_SIZEOF (black_name)); // get black player name
  101.          GetDlgItemText (hWnd, EDITBOX_WHITENAME, white_name, WCHAR_SIZEOF (white_name)); // get white player name
  102.  
  103.          EndDialog (hWnd, 1); // close the dialog box and return OK
  104.       }
  105.  
  106.       // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
  107.       else if (wParam_loword == IDCANCEL)
  108.          EndDialog (hWnd, 0); // close the dialog box
  109.  
  110.       // else was it the status bar hyperlink ?
  111.       else if (wParam_loword == STATICTEXT_RENAMESIDES_STATUSBAR)
  112.          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
  113.    }
  114.  
  115.    // call the default dialog message processing function to keep things going
  116.    return (false);
  117. }
  118.