Subversion Repositories Games.Chess Giants

Rev

Rev 1 | Rev 107 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 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
   return; // _endthread() implied
46
}
47
 
48
 
49
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
50
{
51
   // message handler for the dialog box
52
 
53
   unsigned short wParam_hiword;
54
   unsigned short wParam_loword;
55
 
56
   // filter out the commonly used message values
57
   wParam_hiword = HIWORD (wParam);
58
   wParam_loword = LOWORD (wParam);
59
 
60
   // have we just fired up this window ?
61
   if (message == WM_INITDIALOG)
62
   {
63
      // center the window
64
      CenterWindow (hWnd, hMainWnd);
65
 
66
      // set dialog icons (small one for title bar & big one for task manager)
67
      SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
68
      SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
69
 
70
      // set window title and control texts
71
      SetWindowText (hWnd, LOCALIZE (L"EndGame_Title"));
72
      SetWindowText (GetDlgItem (hWnd, BUTTON_OK), LOCALIZE (L"Button_OK"));
73
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_ENDGAME_STATUSBAR), LOCALIZE (L"EndGame_StatusBar"));
74
 
75
      // set the right message
76
      if (the_board.game_state == STATE_WHITEWIN_CHECKMATE)
77
      {
78
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_CheckMate"));
79
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_WhiteWins"));
80
      }
81
      else if (the_board.game_state == STATE_BLACKWIN_CHECKMATE)
82
      {
83
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_CheckMate"));
84
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_BlackWins"));
85
      }
86
      else if (the_board.game_state == STATE_WHITEWIN_RESIGNORFORFEIT)
87
      {
88
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Resign"));
89
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_WhiteWins"));
90
      }
91
      else if (the_board.game_state == STATE_BLACKWIN_RESIGNORFORFEIT)
92
      {
93
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Resign"));
94
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_BlackWins"));
95
      }
96
      else if (the_board.game_state == STATE_DRAW_STALEMATE)
97
      {
98
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_StaleMate"));
99
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame"));
100
      }
101
      else if (the_board.game_state == STATE_DRAW_AGREEMENT)
102
      {
103
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Agreement"));
104
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame"));
105
      }
106
      else if (the_board.game_state == STATE_DRAW_OTHER)
107
      {
86 pmbaty 108
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_DrawGame")); // TODO: display something better
1 pmbaty 109
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), LOCALIZE (L"EndGame_DrawGame"));
110
      }
111
      else if (the_board.game_state == STATE_ADJOURNED)
112
      {
113
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAW), LOCALIZE (L"EndGame_Adjourned"));
114
         Static_SetText (GetDlgItem (hWnd, STATICTEXT_WINLOSSORDRAWCOMMENT), L"");
115
      }
116
 
117
      // convert the status bar message to a hyperlink
118
      ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_ENDGAME_STATUSBAR));
119
   }
120
 
121
   // else did we click the close button on the title bar ?
122
   else if (message == WM_CLOSE)
123
      EndDialog (hWnd, 0); // close the dialog box
124
 
125
   // else did we take action on one of the controls ?
126
   else if (message == WM_COMMAND)
127
   {
128
      // was it the OK button ?
129
      if (wParam_loword == BUTTON_OK)
130
         EndDialog (hWnd, 1); // close the dialog box and return OK
131
 
132
      // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
133
      else if (wParam_loword == IDCANCEL)
134
         EndDialog (hWnd, 0); // close the dialog box
135
 
136
      // else was it the status bar hyperlink ?
137
      else if (wParam_loword == STATICTEXT_ENDGAME_STATUSBAR)
138
         ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
139
   }
140
 
141
   // call the default dialog message processing function to keep things going
142
   return (false);
143
}