Blame | Last modification | View Log
// Registration.cpp : implementation file//#include "stdafx.h"//#include "flntsys.h"#include "Registration.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CRegistration dialogCRegistration::CRegistration(CWnd* pParent /*=NULL*/): CDialog(CRegistration::IDD, pParent){//{{AFX_DATA_INIT(CRegistration)m_cKeyCode = _T("");m_cKeyPassword = _T("");//}}AFX_DATA_INITm_hIcon = AfxGetApp()->LoadIcon( IDR_REG_MAINFRAME);m_nFirst = 1;}void CRegistration::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CRegistration)DDX_Control(pDX, IDC_REG_PRODUCT, m_cProduct);DDX_Control(pDX, IDC_REG_COMPANY, m_cCompany);DDX_Control(pDX, IDC_REG_EMAILLINK, m_cEmailLink);DDX_Control(pDX, IDOK, m_cButtonOk);DDX_Control(pDX, IDCANCEL, m_cButtonCancel);DDX_Control(pDX, IDC_REG_KEYPASSWORD, m_cEditKeyPassword);DDX_Control(pDX, IDC_REG_KEYCODE, m_cEditKeyCode);DDX_Text(pDX, IDC_REG_KEYCODE, m_cKeyCode);DDV_MaxChars(pDX, m_cKeyCode, 6);DDX_Text(pDX, IDC_REG_KEYPASSWORD, m_cKeyPassword);DDV_MaxChars(pDX, m_cKeyPassword, 16);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CRegistration, CDialog)//{{AFX_MSG_MAP(CRegistration)ON_BN_CLICKED(IDC_REG_PRODUCT, OnProduct)ON_WM_SIZE()//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CRegistration message handlers//////////////////////////////////////////////////////////////////////// BOOL CRegistration::OnInitDialog()//// Initilise all the data and controls of the dialog box just before// showing.//////////////////////////////////////////////////////////////////////BOOL CRegistration::OnInitDialog(){CDialog::OnInitDialog();//set the icon for this dialog. The framework does this automatically//when the application's main window is not a dialogSetIcon(m_hIcon, TRUE); //set big iconSetIcon(m_hIcon, FALSE); //set small icon//Button stylesm_cButtonOk.SetIcon( IDI_REG_OK);m_cButtonOk.SetFlat( FALSE);m_cButtonCancel.SetIcon( IDI_REG_EXPLORE);m_cButtonCancel.SetFlat( FALSE);//Set HyperLink for E-Mailm_cEmailLink.SetURL(_T(IDS_MAILADDR));m_cEmailLink.SetUnderline(TRUE);m_cEmailLink.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_REG_HAND));m_cCompany.SetWindowText( GetCompanyName());m_cProduct.SetWindowText( GetProductName());SetWindowText( GetProductName());return TRUE; //return TRUE unless you set the focus to a control//EXCEPTION: OCX Property Pages should return FALSE}//////////////////////////////////////////////////////////////////////// void CRegistration::OnOK()//// Registration code entered by user, validate and report result//////////////////////////////////////////////////////////////////////void CRegistration::OnOK(){//update the dialog box data, befor usingUpdateData();int ready = TRUE;if (!m_oEncrypt.SetKey( m_cKeyCode)){CString invalid;if (!invalid.LoadString( IDS_REG_INVALIDSERIAL))invalid = _T("Invalid serial number!");//popup message box with error reportMessageBox( invalid, GetProductName(), MB_OK|MB_ICONEXCLAMATION|MB_TOPMOST);return;}//evaluate the serial number ans registration codeif (!m_oEncrypt.SetPassword( m_cKeyPassword))ready = FALSE;elseif (!m_oEncrypt.SavePasswordToRegistry())ready = FALSE;//tell user if regisration has failed, just a simple message boxif (ready) CDialog::OnOK();else{//load invalid regsitration message from resourceCString invalid;if (!invalid.LoadString( IDS_REG_INVALIDREG))invalid = _T("Invalid combination of serial number and registration code!");//popup message box with error reportMessageBox( invalid, GetProductName(), MB_OK|MB_ICONEXCLAMATION|MB_TOPMOST);}}//////////////////////////////////////////////////////////////////////// BOOL CRegistration::IsRegistrated()//// Check for product registration, function returns TRUE if registra-// tion is found and ok, otherwise FALSE is returned//////////////////////////////////////////////////////////////////////BOOL CRegistration::IsRegistered(){//try to setup encryption, quit and return failureif (!m_oEncrypt.Setup( GetProductName())) return FALSE;//try to read the pasword, return the failure statusif (!m_oEncrypt.ReadPasswordFromRegistry()) return FALSE;//registration is foundreturn TRUE;}//////////////////////////////////////////////////////////////////////// void CRegistration::OnProduct()//////////////////////////////////////////////////////////////////////////void CRegistration::OnProduct(){// TODO: Add your control notification handler code here}//////////////////////////////////////////////////////////////////////// void CRegistration::OnCancel()//////////////////////////////////////////////////////////////////////////void CRegistration::OnCancel(){// TODO: Add extra cleanup hereEndDialog( 0);//CDialog::OnCancel();}void CRegistration::OnSize(UINT nType, int cx, int cy){CDialog::OnSize(nType, cx, cy);//If we don't have a console, our dialog is minimized, just show itif (m_nFirst){//we only needs this the first timem_nFirst = 0;//get our window positionRECT Rect;GetWindowRect( &Rect);//the restore position is already determined, normally centeredSetWindowPos( &wndTopMost, Rect.left, Rect.top, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);//make sure we restore the window, otherwise it will still be minimizedShowWindow( SW_RESTORE);}}