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

📄 frmviewcreateserialnum.cpp

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

#include "stdafx.h"
#include "UserRegister.h"
#include "FrmViewCreateSerialNum.h"
#include <stdlib.h>

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

/////////////////////////////////////////////////////////////////////////////
// CFrmViewCreateSerialNum

IMPLEMENT_DYNCREATE(CFrmViewCreateSerialNum, CFormView)

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

CFrmViewCreateSerialNum::~CFrmViewCreateSerialNum()
{
}

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


BEGIN_MESSAGE_MAP(CFrmViewCreateSerialNum, CFormView)
	//{{AFX_MSG_MAP(CFrmViewCreateSerialNum)
	ON_BN_CLICKED(BTN_GENERICSERIALNUM, OnGenericserialnum)
	ON_LBN_SETFOCUS(LIST_SERIALNUMS, OnSetfocusSerialnums)
	ON_LBN_SELCHANGE(LIST_SERIALNUMS, OnSelchangeSerialnums)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFrmViewCreateSerialNum diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CFrmViewCreateSerialNum message handlers

BOOL CFrmViewCreateSerialNum::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	return CFormView::PreCreateWindow(cs);
}

void CFrmViewCreateSerialNum::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	CListBox* lstobj= (CListBox*)GetDlgItem(LIST_SERIALNUMS);
	lstobj->SetHorizontalExtent(2000);
}

void CFrmViewCreateSerialNum::OnGenericserialnum() 
{
	// TODO: Add your control notification handler code here
	CEdit* edtobj= (CEdit*)GetDlgItem(EDT_SERIALNUM);
	CListBox* lstobj= (CListBox*)GetDlgItem(LIST_SERIALNUMS);
	lstobj->ResetContent();

	for(int i=0;i<10;i++) //循环生成10个注册码
	{

		int Box[25];
		//第1-5个字符
		do
		{
			Box[0]=RandomChar();
			Box[1]=RandomChar();
			Box[2]=RandomChar();
			Box[3]=RandomChar();
			Box[4]=RandomChar();
		}while(Arithmetic(Box[0],Box[1],Box[2],Box[3],Box[4],11)!=1);

		//产生第6-10个字符
		do
		{
			Box[5]=RandomChar();
			Box[6]=RandomChar();
			Box[7]=RandomChar();
			Box[8]=RandomChar();
			Box[9]=RandomChar();
		}while(Arithmetic(Box[5],Box[6],Box[7],Box[8],Box[9],12)!=2);

		//产生第11-15个字符
		do
		{
			Box[10]=RandomChar();
			Box[11]=RandomChar();
			Box[12]=RandomChar();
			Box[13]=RandomChar();
			Box[14]=RandomChar();
		}while(Arithmetic(Box[10],Box[11],Box[12],Box[13],Box[14],13)!=3);

		//产生第16-20个字符
		do
		{
			Box[15]=RandomChar();
			Box[16]=RandomChar();
			Box[17]=RandomChar();
			Box[18]=RandomChar();
			Box[19]=RandomChar();
		}while(Arithmetic(Box[15],Box[16],Box[17],Box[18],Box[19],14)!=4);

		//产生第21-25个字符
		do
		{
			Box[20]=RandomChar();
			Box[21]=RandomChar();
			Box[22]=RandomChar();
			Box[23]=RandomChar();
			Box[24]=RandomChar();
		}while(Arithmetic(Box[20],Box[21],Box[22],Box[23],Box[24],15)!=5);

		//输出注册码
		edtobj->SetWindowText(NULL);
		CString strNumber;
		for(int i=0; i<25; i++)
		{
			strNumber = strNumber+CString(Box[i]);
			if((i+1)%5==0 && i<24)
					strNumber= strNumber+"-";
		}
		lstobj->AddString(strNumber);
	}
}

bool CFrmViewCreateSerialNum::CheckTheChar(int AsciiChar)
{
        if((AsciiChar>=48 && AsciiChar<=57) || (AsciiChar>=65 && AsciiChar<=90))
                return true;
        else
                return false;
}

//---------------------------------------------------------------------------
int CFrmViewCreateSerialNum::RandomChar()
{
        int Num;
        do
        {
                Num= rand();
        }while (CheckTheChar(Num)==false);
        return Num;
}

//---------------------------------------------------------------------------
int CFrmViewCreateSerialNum::Arithmetic(int Num1 , int Num2 , int Num3 , int Num4 , int Num5,int Value)
{
        int Sum;
        Sum=Num1+Num2+Num3+Num4+Num5;
        return (Sum % Value);
}

void CFrmViewCreateSerialNum::OnSetfocusSerialnums() 
{
	// TODO: Add your control notification handler code here
}

void CFrmViewCreateSerialNum::OnSelchangeSerialnums() 
{
	// TODO: Add your control notification handler code here
	CEdit* edtobj= (CEdit*)GetDlgItem(EDT_SERIALNUM);
	CListBox* lstobj= (CListBox*)GetDlgItem(LIST_SERIALNUMS);
	int index= lstobj->GetCurSel();
	if(index<0) index= 0;
	CString strItemTxt;
	lstobj->GetText(index,strItemTxt);
	edtobj->SetWindowText(strItemTxt);
}

BOOL CFrmViewCreateSerialNum::PreTranslateMessage(MSG* pMsg)
{
	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 + -