⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registerdlg.cpp

📁 简单注册模块的实现
💻 CPP
字号:
// RegisterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Register.h"
#include "RegisterDlg.h"
#include "MD5.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
extern CRegisterApp theApp;

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRegisterDlg dialog

CRegisterDlg::CRegisterDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRegisterDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRegisterDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CRegisterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRegisterDlg)
	DDX_Control(pDX, IDC_EDITUser, m_UserName);
	DDX_Control(pDX, IDC_EDITPasswordC, m_PasswordC);
	DDX_Control(pDX, IDC_EDITPassword, m_Password);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRegisterDlg, CDialog)
	//{{AFX_MSG_MAP(CRegisterDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRegisterDlg message handlers

BOOL CRegisterDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CRegisterDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CRegisterDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CRegisterDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CRegisterDlg::OnOK() 
{
	// TODO: Add extra validation here
    //定义加密解密模块指针,并初始化
	CMD5* MyMD5 = new CMD5;
	CString UserName,StrTemp,StrSQL,Password,PasswordC; 
    UpdateData(TRUE);
	//获取用户输入的用户名
    m_UserName.GetWindowText(StrTemp);
	//加密用户输入的用户名
    UserName=MyMD5->MD5_Algorithm(StrTemp);  
    //获取用户输入的密码
	m_Password.GetWindowText(StrTemp);
    //加密用户输入的密码
	Password=MyMD5->MD5_Algorithm(StrTemp); 
    //获取用户输入的确认密码
	m_PasswordC.GetWindowText(StrTemp);
	//加密用户输入的确认密码
	PasswordC=MyMD5->MD5_Algorithm(StrTemp); 
    //对查询字符串进行赋值
	StrSQL="Select * From UserInfo Where UserName = '"+UserName+" ' ";
    //初始化记录集
	m_pRs.CreateInstance("ADODB.Recordset");
	//打开记录集
	//从数据库中查找输入用户名
	m_pRs->Open((_variant_t)StrSQL, 
			      _variant_t((IDispatch *)theApp.m_pConn,true), 
				  adOpenStatic, 
				  adLockOptimistic, 
				  adCmdText);
    //如果用户名存在,则提示“用户名存在,请重新输入用户名”
	if(m_pRs->GetRecordCount()!= 0)
	{
		MessageBox("此用户名已存在,请重新输入用户名","注册",MB_OK|MB_ICONWARNING);		
	}
    //如果用户名不存在,判断两次输入的密码是否一致
	//如果两次一致则保存注册信息,否则重新输入密码
	else
	{
	  if(Password.CompareNoCase(PasswordC)==0)
	  {
		m_pRs->AddNew();
		m_pRs->PutCollect("UserName",_variant_t(UserName));
        m_pRs->PutCollect("PassWord",_variant_t(Password));
        m_pRs->Update(); 	
		MessageBox("用户名注册完毕","注册",MB_OK|MB_ICONWARNING);		
	  }
	  else
	  {
		 MessageBox("输入密码不一致请重新输入密码!","注册",MB_OK|MB_ICONWARNING);	
	     m_Password.SetFocus(); 
	  }
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -