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

📄 frmviewcreateregcode.cpp

📁 序列号生成工具,使用MD5加密算法,生成程序的序列号,帮助程序员保护自己的产权.
💻 CPP
字号:
// FrmViewCreateRegCode.cpp : implementation file
//

#include "stdafx.h"
#include "UserRegister.h"
#include "FrmViewCreateRegCode.h"
#include "MD5.h"
#include "FrmViewCreateSerialNum.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFrmViewCreateRegCode

IMPLEMENT_DYNCREATE(CFrmViewCreateRegCode, CFormView)

CFrmViewCreateRegCode::CFrmViewCreateRegCode()
	: CFormView(CFrmViewCreateRegCode::IDD)
{
	//{{AFX_DATA_INIT(CFrmViewCreateRegCode)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CFrmViewCreateRegCode::~CFrmViewCreateRegCode()
{
}

void CFrmViewCreateRegCode::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFrmViewCreateRegCode)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFrmViewCreateRegCode, CFormView)
	//{{AFX_MSG_MAP(CFrmViewCreateRegCode)
	ON_BN_CLICKED(BTN_TESTSERIALNUM, OnTestserialnum)
	ON_BN_CLICKED(BTN_CREATEREGCODE, OnCreateregcode)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFrmViewCreateRegCode diagnostics

#ifdef _DEBUG
void CFrmViewCreateRegCode::AssertValid() const
{
	CFormView::AssertValid();
}

void CFrmViewCreateRegCode::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFrmViewCreateRegCode message handlers

void CFrmViewCreateRegCode::OnTestserialnum() //测试序列号
{
	// TODO: Add your control notification handler code here
	CString strSerialNO,strTemp;
	CEdit* edtobj= (CEdit*)GetDlgItem(EDT_SERIALNO);
	edtobj->GetWindowText(strSerialNO);

	if(strSerialNO.GetLength() != 29)
	{
		MessageBox(_T("序列号错误!"),"提示",MB_OK|MB_ICONSTOP);
		return;
	}
	strTemp= strSerialNO.Mid(0,5);
	if(CheckSerialNO(strTemp[0],strTemp[1],strTemp[2],strTemp[3],strTemp[4],11,1)==FALSE)
	{
		MessageBox(_T("序列号错误!"),"提示",MB_OK|MB_ICONSTOP);
		return;
	}
	strTemp= strSerialNO.Mid(6,5);
	if(CheckSerialNO(strTemp[0],strTemp[1],strTemp[2],strTemp[3],strTemp[4],12,2)==FALSE)
	{
		MessageBox(_T("序列号错误!"),"提示",MB_OK|MB_ICONSTOP);
		return;
	}
	strTemp= strSerialNO.Mid(12,5);
	if(CheckSerialNO(strTemp[0],strTemp[1],strTemp[2],strTemp[3],strTemp[4],13,3)==FALSE)
	{
		MessageBox(_T("序列号错误!"),"提示",MB_OK|MB_ICONSTOP);
		return;
	}
	strTemp= strSerialNO.Mid(18,5);
	if(CheckSerialNO(strTemp[0],strTemp[1],strTemp[2],strTemp[3],strTemp[4],14,4)==FALSE)
	{
		MessageBox(_T("序列号错误!"),"提示",MB_OK|MB_ICONSTOP);
		return;
	}
	strTemp= strSerialNO.Mid(24,5);
	if(CheckSerialNO(strTemp[0],strTemp[1],strTemp[2],strTemp[3],strTemp[4],15,5)==FALSE)
	{
		MessageBox(_T("序列号错误!"),"提示",MB_OK|MB_ICONSTOP);
		return;
	}
	MessageBox(_T("序列号正确!"),"提示",MB_OK|MB_ICONINFORMATION);
}

void CFrmViewCreateRegCode::OnCreateregcode() //生成注册码
{
	// TODO: Add your control notification handler code here
	CString strSerialNO;
	CEdit* edtobj= (CEdit*)GetDlgItem(EDT_SERIALNO);
	edtobj->GetWindowText(strSerialNO);
	if(strSerialNO.GetLength() != 29)
	{
		MessageBox(_T("序列号错误!"),"提示",MB_OK|MB_ICONSTOP);
		return;
	}
	CString strnum1,strnum2,strnum3,strnum4,strnum5;
	strnum1= strSerialNO.Mid(0,5);
	strnum2= strSerialNO.Mid(6,5);
	strnum3= strSerialNO.Mid(12,5);
	strnum4= strSerialNO.Mid(18,5);
	strnum5= strSerialNO.Mid(24,5);
	strnum1= strnum1+strnum2+strnum3+strnum4+strnum5;
	
	CString strKey;
	edtobj= (CEdit*)GetDlgItem(EDT_KEY);
	edtobj->GetWindowText(strKey);

	CMD5 md5;
	CString strRegCode= md5.hmac_md5(strnum1.GetBuffer(1),strKey.GetBuffer(1));
	strRegCode= strRegCode.Mid(3,25);

	CString strResult;
	strResult= _T("序列号:")+strSerialNO+_T("\r\nKEY:")+strKey+_T("\r\n注册码:")+strRegCode+_T("\r\n");
	edtobj= (CEdit*)GetDlgItem(EDT_REGCODE);
	edtobj->SetWindowText(strResult);
}

BOOL CFrmViewCreateRegCode::CheckSerialNO(int num1,int num2,int num3,int num4,int num5,int arg1,int arg2)
{
	if((num1+num2+num3+num4+num5)%arg1 == arg2)
		return TRUE;
	else
		return FALSE;
}

BOOL CFrmViewCreateRegCode::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message== WM_KEYDOWN)
	{
		if((pMsg->wParam== 'C' || pMsg->wParam=='c') && GetKeyState(VK_CONTROL))
		{
			CEdit* edtobj= (CEdit*)this->GetFocus();
			edtobj->Copy();
		}
		if((pMsg->wParam== 'V' || pMsg->wParam=='v') && GetKeyState(VK_CONTROL))
		{
			CEdit* edtobj= (CEdit*)this->GetFocus();
			edtobj->Paste();
		}
		if((pMsg->wParam== 'X' || pMsg->wParam=='x') && GetKeyState(VK_CONTROL))
		{
			CEdit* edtobj= (CEdit*)this->GetFocus();
			edtobj->Cut();
		}
	}
	
	return CFormView::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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