- // dialog_pawnpromotion.cpp 
-   
- #include "../common.h" 
-   
-   
- // dialog template 
- #define THIS_DIALOG DIALOG_PAWNPROMOTION 
-   
-   
- // global variables used in this module only 
- static int promotion_type = PART_NONE; 
-   
-   
- // 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_PawnPromotion (void) 
- { 
-    // helper function to fire up the modeless dialog box 
-   
-    is_dialogbox_displayed = true; 
-    _beginthread (StartThread_ThisDialog, 0, NULL); // so fire up a new one 
-   
-    return; // return as soon as the thread is fired up 
- } 
-   
-   
- void DialogBox_PawnPromotion_Validated (void) 
- { 
-    // callback function called by the main game thread when the dialog box is validated 
-   
-    boardmove_t *currentmove; 
-    player_t *opposite_player; 
-   
-    // remember this callback is no longer to be called 
-    is_dialogbox_pawnpromotion_validated = false; 
-   
-    currentmove = &the_board.moves[the_board.move_count - 1]; // quick access to previous move 
-   
-    // save promotion type and promote the part to the desired type 
-    currentmove->promotion_type = promotion_type; 
-    Move_SetSlot (currentmove, currentmove->target[0], currentmove->target[1], currentmove->color, currentmove->promotion_type); 
-   
-    // evaluate new check and stalemate status 
-    currentmove->is_check = Move_IsCheck (currentmove, 1 - currentmove->color); // save whether opponent is in check or not 
-    currentmove->is_stalemate = Move_IsStaleMate (currentmove, 1 - currentmove->color); // save whether opponent is stalemate 
-   
-    // re-describe our move in Standard Abbreviated Notation and describe the resulting table in Forsyth-Edwards Notation 
-    Move_DescribeInSAN (currentmove, &the_board.moves[the_board.move_count - 2], currentmove->pgntext, WCHAR_SIZEOF (currentmove->pgntext), false); // don't use the localized part abbreviations); 
-    Move_DescribeInFEN (currentmove); 
-   
-    // forget the hovered and selected positions 
-    Board_SetSelectedAndHovered (&the_board, -1, -1, -1, -1); 
-   
-    // pawn promotions are a special case. When the dialog is displayed, the move has ALREADY been done. So we must 
-    // not warn the OPPOSITE player of the current move, but the CURRENT player of the current move. 
-    opposite_player = Player_GetCurrent (); 
-    opposite_player->should_wakeup = true; // tell the opposite player to wake up 
-   
-    the_board.reevaluate = true; // evaluate the new board 
-    the_scene.update = true; // and redraw the scene 
-   
-    return; // finished, pawn has been promoted to the desired part type 
- } 
-   
-   
- 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 
-    promotion_type = DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog); 
-    if (promotion_type > 0) 
-       is_dialogbox_pawnpromotion_validated = true; 
-    is_dialogbox_displayed = false; 
-   
-    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"PawnPromotion_Title")); 
-       Static_SetText (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_QUESTION), LOCALIZE (L"PawnPromotion_Question")); 
-       Static_SetText (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_STATUSBAR), LOCALIZE (L"PawnPromotion_StatusBar")); 
-   
-       // convert the bitmaps to clickable things 
-       ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_ROOK)); 
-       ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_KNIGHT)); 
-       ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_BISHOP)); 
-       ConvertStaticToHyperlink (GetDlgItem (hWnd, BUTTON_QUEEN)); 
-   
-       // convert the status bar message to a hyperlink 
-       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_PAWNPROMOTION_STATUSBAR)); 
-    } 
-   
-    // else did we take action on one of the controls ? 
-    else if (message == WM_COMMAND) 
-    { 
-       // was it the "rook" button ? 
-       if (wParam_loword == BUTTON_ROOK) 
-          EndDialog (hWnd, PART_ROOK); // close the dialog box and return a "promote to rook" value 
-   
-       // else was it the "knight" button ? 
-       else if (wParam_loword == BUTTON_KNIGHT) 
-          EndDialog (hWnd, PART_KNIGHT); // close the dialog box and return a "promote to knight" value 
-   
-       // else was it the "bishop" button ? 
-       else if (wParam_loword == BUTTON_BISHOP) 
-          EndDialog (hWnd, PART_BISHOP); // close the dialog box and return a "promote to bishop" value 
-   
-       // else was it the "queen" button ? 
-       else if (wParam_loword == BUTTON_QUEEN) 
-          EndDialog (hWnd, PART_QUEEN); // close the dialog box and return a "promote to queen" value 
-   
-       // else was it the status bar hyperlink ? 
-       else if (wParam_loword == STATICTEXT_PAWNPROMOTION_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); 
- } 
-