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

📄 车友.cpp

📁 车友管理系统 密码我也不知道 不过可以在源代码里改了 先蒋登陆设为1
💻 CPP
字号:
// 车友.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "车友.h"
#include "车友Dlg.h"
#include "LoginDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyApp

BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
	//{{AFX_MSG_MAP(CMyApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyApp construction

CMyApp::CMyApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMyApp object

CMyApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CMyApp initialization

BOOL CMyApp::InitInstance()
{
	AfxEnableControlContainer();

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
	SetRegistryKey(_T("HMN-SOFT"));
	if(!InitODBC())
		return FALSE;
	CLoginDlg * log = new CLoginDlg;
	if(log->DoModal() != IDOK)
		return FALSE;
	DWORD dwUser;
	dwUser = log->GetUserInfo();
	delete log;
	CMyDlg dlg(dwUser);
	m_pMainWnd = &dlg;
	dlg.DoModal();
	return FALSE;
}
BOOL CMyApp::InitODBC()
{
	char strCurfile[256];
	char * p;
	CFileFind file;
	::GetModuleFileName(m_hInstance,strCurfile,sizeof(strCurfile));
	p = strCurfile;
	while(strchr(p,'\\'))
	{
		p = strchr(p,'\\');
		p++;
	}
	*p = '\0';
	strcat(strCurfile,"Data.mdb");
	if(!file.FindFile(strCurfile))
	{
		AfxMessageBox("找不到Data.mdb数据库文件,请保证该文件和本程序在同一个目录中!",MB_OK|MB_ICONSTOP);
		return FALSE;
	}
	if(GetProfileInt("数据源","IsFirstRun",0))
	{
		CString strKeyDir = GetProfileString("数据源","CurDir");
		if(strKeyDir.Compare(strCurfile))
		{
			WriteProfileString("数据源","CurDir",strCurfile);	
			return(LoadODBC(CString("CarsDataBase"),CString(strCurfile),CString("车友数据源")));
		}
	}
	else
	{
		USERINFO sysuser;
		strcpy(sysuser.name,"System");
		sysuser.oper = 1;
		strcpy(sysuser.password,"system");
		AfxGetApp()->WriteProfileBinary("用户","User0000",(LPBYTE)&sysuser,sizeof(sysuser));
		AfxGetApp()->WriteProfileInt("用户","LastID",1);
		WriteProfileInt("数据源","IsFirstRun",1);
		WriteProfileString("数据源","CurDir",strCurfile);
		return(LoadODBC(CString("CarsDataBase"),CString(strCurfile),CString("车友数据源")));
	}
	return TRUE;
}
BOOL CMyApp::LoadODBC(CString strSourceName,CString strSourceDb, CString strDescription)
{
	//存放打开的注册表键 
	HKEY hKey; 
	DWORD dw; 
	//存放注册表 API函数执行的返回值 
	LONG lReturn; 
	//存放要打开的子键 
	CString strSubKey; 
	//检测是否安装了 MS Access ODBC driver:odbcjt32.dll 
	//获得 Windows系统目录 
	char sysDir[MAX_PATH]; 
	char drvName[]="\\odbcjt32.dll" ; 
	::GetSystemDirectory(sysDir,MAX_PATH); 
	strcat(sysDir,drvName); 
	CFileFind findFile; 
	if(!findFile.FindFile(sysDir)) 
	{
		AfxMessageBox("找不到MS Access的ODBC驱动程序odbcjt32.dll,加载数据源失败!",
			MB_OK|MB_ICONSTOP); 
		return FALSE; 
	}
	strSubKey="SOFTWARE\\ODBC\\ODBC.INI\\"+strSourceName;
	//创建ODBC数据源在注册表中的子键 
	lReturn=::RegCreateKeyEx(HKEY_LOCAL_MACHINE,(LPCTSTR)strSubKey,0,NULL,
		REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hKey,&dw); 
	if(lReturn != ERROR_SUCCESS) 
		return false; 
	//设置数据源的各项参数 
	CString strDbq=strSourceDb;
	CString strDriver=sysDir;
	DWORD dwDriverId=25;
	CString strFil="MS Access;";
	CString strPwd=strSourceName; 
	DWORD dwSafeTransactions=0;
	CString strUid=strSourceName;
	::RegSetValueEx(hKey,"DBQ",0L,REG_SZ,(const BYTE*)((LPCTSTR) strDbq),strDbq.GetLength());
	::RegSetValueEx(hKey,"Description",0L,REG_SZ,(const BYTE*)((LPCTSTR)strDescription),strDescription.GetLength());
	::RegSetValueEx(hKey,"Driver",0L,REG_SZ,(const BYTE*)((LPCTSTR)strDriver),strDriver.GetLength());
	::RegSetValueEx(hKey,"DriverId",0L,REG_DWORD,(const BYTE*)(&dwDriverId),sizeof(dw));
	::RegSetValueEx(hKey,"FIL",0L,REG_SZ,(const BYTE*)((LPCTSTR)strFil),strFil.GetLength()); 
	::RegSetValueEx(hKey,"PWD",0L,REG_SZ,(const BYTE*)((LPCTSTR)strPwd),strPwd.GetLength ());
	::RegSetValueEx(hKey,"SafeTransactions",0L,REG_DWORD,(const BYTE*)(&dwSafeTransactions),sizeof(dw));
	::RegSetValueEx(hKey,"UID",0L,REG_SZ,(const BYTE*)((LPCTSTR)strUid),strUid.GetLength());
	::RegCloseKey(hKey); 
	//创建 ODBC数据源的 Jet子键 
	strSubKey +="\\Engines\\Jet" ; 
	lReturn=::RegCreateKeyEx(HKEY_LOCAL_MACHINE,(LPCTSTR)strSubKey,0,
		NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hKey,&dw);
	if(lReturn != ERROR_SUCCESS)
		return false; 
	//设置该子键下的各项参数 
	CString strImplict="" ; 
	CString strUserCommit="Yes" ; 
	DWORD dwPageTimeout=5;
	DWORD dwThreads=3; 
	DWORD dwMaxBufferSize=2048;
	::RegSetValueEx(hKey,"ImplictCommitSync",0L,REG_SZ,(const BYTE*)((LPCTSTR)strImplict),strImplict.GetLength()+1); 
	::RegSetValueEx(hKey,"MaxBufferSize",0L,REG_DWORD,(const BYTE*)(&dwMaxBufferSize),sizeof(dw)); 
	::RegSetValueEx(hKey,"PageTimeout",0L,REG_DWORD,(const BYTE*)(&dwPageTimeout),sizeof(dw)); 
	::RegSetValueEx(hKey,"Threads",0L,REG_DWORD,(const BYTE*)(&dwThreads),sizeof(dw)); 
	::RegSetValueEx(hKey,"UserCommitSync" ,0L,REG_SZ,(const BYTE*)((LPCTSTR)strUserCommit),strUserCommit.GetLength()); 
	::RegCloseKey(hKey); 
	//设置 ODBC数据库引擎名称 
	lReturn=::RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources" ,0L,KEY_WRITE,&hKey); 
	if(lReturn !=ERROR_SUCCESS) 
		return false; 
	CString strDbType="Microsoft Access Driver (*.mdb)";
	::RegSetValueEx(hKey,strSourceName,0L,REG_SZ,(const BYTE*)((LPCTSTR)strDbType),strDbType.GetLength());
	::RegCloseKey(hKey);
	return true; 
}

⌨️ 快捷键说明

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