- // dialog_registration.cpp 
-   
- #include "../common.h" 
-   
-   
- // dialog template 
- #define THIS_DIALOG DIALOG_REGISTER 
-   
-   
- // prototypes of local functions 
- static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam); 
-   
-   
- void DialogBox_Registration (void) 
- { 
-    // helper function to fire up the modal dialog box 
-   
-    // display the dialog box (set the parent to be the desktop) 
-    DialogBox (hAppInstance, MAKEINTRESOURCE (THIS_DIALOG), NULL, DialogProc_ThisDialog); 
-   
-    return; // finished processing this dialog 
- } 
-   
-   
- static int CALLBACK DialogProc_ThisDialog (HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam) 
- { 
-    // message handler for the dialog box 
-   
-    static wchar_t error_message[1024]; 
-    static wchar_t candidate_email[256]; 
-   
-    unsigned long candidate_code; 
-    unsigned short wParam_hiword; 
-    unsigned short wParam_loword; 
-    BOOL was_translated; // needs to be of type BOOL (int) 
-    int read_index; 
-    int write_index; 
-    int length; 
-   
-    // 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"Registration_Title")); 
-   
-       // set the static texts 
-       Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_QUESTION), LOCALIZE (L"Registration_Question")); 
-       SetWindowText (GetDlgItem (hWnd, BUTTON_DONATE), LOCALIZE (L"Registration_Donate")); 
-       Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_NOPAYPAL), LOCALIZE (L"Registration_NoPayPal")); 
-       Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_INSTRUCTIONS), LOCALIZE (L"Registration_Instructions")); 
-       Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_EMAILADDRESS), LOCALIZE (L"Registration_EmailAddress")); 
-       SetDlgItemText (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS, options.registration.user_email); 
-       Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_ACTIVATIONCODE), LOCALIZE (L"Registration_ActivationCode")); 
-       //SetDlgItemInt (hWnd, EDITBOX_REGISTRATION_ACTIVATIONCODE, options.registration.activation_code, false); 
-       SetWindowText (GetDlgItem (hWnd, BUTTON_VALIDATECODE), LOCALIZE (L"Registration_ValidateCode")); 
-       Static_SetText (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_STATUSBAR), LOCALIZE (L"Registration_StatusBar")); 
-   
-       // set focus to the first settable item 
-       SendMessage (GetDlgItem (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS), EM_SETSEL, 0, -1); // select all text 
-       SetFocus (GetDlgItem (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS)); 
-   
-       // convert the "no paypal" and the status bar message to hyperlinks 
-       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_NOPAYPAL)); 
-       ConvertStaticToHyperlink (GetDlgItem (hWnd, STATICTEXT_REGISTRATION_STATUSBAR)); 
-    } 
-   
-    // 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) 
-    { 
-       // did we cancel the dialog box ? (IDCANCEL is a system-wide dialog box handler value, that catches the ESC key) 
-       if (wParam_loword == IDCANCEL) 
-          EndDialog (hWnd, 0); // close the dialog box 
-   
-       // else was it the validation button ? 
-       else if (wParam_loword == BUTTON_VALIDATECODE) 
-       { 
-          // retrieve form data 
-          GetDlgItemText (hWnd, EDITBOX_REGISTRATION_EMAILADDRESS, candidate_email, WCHAR_SIZEOF (candidate_email)); 
-          candidate_code = GetDlgItemInt (hWnd, EDITBOX_REGISTRATION_ACTIVATIONCODE, &was_translated, false); 
-   
-          // strip spaces and unprintable characters from candidate email 
-          length = wcslen (candidate_email); 
-          write_index = 0; 
-          for (read_index = 0; read_index < length; read_index++) 
-             if (!iswspace (candidate_email[read_index]) && (read_index > write_index)) 
-             { 
-                candidate_email[write_index] = candidate_email[read_index]; 
-                write_index++; 
-             } 
-          candidate_email[write_index] = 0; // ensure string is correctly terminated 
-   
-          // save activation email 
-          wcscpy_s (options.registration.user_email, WCHAR_SIZEOF (options.registration.user_email), candidate_email); 
-   
-          // is the email or the activation code empty ? 
-          if ((candidate_email[0] == 0) || !was_translated) 
-             EndDialog (hWnd, 0); // if so, just exit the dialog (assume user did not want to register) 
-   
-          // else is the supplied data correct ? 
-          else if (IsRegistrationCorrect (candidate_email, candidate_code)) 
-          { 
-             // if so, save activation code 
-             options.registration.activation_code = candidate_code; 
-             MessageBox (hWnd, LOCALIZE (L"Registration_ThankYou"), PROGRAM_NAME, MB_ICONINFORMATION | MB_OK); 
-             EndDialog (hWnd, 0); // then display a thank you dialog box and exit the program 
-          } 
-   
-          // else the supplied data is wrong 
-          else 
-          { 
-             swprintf_s (error_message, WCHAR_SIZEOF (error_message), LOCALIZE (L"Registration_Error"), AUTHOR_EMAIL); 
-             MessageBox (hWnd, error_message, PROGRAM_NAME, MB_ICONINFORMATION | MB_OK); // wrong activation. Display an error and DON'T exit the program 
-          } 
-       } 
-   
-       // else was it the PayPal button ? 
-       else if (wParam_loword == BUTTON_DONATE) 
-          ShellExecute (NULL, L"open", PAYPAL_URL, NULL, NULL, SW_MAXIMIZE); // open PayPal in the default browser, maximized 
-   
-       // else was it the "no PayPal" hyperlink ? 
-       else if (wParam_loword == STATICTEXT_REGISTRATION_NOPAYPAL) 
-          ShellExecute (NULL, L"open", NOPAYPAL_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized 
-   
-       // else was it the status bar hyperlink ? 
-       else if (wParam_loword == STATICTEXT_REGISTRATION_STATUSBAR) 
-          ShellExecute (NULL, L"open", PROGRAM_URL, NULL, NULL, SW_MAXIMIZE); // open the donation page in the default browser, maximized 
-    } 
-   
-    // call the default dialog message processing function to keep things going 
-    return (false); 
- } 
-