// dialog_about.cpp
 
 
 
#include "../common.h"
 
 
 
 
 
// dialog template
 
#define THIS_DIALOG DIALOG_ABOUT
 
 
 
 
 
// global variables used in this module only
 
static bool is_authordisplayed = false;
 
static HFONT hFontBanner;
 
 
 
 
 
// prototypes of local functions
 
static void StartThread_ThisDialog (void *thread_parms);
 
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam);
 
 
 
 
 
void DialogBox_About (void)
 
{
 
   // helper function to fire up the modeless dialog box
 
 
 
   _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one
 
 
 
   return; // return as soon as the thread is fired up
 
}
 
 
 
 
 
void DialogBox_About_Validated (void)
 
{
 
   // callback function called by the main game thread when the dialog box is validated
 
 
 
   // remember this callback is no longer to be called
 
   is_dialogbox_about_validated = false;
 
 
 
   return; // finished
 
}
 
 
 
 
 
static void StartThread_ThisDialog (void *thread_parms)
 
{
 
   // this function runs in a separate thread, for that's the only way (seemingly)
 
   // to implement a non-modal message box using the Common Controls library.
 
 
 
   // create the banner font
 
   hFontBanner = CreateFont (42, 0, 0, 0, FW_DONTCARE, true, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
 
                             CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Papyrus");
 
 
 
   // display the dialog box
 
   if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
 
      is_dialogbox_about_validated = true;
 
 
 
   // destroy the font object we used
 
   DeleteObject (hFontBanner);
 
 
 
   return; // _endthread() implied
 
}
 
 
 
 
 
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
 
{
 
   // message handler for the dialog box
 
 
 
   static wchar_t temp_buffer[256];
 
 
 
   unsigned short wParam_hiword;
 
   unsigned short wParam_loword;
 
 
 
   // filter out the commonly used message values
 
   wParam_hiword = HIWORD (wParam);
 
   wParam_loword = LOWORD (wParam);
 
 
 
   // have we just fired up this window ?
 
   if (message == WM_INITDIALOG)
 
   {
 
      // center the window
 
      CenterWindow (hWnd, hMainWnd);
 
 
 
      // set dialog icons (small one for title bar & big one for task manager)
 
      SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
 
      SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
 
 
 
      // set window title and control texts
 
      SetWindowText (hWnd, LOCALIZE (L"AboutBox_Title"));
 
 
 
      // set the banner area font
 
      SendMessage (GetDlgItem (hWnd, STATICTEXT_BANNER), WM_SETFONT, (WPARAM) hFontBanner, false);
 
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_BANNER), PROGRAM_NAME);
 
 
 
      swprintf_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), L"version %c%c%c%c%s%c%c " PROGRAM_COPYRIGHT L" " AUTHOR_NAME L" - ",
 
                  __DATE__[7], __DATE__[8], __DATE__[9], __DATE__[10],
 
                  (strncmp (__DATE__, "Jan", 3) == 0 ? L"01" :
 
                   (strncmp (__DATE__, "Feb", 3) == 0 ? L"02" :
 
                    (strncmp (__DATE__, "Mar", 3) == 0 ? L"03" :
 
                     (strncmp (__DATE__, "Apr", 3) == 0 ? L"04" :
 
                      (strncmp (__DATE__, "May", 3) == 0 ? L"05" :
 
                       (strncmp (__DATE__, "Jun", 3) == 0 ? L"06" :
 
                        (strncmp (__DATE__, "Jul", 3) == 0 ? L"07" :
 
                         (strncmp (__DATE__, "Aug", 3) == 0 ? L"08" :
 
                          (strncmp (__DATE__, "Sep", 3) == 0 ? L"09" :
 
                           (strncmp (__DATE__, "Oct", 3) == 0 ? L"10" :
 
                            (strncmp (__DATE__, "Nov", 3) == 0 ? L"11" :
 
                             (strncmp (__DATE__, "Dec", 3) == 0 ? L"12" : L"??")))))))))))),
 
                  __DATE__[4], __DATE__[5]);
 
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_PROGRAMVERSION), temp_buffer);
 
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL), AUTHOR_EMAIL);
 
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_1STPARAGRAPH), LOCALIZE (L"AboutBox_1stParagraph"));
 
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_2NDPARAGRAPH), LOCALIZE (L"AboutBox_2ndParagraph"));
 
      SetWindowText (GetDlgItem (hWnd, BUTTON_WEBSITE), LOCALIZE (L"AboutBox_VisitWebsite"));
 
 
 
      // build the "registered to:" message and display it
 
      if (is_registered)
 
         swprintf_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), LOCALIZE (L"Registration_RegisteredTo"), options.registration.user_email);
 
      else
 
         wcscpy_s (temp_buffer, WCHAR_SIZEOF (temp_buffer), LOCALIZE (L"Registration_Unregistered"));
 
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTEREDTO), temp_buffer);
 
 
 
      // convert the bitmaps to clickable things
 
      ConvertStaticToHyperlink (GetDlgItem (hWnd, BITMAP_ABOUT));
 
      ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL));
 
   }
 
 
 
   // else did we click the close button on the title bar ?
 
   else if (message == WM_CLOSE)
 
      EndDialog (hWnd, 0); // close the dialog box
 
 
 
   // else did we take action on one of the controls ?
 
   else if (message == WM_COMMAND)
 
   {
 
      // was it the website button ?
 
      if (wParam_loword == BUTTON_WEBSITE)
 
      {
 
         ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the website in the default browser, maximized
 
         EndDialog (hWnd, 0); // close the dialog box
 
      }
 
 
 
      // else was it the author's email ?
 
      else if (wParam_loword == STATICTEXT_AUTHOREMAIL)
 
         ShellExecute (NULL, L"open", L"mailto:" AUTHOR_EMAIL, NULL, NULL, SW_MAXIMIZE); // fire up the mail client
 
 
 
      // else was it the picture ? change the picture and display our face instead :p
 
      else if (wParam_loword == BITMAP_ABOUT)
 
      {
 
         is_authordisplayed ^= true; // alternate author display with about display picture
 
         SendMessage (GetDlgItem (hWnd, BITMAP_ABOUT), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) LoadBitmap (hAppInstance, MAKEINTRESOURCE (is_authordisplayed ? BITMAP_AUTHOR : BITMAP_ABOUT)));
 
      }
 
 
 
      // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
 
      else if (wParam_loword == IDCANCEL)
 
         EndDialog (hWnd, 0); // close the dialog box
 
   }
 
 
 
   // call the default dialog message processing function to keep things going
 
   return (false);
 
}