- // dialog_endgame.cpp 
-   
- #include "../common.h" 
-   
-   
- // dialog template 
- #define THIS_DIALOG DIALOG_GOTOMOVE 
-   
-   
- // global variables used in this module only 
- static int wanted_move = 0; 
-   
-   
- // prototypes of local functions 
- static void StartThread_ThisDialog (void *thread_parms); 
- static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); 
-   
-   
- void DialogBox_GoToMove (void) 
- { 
-    // helper function to fire up the modeless dialog box 
-   
-    _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one 
-   
-    return; // return as soon as the thread is fired up 
- } 
-   
-   
- void DialogBox_GoToMove_Validated (void) 
- { 
-    // callback function called by the main game thread when the dialog box is validated 
-   
-    // remember this callback is no longer to be called 
-    is_dialogbox_gotomove_validated = false; 
-   
-    // enter view mode and set the viewed move to the one we want (with sanity checks) 
-    if (wanted_move < 0) 
-       the_board.viewed_move = 0; // clamp min to start state 
-    else if ((the_board.move_count > 1) && (wanted_move > the_board.move_count - 1)) 
-       the_board.viewed_move = the_board.move_count - 1; // clamp max to last move 
-    else 
-       the_board.viewed_move = wanted_move; // else any move in between 
-   
-    the_board.reevaluate = true; // evaluate board again 
-    return; // finished, invitation is sent 
- } 
-   
-   
- static void StartThread_ThisDialog (void *thread_parms) 
- { 
-    // this function runs in a separate thread, for that's the only way (seemingly) 
-    // to implement a non-modal message box using the Common Controls library. 
-   
-    // display the dialog box 
-    if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1) 
-       is_dialogbox_gotomove_validated = true; 
-   
-    the_board.reevaluate = true; // refresh the GUI buttons if needed 
-    return; // _endthread() implied 
- } 
-   
-   
- static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) 
- { 
-    // message handler for the dialog box 
-   
-    unsigned short wParam_hiword; 
-    unsigned short wParam_loword; 
-   
-    // filter out the commonly used message values 
-    wParam_hiword = HIWORD (wParam); 
-    wParam_loword = LOWORD (wParam); 
-   
-    // have we just fired up this window ? 
-    if (message == WM_INITDIALOG) 
-    { 
-       // center the window 
-       CenterWindow (hWnd, hMainWnd); 
-   
-       // set dialog icons (small one for title bar & big one for task manager) 
-       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); 
-       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); 
-   
-       // set window title and control texts 
-       SetWindowText (hWnd, LOCALIZE (L"GoToMove_Title")); 
-       SetDlgItemText (hWnd, BUTTON_OK, LOCALIZE (L"Button_OK")); 
-       SetDlgItemText (hWnd, STATICTEXT_GOTOMOVE, LOCALIZE (L"GoToMove")); 
-       SetDlgItemInt (hWnd, EDITBOX_GOTOMOVE, MOVEINDEX_TO_PGNMOVENUMBER (the_board.viewed_move), false); 
-       SetDlgItemText (hWnd, RADIOBUTTON_GOTOMOVE_WHITE, LOCALIZE (L"Games_White")); 
-       SetDlgItemText (hWnd, RADIOBUTTON_GOTOMOVE_BLACK, LOCALIZE (L"Games_Black")); 
-       SetDlgItemText (hWnd, STATICTEXT_GOTOMOVE_STATUSBAR, LOCALIZE (L"GoToMove_StatusBar")); 
-   
-       // initialize the radio buttons 
-       Button_SetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_WHITE), (1 - the_board.viewed_move % 2 == COLOR_WHITE ? BST_CHECKED : BST_UNCHECKED)); 
-       Button_SetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_BLACK), (1 - the_board.viewed_move % 2 == COLOR_BLACK ? BST_CHECKED : BST_UNCHECKED)); 
-   
-       // convert the status bar message to a hyperlink 
-       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_GOTOMOVE_STATUSBAR)); 
-    } 
-   
-    // else did we click the close button on the title bar ? 
-    else if (message == WM_CLOSE) 
-       EndDialog (hWnd, 0); // close the dialog box 
-   
-    // else did we take action on one of the controls ? 
-    else if (message == WM_COMMAND) 
-    { 
-       // was it the OK button ? 
-       if (wParam_loword == BUTTON_OK) 
-       { 
-          // translate the wanted move number into a move array index 
-          wanted_move = PGNMOVENUMBER_TO_MOVEINDEX (GetDlgItemInt (hWnd, EDITBOX_GOTOMOVE, NULL, false), 
-                                                    (Button_GetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_BLACK)) == BST_CHECKED ? COLOR_BLACK : COLOR_WHITE)); 
-          EndDialog (hWnd, 1); // close the dialog box and return a success value 
-       } 
-   
-       // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) 
-       else if (wParam_loword == IDCANCEL) 
-          EndDialog (hWnd, 0); // close the dialog box 
-   
-       // else is it a radio button ? 
-       else if (wParam_loword == RADIOBUTTON_GOTOMOVE_WHITE) 
-          Button_SetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_BLACK), BST_UNCHECKED); 
-       else if (wParam_loword == RADIOBUTTON_GOTOMOVE_BLACK) 
-          Button_SetCheck (GetDlgItem (hWnd, RADIOBUTTON_GOTOMOVE_WHITE), BST_UNCHECKED); 
-   
-       // else was it the status bar hyperlink ? 
-       else if (wParam_loword == STATICTEXT_ENDGAME_STATUSBAR) 
-          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized 
-    } 
-   
-    // call the default dialog message processing function to keep things going 
-    return (false); 
- } 
-