Rev 19 | Rev 23 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | pmbaty | 1 | // dialog_registration.cpp |
2 | |||
3 | #include "../common.h" |
||
4 | |||
5 | |||
6 | // dialog template |
||
7 | #define THIS_DIALOG DIALOG_REGISTER |
||
8 | |||
9 | |||
10 | // prototypes of local functions |
||
11 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); |
||
12 | |||
13 | |||
14 | void DialogBox_Registration (void) |
||
15 | { |
||
16 | // helper function to fire up the modal dialog box |
||
17 | |||
18 | // display the dialog box (set the parent to be the desktop) |
||
19 | DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), NULL, DialogProc_ThisDialog); |
||
20 | |||
21 | return; // finished processing this dialog |
||
22 | } |
||
23 | |||
24 | |||
25 | static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) |
||
26 | { |
||
27 | // message handler for the dialog box |
||
28 | |||
29 | static wchar_t error_message[1024]; |
||
30 | static wchar_t candidate_email[256]; |
||
31 | |||
32 | unsigned long candidate_code; |
||
33 | unsigned short wParam_hiword; |
||
34 | unsigned short wParam_loword; |
||
35 | BOOL was_translated; // needs to be of type BOOL (int) |
||
36 | int read_index; |
||
37 | int write_index; |
||
38 | int length; |
||
39 | |||
40 | // filter out the commonly used message values |
||
41 | wParam_hiword = HIWORD (wParam); |
||
42 | wParam_loword = LOWORD (wParam); |
||
43 | |||
44 | // have we just fired up this window ? |
||
45 | if (message == WM_INITDIALOG) |
||
46 | { |
||
47 | // center the window |
||
48 | CenterWindow (hWnd, hMainWnd); |
||
49 | |||
50 | // set dialog icons (small one for title bar & big one for task manager) |
||
51 | SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
52 | SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, MAKEINTRESOURCE (ICON_MAIN))); |
||
53 | |||
54 | // set window title and control texts |
||
55 | SetWindowText (hWnd, LOCALIZE (L"Registration_Title")); |
||
56 | |||
57 | // set the static texts |
||
58 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_QUESTION), LOCALIZE (L"Registration_Question")); |
||
59 | SetWindowText (GetDlgItem (hWnd, BUTTON_DONATE), LOCALIZE (L"Registration_Donate")); |
||
60 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_NOPAYPAL), LOCALIZE (L"Registration_NoPayPal")); |
||
61 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_INSTRUCTIONS), LOCALIZE (L"Registration_Instructions")); |
||
62 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_EMAILADDRESS), LOCALIZE (L"Registration_EmailAddress")); |
||
63 | SetDlgItemText (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS, options.registration.user_email); |
||
64 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_ACTIVATIONCODE), LOCALIZE (L"Registration_ActivationCode")); |
||
65 | //SetDlgItemInt (hWnd, EDITBOX_REGISTRATION_ACTIVATIONCODE, options.registration.activation_code, false); |
||
66 | SetWindowText (GetDlgItem (hWnd, BUTTON_VALIDATECODE), LOCALIZE (L"Registration_ValidateCode")); |
||
67 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_STATUSBAR), LOCALIZE (L"Registration_StatusBar")); |
||
68 | |||
69 | // set focus to the first settable item |
||
70 | SendMessage (GetDlgItem (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS), EM_SETSEL, 0, -1); // select all text |
||
71 | SetFocus (GetDlgItem (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS)); |
||
72 | |||
73 | // convert the "no paypal" and the status bar message to hyperlinks |
||
74 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_NOPAYPAL)); |
||
75 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_STATUSBAR)); |
||
76 | } |
||
77 | |||
78 | // else did we click the close button on the title bar ? |
||
79 | else if (message == WM_CLOSE) |
||
80 | EndDialog (hWnd, 0); // close the dialog box |
||
81 | |||
82 | // else did we take action on one of the controls ? |
||
83 | else if (message == WM_COMMAND) |
||
84 | { |
||
85 | // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
86 | if (wParam_loword == IDCANCEL) |
||
87 | EndDialog (hWnd, 0); // close the dialog box |
||
88 | |||
21 | pmbaty | 89 | // else did the user enter something in the edit boxes ? |
90 | else if (wParam_hiword == EN_CHANGE) |
||
91 | { |
||
92 | // enable the validation button only if the two fields have data |
||
93 | GetDlgItemText (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS, candidate_email, WCHAR_SIZEOF (candidate_email)); |
||
94 | candidate_code = GetDlgItemInt (hWnd, EDITBOX_REGISTRATION_ACTIVATIONCODE, &was_translated, false); |
||
95 | EnableWindow (GetDlgItem (hWnd, BUTTON_VALIDATECODE), ((candidate_email[0] != 0) && (candidate_code != 0))); |
||
96 | } |
||
97 | |||
14 | pmbaty | 98 | // else was it the validation button ? |
99 | else if (wParam_loword == BUTTON_VALIDATECODE) |
||
100 | { |
||
101 | // retrieve form data |
||
102 | GetDlgItemText (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS, candidate_email, WCHAR_SIZEOF (candidate_email)); |
||
103 | candidate_code = GetDlgItemInt (hWnd, EDITBOX_REGISTRATION_ACTIVATIONCODE, &was_translated, false); |
||
104 | |||
105 | // strip spaces and unprintable characters from candidate email |
||
106 | length = wcslen (candidate_email); |
||
107 | write_index = 0; |
||
108 | for (read_index = 0; read_index < length; read_index++) |
||
19 | pmbaty | 109 | if (!iswspace (candidate_email[read_index])) |
14 | pmbaty | 110 | { |
111 | candidate_email[write_index] = candidate_email[read_index]; |
||
112 | write_index++; |
||
113 | } |
||
114 | candidate_email[write_index] = 0; // ensure string is correctly terminated |
||
115 | |||
116 | // save activation email |
||
117 | wcscpy_s (options.registration.user_email, WCHAR_SIZEOF (options.registration.user_email), candidate_email); |
||
118 | |||
119 | // is the email or the activation code empty ? |
||
120 | if ((candidate_email[0] == 0) || !was_translated) |
||
121 | EndDialog (hWnd, 0); // if so, just exit the dialog (assume user did not want to register) |
||
122 | |||
123 | // else is the supplied data correct ? |
||
124 | else if (IsRegistrationCorrect (candidate_email, candidate_code)) |
||
125 | { |
||
126 | // if so, save activation code |
||
127 | options.registration.activation_code = candidate_code; |
||
128 | MessageBox (hWnd, LOCALIZE (L"Registration_ThankYou"), PROGRAM_NAME, MB_ICONINFORMATION | MB_OK); |
||
129 | EndDialog (hWnd, 0); // then display a thank you dialog box and exit the program |
||
130 | } |
||
131 | |||
132 | // else the supplied data is wrong |
||
133 | else |
||
134 | { |
||
135 | swprintf_s (error_message, WCHAR_SIZEOF (error_message), LOCALIZE (L"Registration_Error"), AUTHOR_EMAIL); |
||
136 | MessageBox (hWnd, error_message, PROGRAM_NAME, MB_ICONINFORMATION | MB_OK); // wrong activation. Display an error and DON'T exit the program |
||
137 | } |
||
138 | } |
||
139 | |||
140 | // else was it the PayPal button ? |
||
141 | else if (wParam_loword == BUTTON_DONATE) |
||
142 | ShellExecute (NULL, L"open", PAYPAL_URL, NULL, NULL, SW_MAXIMIZE); // open PayPal in the default browser, maximized |
||
143 | |||
144 | // else was it the "no PayPal" hyperlink ? |
||
145 | else if (wParam_loword == STATICTEXT_REGISTRATION_NOPAYPAL) |
||
146 | ShellExecute (NULL, L"open", NOPAYPAL_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
147 | |||
148 | // else was it the status bar hyperlink ? |
||
149 | else if (wParam_loword == STATICTEXT_REGISTRATION_STATUSBAR) |
||
150 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized |
||
151 | } |
||
152 | |||
153 | // call the default dialog message processing function to keep things going |
||
154 | return (false); |
||
155 | } |