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