📄 dregedit.cpp
字号:
// DRegedit.cpp : implementation file
//
#include "stdafx.h"
#include "MyProject.h"
#include "DRegedit.h"
#include "DLogin.h"
#include "Math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDRegedit dialog
CDRegedit::CDRegedit(CWnd* pParent /*=NULL*/)
: CDialog(CDRegedit::IDD, pParent)
{
//{{AFX_DATA_INIT(CDRegedit)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDRegedit::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDRegedit)
DDX_Control(pDX, IDC_BUTTRY, m_ButTry);
DDX_Control(pDX, IDC_EDTCODE, m_EdtCode);
DDX_Control(pDX, IDC_EDTUSERNAME, m_EdtUserName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDRegedit, CDialog)
//{{AFX_MSG_MAP(CDRegedit)
ON_BN_CLICKED(IDC_BUTHERE, OnButhere)
ON_BN_CLICKED(IDC_BUTREG, OnButreg)
ON_BN_CLICKED(IDC_BUTTRY, OnButtry)
ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDRegedit message handlers
void CDRegedit::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CDRegedit::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CDRegedit::OnButhere()
{
CString sUserName;
m_EdtUserName.GetWindowText(sUserName);
if(sUserName.IsEmpty())
{
MessageBox("请输入用户名!","系统提示",MB_OK|MB_ICONSTOP);
this->m_EdtUserName.SetFocus();
}
CString sSerialNumber;
sSerialNumber.Format("%d",m_VolumnSerialNumber^1234567890123);
CFileDialog dlg(false,"注册.RXI","注册.RXI",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"注册文件|*.RXI|");
dlg.DoModal();
CString sFile=dlg.GetPathName();
if(sFile.IsEmpty())
return;
//写入文件
CFile file(sFile, CFile::modeCreate | CFile::modeWrite );
file.WriteHuge(sUserName.GetBuffer(sUserName.GetLength()),sUserName.GetLength());
file.WriteHuge("~",1);
file.WriteHuge(sSerialNumber.GetBuffer(sSerialNumber.GetLength()),sSerialNumber.GetLength());
file.Close();
MessageBox("注册文件生成完毕,其路径为: "+sFile,"系统提示",MB_OK|MB_ICONEXCLAMATION);
}
void CDRegedit::OnButreg()
{
//将用户名与机器码作异或运算
CString sName,sNameCode,sCode;
this->m_EdtUserName.GetWindowText(sName);
char * cNameCode=sName.GetBuffer(sName.GetLength());
DWORD dNameCode=*cNameCode;
sCode.Format("%d",m_VolumnSerialNumber^dNameCode);
for(int i=0;i<sCode.GetLength();i++)
{
if((i+1)%4==0)
sCode.Insert(i,"-");
}
CString sCodeText;
CString sPath;
this->m_EdtCode.GetWindowText(sCodeText);
//写入文件
if(sCodeText==sCode) //注册成功
{
char cPath[_MAX_DIR];
::GetSystemDirectory(cPath,sizeof(cPath));
sPath.Format("%s\\SYSRX.ini",cPath);
::WritePrivateProfileString("ENROL","NAME",sName,sPath);
::WritePrivateProfileString("ENROL","CODE",sCode,sPath);
MessageBox("您已成功注册《物流综合管理系统》,感谢对国产软件事业的支持!","系统提示",MB_OK|MB_ICONEXCLAMATION);
p_Try=true;
this->OnCancel();
CDLogin dlg;
dlg.DoModal();
}
else
MessageBox("您输入的用户名或注册码有误!请与供应商联系!","系统提示",MB_OK|MB_ICONSTOP);
}
void CDRegedit::OnButtry()
{
HKEY Key;
CString sKeyPath;
sKeyPath="Software\\明日软件";
if(RegOpenKey(HKEY_CURRENT_USER,sKeyPath,&Key)!=0 &&RegOpenKey(HKEY_CURRENT_USER,sKeyPath,&Key)!=ERROR_SUCCESS)
{
//在注册表中记录已试用的次数
::RegCreateKey(HKEY_CURRENT_USER,sKeyPath,&Key);
::RegSetValueEx(Key,"TryTime",0,REG_SZ,(unsigned char*)"99",2);
::RegCloseKey(Key);
MessageBox("您还可以试用99次!","系统提示",MB_OK|MB_ICONEXCLAMATION);
CDLogin dlg;
dlg.DoModal();
return;
}
else //已经存在注册信息
{
CString sTryTime;
int nTryTime;
LPBYTE Data=new BYTE[80];
DWORD TYPE=REG_SZ;
DWORD cbData=80;
//取出已记载的数量
::RegQueryValueEx(Key,"TryTime",0,&TYPE,Data,&cbData);
sTryTime.Format("%s",Data);
nTryTime=atoi(sTryTime);
if(nTryTime<1)
{
MessageBox("您的最大试用次数已过,只有注册后才允许继续使用!","系统提示",MB_OK|MB_ICONSTOP);
this->m_ButTry.EnableWindow(false);
return;
}
nTryTime--;
sTryTime.Format("%d",nTryTime);
::RegSetValueEx(Key,"TryTime",0,REG_SZ,(unsigned char*)sTryTime.GetBuffer(sTryTime.GetLength()),2);
::RegCloseKey(Key);
MessageBox("您还可以试用"+sTryTime+"次!","系统提示",MB_OK|MB_ICONEXCLAMATION);
this->OnCancel();
CDLogin dlg;
dlg.DoModal();
}
}
void CDRegedit::OnButexit()
{
this->OnCancel();
}
BOOL CDRegedit::OnInitDialog()
{
CDialog::OnInitDialog();
//取得机器码(C盘序列号)
LPCTSTR lpRootPathName="C:\\";
LPTSTR lpVolumeNameBuffer=new char[12];
DWORD nVolumnNameSize=12;
DWORD MaximumComponentLength;
DWORD FileSystemFlags;
LPTSTR lpFileSystemNameBuffer=new char[10];
DWORD FileSystemNameLength=12;
GetVolumeInformation(lpRootPathName,lpVolumeNameBuffer,nVolumnNameSize,&m_VolumnSerialNumber,&MaximumComponentLength,&FileSystemFlags,lpFileSystemNameBuffer,FileSystemNameLength);
delete(lpVolumeNameBuffer);
delete(lpFileSystemNameBuffer);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -