Rev 186 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | // dialog_about.cpp |
2 | |||
3 | #include "../common.h" |
||
4 | |||
5 | |||
6 | // dialog template |
||
7 | #define THIS_DIALOG DIALOG_ABOUT |
||
8 | |||
9 | |||
10 | // global variables used in this module only |
||
11 | static HFONT hFontBanner; |
||
12 | |||
13 | |||
14 | // prototypes of local functions |
||
15 | static void StartThread_ThisDialog (void *thread_parms); |
||
16 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
17 | |||
18 | |||
19 | void DialogBox_About (void) |
||
20 | { |
||
21 | // helper function to fire up the modeless dialog box |
||
22 | |||
140 | pmbaty | 23 | is_dialogbox_displayed = true; |
1 | pmbaty | 24 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one |
25 | |||
26 | return; // return as soon as the thread is fired up |
||
27 | } |
||
28 | |||
29 | |||
30 | void DialogBox_About_Validated (void) |
||
31 | { |
||
32 | // callback function called by the main game thread when the dialog box is validated |
||
33 | |||
34 | // remember this callback is no longer to be called |
||
35 | is_dialogbox_about_validated = false; |
||
36 | |||
37 | return; // finished |
||
38 | } |
||
39 | |||
40 | |||
41 | static void StartThread_ThisDialog (void *thread_parms) |
||
42 | { |
||
43 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
44 | // to implement a non-modal message box using the Common Controls library. |
||
45 | |||
46 | // create the banner font |
||
47 | hFontBanner = CreateFont (42, 0, 0, 0, FW_DONTCARE, true, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, |
||
48 | CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Papyrus"); |
||
49 | |||
50 | // display the dialog box |
||
51 | if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1) |
||
52 | is_dialogbox_about_validated = true; |
||
140 | pmbaty | 53 | is_dialogbox_displayed = false; |
1 | pmbaty | 54 | |
55 | // destroy the font object we used |
||
56 | DeleteObject (hFontBanner); |
||
57 | |||
124 | pmbaty | 58 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
1 | pmbaty | 59 | return; // _endthread() implied |
60 | } |
||
61 | |||
62 | |||
63 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
64 | { |
||
65 | // message handler for the dialog box |
||
66 | |||
74 | pmbaty | 67 | static wchar_t temp_buffer[256]; |
186 | pmbaty | 68 | static wchar_t wide_version[32]; |
69 | static char version[32]; |
||
14 | pmbaty | 70 | |
1 | pmbaty | 71 | unsigned short wParam_hiword; |
72 | unsigned short wParam_loword; |
||
73 | |||
74 | // filter out the commonly used message values |
||
75 | wParam_hiword = HIWORD (wParam); |
||
76 | wParam_loword = LOWORD (wParam); |
||
77 | |||
78 | // have we just fired up this window ? |
||
79 | if (message == WM_INITDIALOG) |
||
80 | { |
||
81 | // center the window |
||
82 | CenterWindow (hWnd, hMainWnd); |
||
83 | |||
84 | // set dialog icons (small one for title bar & big one for task manager) |
||
85 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
86 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
87 | |||
88 | // set window title and control texts |
||
89 | SetWindowText (hWnd, LOCALIZE (L"AboutBox_Title")); |
||
90 | |||
91 | // set the banner area font |
||
92 | SendMessage (GetDlgItem (hWnd, STATICTEXT_BANNER), WM_SETFONT, (WPARAM) hFontBanner, false); |
||
93 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_BANNER), PROGRAM_NAME); |
||
94 | |||
186 | pmbaty | 95 | GenerateVersionNumber (version, sizeof (version)); |
96 | ConvertToWideChar (wide_version, WCHAR_SIZEOF (wide_version), version); |
||
97 | swprintf_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), L"version %s © 2010-%.4s Pierre-Marie Baty - ", wide_version, wide_version); |
||
74 | pmbaty | 98 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_PROGRAMVERSION), temp_buffer); |
1 | pmbaty | 99 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL), AUTHOR_EMAIL); |
100 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_1STPARAGRAPH), LOCALIZE (L"AboutBox_1stParagraph")); |
||
101 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_2NDPARAGRAPH), LOCALIZE (L"AboutBox_2ndParagraph")); |
||
102 | SetWindowText (GetDlgItem (hWnd, BUTTON_WEBSITE), LOCALIZE (L"AboutBox_VisitWebsite")); |
||
103 | |||
194 | pmbaty | 104 | #ifndef NO_REGISTRATION |
14 | pmbaty | 105 | // build the "registered to:" message and display it |
106 | if (is_registered) |
||
74 | pmbaty | 107 | swprintf_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), LOCALIZE (L"Registration_RegisteredTo"), options.registration.user_email); |
14 | pmbaty | 108 | else |
74 | pmbaty | 109 | wcscpy_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), LOCALIZE (L"Registration_Unregistered")); |
110 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTEREDTO), temp_buffer); |
||
194 | pmbaty | 111 | #else // NO_REGISTRATION |
112 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTEREDTO), L""); |
||
113 | #endif // !NO_REGISTRATION |
||
14 | pmbaty | 114 | |
147 | pmbaty | 115 | // convert the author's email to something clickable |
1 | pmbaty | 116 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL)); |
117 | } |
||
118 | |||
119 | // else did we click the close button on the title bar ? |
||
120 | else if (message == WM_CLOSE) |
||
121 | EndDialog (hWnd, 0); // close the dialog box |
||
122 | |||
123 | // else did we take action on one of the controls ? |
||
124 | else if (message == WM_COMMAND) |
||
125 | { |
||
126 | // was it the website button ? |
||
127 | if (wParam_loword == BUTTON_WEBSITE) |
||
128 | { |
||
129 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the website in the default browser, maximized |
||
130 | EndDialog (hWnd, 0); // close the dialog box |
||
131 | } |
||
132 | |||
133 | // else was it the author's email ? |
||
134 | else if (wParam_loword == STATICTEXT_AUTHOREMAIL) |
||
135 | ShellExecute (NULL, L"open", L"mailto:" AUTHOR_EMAIL, NULL, NULL, SW_MAXIMIZE); // fire up the mail client |
||
136 | |||
137 | // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
138 | else if (wParam_loword == IDCANCEL) |
||
139 | EndDialog (hWnd, 0); // close the dialog box |
||
140 | } |
||
141 | |||
142 | // call the default dialog message processing function to keep things going |
||
143 | return (false); |
||
144 | } |