Rev 124 | Rev 147 | Go to most recent revision | 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 bool is_authordisplayed = false; |
||
12 | static HFONT hFontBanner; |
||
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_About (void) |
||
21 | { |
||
22 | // helper function to fire up the modeless dialog box |
||
23 | |||
140 | pmbaty | 24 | is_dialogbox_displayed = true; |
1 | pmbaty | 25 | _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one |
26 | |||
27 | return; // return as soon as the thread is fired up |
||
28 | } |
||
29 | |||
30 | |||
31 | void DialogBox_About_Validated (void) |
||
32 | { |
||
33 | // callback function called by the main game thread when the dialog box is validated |
||
34 | |||
35 | // remember this callback is no longer to be called |
||
36 | is_dialogbox_about_validated = false; |
||
37 | |||
38 | return; // finished |
||
39 | } |
||
40 | |||
41 | |||
42 | static void StartThread_ThisDialog (void *thread_parms) |
||
43 | { |
||
44 | // this function runs in a separate thread, for that's the only way (seemingly) |
||
45 | // to implement a non-modal message box using the Common Controls library. |
||
46 | |||
47 | // create the banner font |
||
48 | hFontBanner = CreateFont (42, 0, 0, 0, FW_DONTCARE, true, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, |
||
49 | CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Papyrus"); |
||
50 | |||
51 | // display the dialog box |
||
52 | if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1) |
||
53 | is_dialogbox_about_validated = true; |
||
140 | pmbaty | 54 | is_dialogbox_displayed = false; |
1 | pmbaty | 55 | |
56 | // destroy the font object we used |
||
57 | DeleteObject (hFontBanner); |
||
58 | |||
124 | pmbaty | 59 | the_board.reevaluate = true; // refresh the GUI buttons if needed |
1 | pmbaty | 60 | return; // _endthread() implied |
61 | } |
||
62 | |||
63 | |||
64 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
65 | { |
||
66 | // message handler for the dialog box |
||
67 | |||
74 | pmbaty | 68 | static wchar_t temp_buffer[256]; |
14 | pmbaty | 69 | |
1 | pmbaty | 70 | unsigned short wParam_hiword; |
71 | unsigned short wParam_loword; |
||
72 | |||
73 | // filter out the commonly used message values |
||
74 | wParam_hiword = HIWORD (wParam); |
||
75 | wParam_loword = LOWORD (wParam); |
||
76 | |||
77 | // have we just fired up this window ? |
||
78 | if (message == WM_INITDIALOG) |
||
79 | { |
||
80 | // center the window |
||
81 | CenterWindow (hWnd, hMainWnd); |
||
82 | |||
83 | // set dialog icons (small one for title bar & big one for task manager) |
||
84 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
85 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
86 | |||
87 | // set window title and control texts |
||
88 | SetWindowText (hWnd, LOCALIZE (L"AboutBox_Title")); |
||
89 | |||
90 | // set the banner area font |
||
91 | SendMessage (GetDlgItem (hWnd, STATICTEXT_BANNER), WM_SETFONT, (WPARAM) hFontBanner, false); |
||
92 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_BANNER), PROGRAM_NAME); |
||
93 | |||
74 | pmbaty | 94 | swprintf_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), L"version %c%c%c%c%s%c%c " PROGRAM_COPYRIGHT L" " AUTHOR_NAME L" - ", |
95 | __DATE__[7], __DATE__[8], __DATE__[9], __DATE__[10], |
||
96 | (strncmp (__DATE__, "Jan", 3) == 0 ? L"01" : |
||
97 | (strncmp (__DATE__, "Feb", 3) == 0 ? L"02" : |
||
98 | (strncmp (__DATE__, "Mar", 3) == 0 ? L"03" : |
||
99 | (strncmp (__DATE__, "Apr", 3) == 0 ? L"04" : |
||
100 | (strncmp (__DATE__, "May", 3) == 0 ? L"05" : |
||
101 | (strncmp (__DATE__, "Jun", 3) == 0 ? L"06" : |
||
102 | (strncmp (__DATE__, "Jul", 3) == 0 ? L"07" : |
||
103 | (strncmp (__DATE__, "Aug", 3) == 0 ? L"08" : |
||
104 | (strncmp (__DATE__, "Sep", 3) == 0 ? L"09" : |
||
105 | (strncmp (__DATE__, "Oct", 3) == 0 ? L"10" : |
||
106 | (strncmp (__DATE__, "Nov", 3) == 0 ? L"11" : |
||
107 | (strncmp (__DATE__, "Dec", 3) == 0 ? L"12" : L"??")))))))))))), |
||
83 | pmbaty | 108 | (__DATE__[4] == ' ' ? '0' : __DATE__[4]), __DATE__[5]); |
74 | pmbaty | 109 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_PROGRAMVERSION), temp_buffer); |
1 | pmbaty | 110 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL), AUTHOR_EMAIL); |
111 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_1STPARAGRAPH), LOCALIZE (L"AboutBox_1stParagraph")); |
||
112 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_2NDPARAGRAPH), LOCALIZE (L"AboutBox_2ndParagraph")); |
||
113 | SetWindowText (GetDlgItem (hWnd, BUTTON_WEBSITE), LOCALIZE (L"AboutBox_VisitWebsite")); |
||
114 | |||
14 | pmbaty | 115 | // build the "registered to:" message and display it |
116 | if (is_registered) |
||
74 | pmbaty | 117 | swprintf_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), LOCALIZE (L"Registration_RegisteredTo"), options.registration.user_email); |
14 | pmbaty | 118 | else |
74 | pmbaty | 119 | wcscpy_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), LOCALIZE (L"Registration_Unregistered")); |
120 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTEREDTO), temp_buffer); |
||
14 | pmbaty | 121 | |
1 | pmbaty | 122 | // convert the bitmaps to clickable things |
123 | ConvertStaticToHyperlink (GetDlgItem (hWnd, BITMAP_ABOUT)); |
||
124 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL)); |
||
125 | } |
||
126 | |||
127 | // else did we click the close button on the title bar ? |
||
128 | else if (message == WM_CLOSE) |
||
129 | EndDialog (hWnd, 0); // close the dialog box |
||
130 | |||
131 | // else did we take action on one of the controls ? |
||
132 | else if (message == WM_COMMAND) |
||
133 | { |
||
134 | // was it the website button ? |
||
135 | if (wParam_loword == BUTTON_WEBSITE) |
||
136 | { |
||
137 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the website in the default browser, maximized |
||
138 | EndDialog (hWnd, 0); // close the dialog box |
||
139 | } |
||
140 | |||
141 | // else was it the author's email ? |
||
142 | else if (wParam_loword == STATICTEXT_AUTHOREMAIL) |
||
143 | ShellExecute (NULL, L"open", L"mailto:" AUTHOR_EMAIL, NULL, NULL, SW_MAXIMIZE); // fire up the mail client |
||
144 | |||
145 | // else was it the picture ? change the picture and display our face instead :p |
||
146 | else if (wParam_loword == BITMAP_ABOUT) |
||
147 | { |
||
148 | is_authordisplayed ^= true; // alternate author display with about display picture |
||
149 | SendMessage (GetDlgItem (hWnd, BITMAP_ABOUT), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) LoadBitmap (hAppInstance, MAKEINTRESOURCE (is_authordisplayed ? BITMAP_AUTHOR : BITMAP_ABOUT))); |
||
150 | } |
||
151 | |||
152 | // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
153 | else if (wParam_loword == IDCANCEL) |
||
154 | EndDialog (hWnd, 0); // close the dialog box |
||
155 | } |
||
156 | |||
157 | // call the default dialog message processing function to keep things going |
||
158 | return (false); |
||
159 | } |