Rev 21 | Rev 83 | 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")); |
||
23 | pmbaty | 62 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_CODENOTRECEIVED), LOCALIZE (L"Registration_CodeNotReceived")); |
14 | pmbaty | 63 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_EMAILADDRESS), LOCALIZE (L"Registration_EmailAddress")); |
64 | SetDlgItemText (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS, options.registration.user_email); |
||
65 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_ACTIVATIONCODE), LOCALIZE (L"Registration_ActivationCode")); |
||
66 | //SetDlgItemInt (hWnd, EDITBOX_REGISTRATION_ACTIVATIONCODE, options.registration.activation_code, false); |
||
67 | SetWindowText (GetDlgItem (hWnd, BUTTON_VALIDATECODE), LOCALIZE (L"Registration_ValidateCode")); |
||
68 | Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_STATUSBAR), LOCALIZE (L"Registration_StatusBar")); |
||
69 | |||
70 | // set focus to the first settable item |
||
71 | SendMessage (GetDlgItem (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS), EM_SETSEL, 0, -1); // select all text |
||
72 | SetFocus (GetDlgItem (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS)); |
||
73 | |||
74 | // convert the "no paypal" and the status bar message to hyperlinks |
||
75 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_NOPAYPAL)); |
||
23 | pmbaty | 76 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_CODENOTRECEIVED)); |
14 | pmbaty | 77 | ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_STATUSBAR)); |
78 | } |
||
79 | |||
80 | // else did we click the close button on the title bar ? |
||
81 | else if (message == WM_CLOSE) |
||
82 | EndDialog (hWnd, 0); // close the dialog box |
||
83 | |||
84 | // else did we take action on one of the controls ? |
||
85 | else if (message == WM_COMMAND) |
||
86 | { |
||
87 | // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) |
||
88 | if (wParam_loword == IDCANCEL) |
||
89 | EndDialog (hWnd, 0); // close the dialog box |
||
90 | |||
21 | pmbaty | 91 | // else did the user enter something in the edit boxes ? |
92 | else if (wParam_hiword == EN_CHANGE) |
||
93 | { |
||
94 | // enable the validation button only if the two fields have data |
||
95 | GetDlgItemText (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS, candidate_email, WCHAR_SIZEOF (candidate_email)); |
||
96 | candidate_code = GetDlgItemInt (hWnd, EDITBOX_REGISTRATION_ACTIVATIONCODE, &was_translated, false); |
||
97 | EnableWindow (GetDlgItem (hWnd, BUTTON_VALIDATECODE), ((candidate_email[0] != 0) && (candidate_code != 0))); |
||
98 | } |
||
99 | |||
14 | pmbaty | 100 | // else was it the validation button ? |
101 | else if (wParam_loword == BUTTON_VALIDATECODE) |
||
102 | { |
||
103 | // retrieve form data |
||
104 | GetDlgItemText (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS, candidate_email, WCHAR_SIZEOF (candidate_email)); |
||
105 | candidate_code = GetDlgItemInt (hWnd, EDITBOX_REGISTRATION_ACTIVATIONCODE, &was_translated, false); |
||
106 | |||
107 | // strip spaces and unprintable characters from candidate email |
||
108 | length = wcslen (candidate_email); |
||
109 | write_index = 0; |
||
110 | for (read_index = 0; read_index < length; read_index++) |
||
19 | pmbaty | 111 | if (!iswspace (candidate_email[read_index])) |
14 | pmbaty | 112 | { |
113 | candidate_email[write_index] = candidate_email[read_index]; |
||
114 | write_index++; |
||
115 | } |
||
116 | candidate_email[write_index] = 0; // ensure string is correctly terminated |
||
117 | |||
118 | // save activation email |
||
119 | wcscpy_s (options.registration.user_email, WCHAR_SIZEOF (options.registration.user_email), candidate_email); |
||
120 | |||
121 | // is the email or the activation code empty ? |
||
122 | if ((candidate_email[0] == 0) || !was_translated) |
||
123 | EndDialog (hWnd, 0); // if so, just exit the dialog (assume user did not want to register) |
||
124 | |||
125 | // else is the supplied data correct ? |
||
126 | else if (IsRegistrationCorrect (candidate_email, candidate_code)) |
||
127 | { |
||
128 | // if so, save activation code |
||
129 | options.registration.activation_code = candidate_code; |
||
130 | MessageBox (hWnd, LOCALIZE (L"Registration_ThankYou"), PROGRAM_NAME, MB_ICONINFORMATION | MB_OK); |
||
131 | EndDialog (hWnd, 0); // then display a thank you dialog box and exit the program |
||
132 | } |
||
133 | |||
134 | // else the supplied data is wrong |
||
135 | else |
||
136 | { |
||
137 | swprintf_s (error_message, WCHAR_SIZEOF (error_message), LOCALIZE (L"Registration_Error"), AUTHOR_EMAIL); |
||
138 | MessageBox (hWnd, error_message, PROGRAM_NAME, MB_ICONINFORMATION | MB_OK); // wrong activation. Display an error and DON'T exit the program |
||
139 | } |
||
140 | } |
||
141 | |||
142 | // else was it the PayPal button ? |
||
143 | else if (wParam_loword == BUTTON_DONATE) |
||
144 | ShellExecute (NULL, L"open", PAYPAL_URL, NULL, NULL, SW_MAXIMIZE); // open PayPal in the default browser, maximized |
||
145 | |||
146 | // else was it the "no PayPal" hyperlink ? |
||
147 | else if (wParam_loword == STATICTEXT_REGISTRATION_NOPAYPAL) |
||
23 | pmbaty | 148 | ShellExecute (NULL, L"open", NOPAYPAL_URL, NULL, NULL, SW_MAXIMIZE); // open the bank account page in the default browser, maximized |
14 | pmbaty | 149 | |
23 | pmbaty | 150 | // else was it the "code not received" hyperlink ? |
151 | else if (wParam_loword == STATICTEXT_REGISTRATION_CODENOTRECEIVED) |
||
152 | ShellExecute (NULL, L"open", PAYPAL_RETURNURL, NULL, NULL, SW_MAXIMIZE); // open the manual code retrieval page in the default browser, maximized |
||
153 | |||
14 | pmbaty | 154 | // else was it the status bar hyperlink ? |
155 | else if (wParam_loword == STATICTEXT_REGISTRATION_STATUSBAR) |
||
23 | pmbaty | 156 | ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the main page in the default browser, maximized |
14 | pmbaty | 157 | } |
158 | |||
159 | // call the default dialog message processing function to keep things going |
||
160 | return (false); |
||
161 | } |