Subversion Repositories Games.Chess Giants

Rev

Rev 74 | Rev 124 | 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
 
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;
53
 
54
   // destroy the font object we used
55
   DeleteObject (hFontBanner);
56
 
57
   return; // _endthread() implied
58
}
59
 
60
 
61
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
62
{
63
   // message handler for the dialog box
64
 
74 pmbaty 65
   static wchar_t temp_buffer[256];
14 pmbaty 66
 
1 pmbaty 67
   unsigned short wParam_hiword;
68
   unsigned short wParam_loword;
69
 
70
   // filter out the commonly used message values
71
   wParam_hiword = HIWORD (wParam);
72
   wParam_loword = LOWORD (wParam);
73
 
74
   // have we just fired up this window ?
75
   if (message == WM_INITDIALOG)
76
   {
77
      // center the window
78
      CenterWindow (hWnd, hMainWnd);
79
 
80
      // set dialog icons (small one for title bar & big one for task manager)
81
      SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
82
      SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
83
 
84
      // set window title and control texts
85
      SetWindowText (hWnd, LOCALIZE (L"AboutBox_Title"));
86
 
87
      // set the banner area font
88
      SendMessage (GetDlgItem (hWnd, STATICTEXT_BANNER), WM_SETFONT, (WPARAM) hFontBanner, false);
89
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_BANNER), PROGRAM_NAME);
90
 
74 pmbaty 91
      swprintf_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), L"version %c%c%c%c%s%c%c " PROGRAM_COPYRIGHT L" " AUTHOR_NAME L" - ",
92
                  __DATE__[7], __DATE__[8], __DATE__[9], __DATE__[10],
93
                  (strncmp (__DATE__, "Jan", 3) == 0 ? L"01" :
94
                   (strncmp (__DATE__, "Feb", 3) == 0 ? L"02" :
95
                    (strncmp (__DATE__, "Mar", 3) == 0 ? L"03" :
96
                     (strncmp (__DATE__, "Apr", 3) == 0 ? L"04" :
97
                      (strncmp (__DATE__, "May", 3) == 0 ? L"05" :
98
                       (strncmp (__DATE__, "Jun", 3) == 0 ? L"06" :
99
                        (strncmp (__DATE__, "Jul", 3) == 0 ? L"07" :
100
                         (strncmp (__DATE__, "Aug", 3) == 0 ? L"08" :
101
                          (strncmp (__DATE__, "Sep", 3) == 0 ? L"09" :
102
                           (strncmp (__DATE__, "Oct", 3) == 0 ? L"10" :
103
                            (strncmp (__DATE__, "Nov", 3) == 0 ? L"11" :
104
                             (strncmp (__DATE__, "Dec", 3) == 0 ? L"12" : L"??")))))))))))),
83 pmbaty 105
                  (__DATE__[4] == ' ' ? '0' : __DATE__[4]), __DATE__[5]);
74 pmbaty 106
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_PROGRAMVERSION), temp_buffer);
1 pmbaty 107
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL), AUTHOR_EMAIL);
108
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_1STPARAGRAPH), LOCALIZE (L"AboutBox_1stParagraph"));
109
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_2NDPARAGRAPH), LOCALIZE (L"AboutBox_2ndParagraph"));
110
      SetWindowText (GetDlgItem (hWnd, BUTTON_WEBSITE), LOCALIZE (L"AboutBox_VisitWebsite"));
111
 
14 pmbaty 112
      // build the "registered to:" message and display it
113
      if (is_registered)
74 pmbaty 114
         swprintf_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), LOCALIZE (L"Registration_RegisteredTo"), options.registration.user_email);
14 pmbaty 115
      else
74 pmbaty 116
         wcscpy_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), LOCALIZE (L"Registration_Unregistered"));
117
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTEREDTO), temp_buffer);
14 pmbaty 118
 
1 pmbaty 119
      // convert the bitmaps to clickable things
120
      ConvertStaticToHyperlink (GetDlgItem (hWnd, BITMAP_ABOUT));
121
      ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL));
122
   }
123
 
124
   // else did we click the close button on the title bar ?
125
   else if (message == WM_CLOSE)
126
      EndDialog (hWnd, 0); // close the dialog box
127
 
128
   // else did we take action on one of the controls ?
129
   else if (message == WM_COMMAND)
130
   {
131
      // was it the website button ?
132
      if (wParam_loword == BUTTON_WEBSITE)
133
      {
134
         ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the website in the default browser, maximized
135
         EndDialog (hWnd, 0); // close the dialog box
136
      }
137
 
138
      // else was it the author's email ?
139
      else if (wParam_loword == STATICTEXT_AUTHOREMAIL)
140
         ShellExecute (NULL, L"open", L"mailto:" AUTHOR_EMAIL, NULL, NULL, SW_MAXIMIZE); // fire up the mail client
141
 
142
      // else was it the picture ? change the picture and display our face instead :p
143
      else if (wParam_loword == BITMAP_ABOUT)
144
      {
145
         is_authordisplayed ^= true; // alternate author display with about display picture
146
         SendMessage (GetDlgItem (hWnd, BITMAP_ABOUT), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) LoadBitmap (hAppInstance, MAKEINTRESOURCE (is_authordisplayed ? BITMAP_AUTHOR : BITMAP_ABOUT)));
147
      }
148
 
149
      // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
150
      else if (wParam_loword == IDCANCEL)
151
         EndDialog (hWnd, 0); // close the dialog box
152
   }
153
 
154
   // call the default dialog message processing function to keep things going
155
   return (false);
156
}