Subversion Repositories Games.Chess Giants

Rev

Rev 14 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.  
  65.    unsigned short wParam_hiword;
  66.    unsigned short wParam_loword;
  67.  
  68.    // filter out the commonly used message values
  69.    wParam_hiword = HIWORD (wParam);
  70.    wParam_loword = LOWORD (wParam);
  71.  
  72.    // have we just fired up this window ?
  73.    if (message == WM_INITDIALOG)
  74.    {
  75.       // center the window
  76.       CenterWindow (hWnd, hMainWnd);
  77.  
  78.       // set dialog icons (small one for title bar & big one for task manager)
  79.       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  80.       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
  81.  
  82.       // set window title and control texts
  83.       SetWindowText (hWnd, LOCALIZE (L"AboutBox_Title"));
  84.  
  85.       // set the banner area font
  86.       SendMessage (GetDlgItem (hWnd, STATICTEXT_BANNER), WM_SETFONT, (WPARAM) hFontBanner, false);
  87.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_BANNER), PROGRAM_NAME);
  88.  
  89.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_PROGRAMVERSION), L"version " PROGRAM_VERSION L" " PROGRAM_COPYRIGHT L" " AUTHOR_NAME L" - ");
  90.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL), AUTHOR_EMAIL);
  91.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_1STPARAGRAPH), LOCALIZE (L"AboutBox_1stParagraph"));
  92.       Static_SetText (GetDlgItem (hWnd, STATICTEXT_ABOUTBOX_2NDPARAGRAPH), LOCALIZE (L"AboutBox_2ndParagraph"));
  93.       SetWindowText (GetDlgItem (hWnd, BUTTON_WEBSITE), LOCALIZE (L"AboutBox_VisitWebsite"));
  94.  
  95.       // convert the bitmaps to clickable things
  96.       ConvertStaticToHyperlink (GetDlgItem (hWnd, BITMAP_ABOUT));
  97.       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_AUTHOREMAIL));
  98.    }
  99.  
  100.    // else did we click the close button on the title bar ?
  101.    else if (message == WM_CLOSE)
  102.       EndDialog (hWnd, 0); // close the dialog box
  103.  
  104.    // else did we take action on one of the controls ?
  105.    else if (message == WM_COMMAND)
  106.    {
  107.       // was it the website button ?
  108.       if (wParam_loword == BUTTON_WEBSITE)
  109.       {
  110.          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the website in the default browser, maximized
  111.          EndDialog (hWnd, 0); // close the dialog box
  112.       }
  113.  
  114.       // else was it the author's email ?
  115.       else if (wParam_loword == STATICTEXT_AUTHOREMAIL)
  116.          ShellExecute (NULL, L"open", L"mailto:" AUTHOR_EMAIL, NULL, NULL, SW_MAXIMIZE); // fire up the mail client
  117.  
  118.       // else was it the picture ? change the picture and display our face instead :p
  119.       else if (wParam_loword == BITMAP_ABOUT)
  120.       {
  121.          is_authordisplayed ^= true; // alternate author display with about display picture
  122.          SendMessage (GetDlgItem (hWnd, BITMAP_ABOUT), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) LoadBitmap (hAppInstance, MAKEINTRESOURCE (is_authordisplayed ? BITMAP_AUTHOR : BITMAP_ABOUT)));
  123.       }
  124.  
  125.       // else did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
  126.       else if (wParam_loword == IDCANCEL)
  127.          EndDialog (hWnd, 0); // close the dialog box
  128.    }
  129.  
  130.    // call the default dialog message processing function to keep things going
  131.    return (false);
  132. }
  133.