Subversion Repositories Games.Chess Giants

Rev

Rev 19 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
// dialog_quit.cpp
2
 
3
#include "../common.h"
4
 
5
 
6
// dialog template
7
#define THIS_DIALOG DIALOG_QUIT
8
 
9
 
10
// prototypes of local functions
11
static void StartThread_ThisDialog (void *thread_parms);
12
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam);
13
 
14
 
15
void DialogBox_Quit (void)
16
{
17
   // helper function to fire up the modeless dialog box
18
 
19
   _beginthread (StartThread_ThisDialog, 0, NULL); // fire up a new one
20
 
21
   return; // return as soon as the thread is fired up
22
}
23
 
24
 
25
void DialogBox_Quit_Validated (void)
26
{
27
   // callback function called by the main game thread when the dialog box is validated
28
 
29
   // remember this callback is no longer to be called
30
   is_dialogbox_quit_validated = false;
31
 
32
   // destroy the main window, which in turn will raise the "terminate_everything" global flag
33
   DestroyWindow (hMainWnd);
34
 
35
   return; // finished, we're now quitting the program
36
}
37
 
38
 
39
static void StartThread_ThisDialog (void *thread_parms)
40
{
41
   // this function runs in a separate thread, for that's the only way (seemingly)
42
   // to implement a non-modal message box using the Common Controls library.
43
 
44
   // display the dialog box
45
   if (DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), hMainWnd, DialogProc_ThisDialog) == 1)
46
      is_dialogbox_quit_validated = true;
47
 
48
   return; // _endthread() implied
49
}
50
 
51
 
52
static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam)
53
{
54
   // message handler for the dialog box
55
 
56
   unsigned short wParam_hiword;
57
   unsigned short wParam_loword;
58
 
59
   // filter out the commonly used message values
60
   wParam_hiword = HIWORD (wParam);
61
   wParam_loword = LOWORD (wParam);
62
 
63
   // have we just fired up this window ?
64
   if (message == WM_INITDIALOG)
65
   {
66
      // center the window
67
      CenterWindow (hWnd, hMainWnd);
68
 
69
      // set dialog icons (small one for title bar & big one for task manager)
70
      SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
71
      SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN)));
72
 
73
      // set window title and control texts
74
      SetWindowText (hWnd, LOCALIZE (L"Quit_Title"));
75
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_QUIT_QUESTION), LOCALIZE (L"Quit_Question"));
76
      SetWindowText (GetDlgItem (hWnd, BUTTON_GIVEUPANDQUIT), LOCALIZE (L"Quit_GiveUpAndQuit"));
77
      SetWindowText (GetDlgItem (hWnd, BUTTON_BACKTOGAME), LOCALIZE (L"Quit_BackToGame"));
78
      Static_SetText (GetDlgItem (hWnd, STATICTEXT_QUIT_STATUSBAR), LOCALIZE (L"Quit_StatusBar"));
79
 
80
      // convert the status bar message to a hyperlink
81
      ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_QUIT_STATUSBAR));
82
   }
83
 
84
   // else did we click the close button on the title bar ?
85
   else if (message == WM_CLOSE)
86
      EndDialog (hWnd, 0); // close the dialog box
87
 
88
   // else did we take action on one of the controls ?
89
   else if (message == WM_COMMAND)
90
   {
91
      // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key)
92
      if (wParam_loword == IDCANCEL)
93
         EndDialog (hWnd, 0); // close the dialog box
94
 
95
      // else was it the quit button ?
96
      else if (wParam_loword == BUTTON_GIVEUPANDQUIT)
97
         EndDialog (hWnd, 1); // close the dialog box and return a success value
98
 
99
      // else was it the back to game button ?
100
      else if (wParam_loword == BUTTON_BACKTOGAME)
101
         EndDialog (hWnd, 0); // close the dialog box
102
 
103
      // else was it the status bar hyperlink ?
104
      else if (wParam_loword == STATICTEXT_QUIT_STATUSBAR)
105
         ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized
106
   }
107
 
108
   // call the default dialog message processing function to keep things going
109
   return (false);
110
}