Rev 75 | Go to most recent revision | Details | Compare with Previous | 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 | |||
124 | pmbaty | 55 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
75 | pmbaty | 56 | return; // _endthread() implied |
57 | } |
||
58 | |||
59 | |||
60 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
61 | { |
||
62 | unsigned short wParam_hiword; |
||
63 | unsigned short wParam_loword; |
||
64 | |||
65 | // filter out the commonly used message values |
||
66 | wParam_hiword = HIWORD (wParam); |
||
67 | wParam_loword = LOWORD (wParam); |
||
68 | |||
69 | // have we just fired up this window ? |
||
70 | if (message == WM_INITDIALOG) |
||
71 | { |
||
72 | // center the window |
||
73 | CenterWindow (hWnd, hMainWnd); |
||
74 | |||
75 | // set dialog icons (small one for title bar & big one for task manager) |
||
76 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
77 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
78 | |||
79 | // set window title and control texts |
||
80 | SetWindowText (hWnd, LOCALIZE (L"Menu_ChessboardRenameSides")); |
||
81 | SetDlgItemText (hWnd, BUTTON_OK, LOCALIZE (L"Button_OK")); |
||
82 | SetDlgItemText (hWnd, STATICTEXT_RENAMESIDES_STATUSBAR, LOCALIZE (L"GoToMove_StatusBar")); |
||
83 | |||
84 | // set the player's names |
||
85 | SetDlgItemText (hWnd, EDITBOX_BLACKNAME, the_board.players[COLOR_BLACK].name); // get black player name |
||
86 | SetDlgItemText (hWnd, EDITBOX_WHITENAME, the_board.players[COLOR_WHITE].name); // get white player name |
||
87 | |||
88 | // convert the status bar message to a hyperlink |
||
89 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_RENAMESIDES_STATUSBAR)); |
||
90 | } |
||
91 | |||
92 | // else did we take action on one of the controls ? |
||
93 | else if (message == WM_COMMAND) |
||
94 | { |
||
95 | // was it the OK button ? |
||
96 | if (wParam_loword == BUTTON_OK) |
||
97 | { |
||
98 | GetDlgItemText (hWnd, EDITBOX_BLACKNAME, black_name, WCHAR_SIZEOF (black_name)); // get black player name |
||
99 | GetDlgItemText (hWnd, EDITBOX_WHITENAME, white_name, WCHAR_SIZEOF (white_name)); // get white player name |
||
100 | |||
101 | EndDialog (hWnd, 1); // close the dialog box and return OK |
||
102 | } |
||
103 | |||
104 | // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
105 | else if (wParam_loword == IDCANCEL) |
||
106 | EndDialog (hWnd, 0); // close the dialog box |
||
107 | |||
108 | // else was it the status bar hyperlink ? |
||
109 | else if (wParam_loword == STATICTEXT_RENAMESIDES_STATUSBAR) |
||
110 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
111 | } |
||
112 | |||
113 | // call the default dialog message processing function to keep things going |
||
114 | return (false); |
||
115 | } |