如题 这应该检查哪儿的代码呢?谢谢!!各位高手!请指教!
初始化为:BOOL CZXXGVAApp::InitInstance()
{
AfxEnableControlContainer();
CoInitialize(NULL);
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
//初始化SkinLoad,加载皮肤文件
//InitSkinLoad(GetCurrentThreadId());
//LoadSkin("xp_silver.skin");//xp_normal
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CZXXGVADoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CZXXGVAView));
AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
m_nCmdShow = SW_SHOWMAXIMIZED;
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE; // The one and only window has been initialized, so show and update it.
m_pMainWnd->SetWindowText(_T("上海哈顿车辆监控系统"));
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
CHAR szFileName[MAX_PATH];
GetModuleFileName(NULL,szFileName,MAX_PATH);
CString strPath(szFileName);
int nPos = strPath.ReverseFind('\\');
strPath = strPath.Left(nPos);
nPos = strPath.ReverseFind('\\');
strPath = strPath.Left(nPos);
strPath += _T("\\Debug\\ZXXDBC.ini"); CStdioFile file;
if(file.Open(strPath,CFile::modeRead))
{
CString strText;
file.ReadString(strText);
int nPos;
CString strLeft,strRight;
int nIndex = 0;
while(file.ReadString(strText))
{
nPos = strText.Find("=");
strLeft = strText.Left(nPos);
strLeft.TrimLeft();
strLeft.TrimRight();
strRight = strText.Mid(nPos+1);
strRight.TrimLeft();
strRight.TrimRight();
if ("SERVER"==strLeft)
SERVER=strRight;
if ("DATABASE"==strLeft)
DATABASE=strRight;
if ("UID"==strLeft)
UID=strRight;
if ("PWD"==strLeft)
PWD=strRight;
if (("ServerDBIP"==strLeft)&&(strRight!=""))
ServerDBIP=strRight;
nIndex++;
}
file.Close();
}
else
{
AfxMessageBox("数据库配置文件错误!");
return FALSE;
} /*
if(m_adoConnection.ConnectSQLServer(_T("CRE-GVA"),_T("Monitor"),_T("sa"),_T("123")))
{
m_adoRecordSet.SetAdoConnection(&m_adoConnection);
m_adoRecordSet.SetCursorLocation();
}
else
{
AfxMessageBox("数据库连接失败!");
}*/
return TRUE;
}
初始化为:BOOL CZXXGVAApp::InitInstance()
{
AfxEnableControlContainer();
CoInitialize(NULL);
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
//初始化SkinLoad,加载皮肤文件
//InitSkinLoad(GetCurrentThreadId());
//LoadSkin("xp_silver.skin");//xp_normal
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CZXXGVADoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CZXXGVAView));
AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
m_nCmdShow = SW_SHOWMAXIMIZED;
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE; // The one and only window has been initialized, so show and update it.
m_pMainWnd->SetWindowText(_T("上海哈顿车辆监控系统"));
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
CHAR szFileName[MAX_PATH];
GetModuleFileName(NULL,szFileName,MAX_PATH);
CString strPath(szFileName);
int nPos = strPath.ReverseFind('\\');
strPath = strPath.Left(nPos);
nPos = strPath.ReverseFind('\\');
strPath = strPath.Left(nPos);
strPath += _T("\\Debug\\ZXXDBC.ini"); CStdioFile file;
if(file.Open(strPath,CFile::modeRead))
{
CString strText;
file.ReadString(strText);
int nPos;
CString strLeft,strRight;
int nIndex = 0;
while(file.ReadString(strText))
{
nPos = strText.Find("=");
strLeft = strText.Left(nPos);
strLeft.TrimLeft();
strLeft.TrimRight();
strRight = strText.Mid(nPos+1);
strRight.TrimLeft();
strRight.TrimRight();
if ("SERVER"==strLeft)
SERVER=strRight;
if ("DATABASE"==strLeft)
DATABASE=strRight;
if ("UID"==strLeft)
UID=strRight;
if ("PWD"==strLeft)
PWD=strRight;
if (("ServerDBIP"==strLeft)&&(strRight!=""))
ServerDBIP=strRight;
nIndex++;
}
file.Close();
}
else
{
AfxMessageBox("数据库配置文件错误!");
return FALSE;
} /*
if(m_adoConnection.ConnectSQLServer(_T("CRE-GVA"),_T("Monitor"),_T("sa"),_T("123")))
{
m_adoRecordSet.SetAdoConnection(&m_adoConnection);
m_adoRecordSet.SetCursorLocation();
}
else
{
AfxMessageBox("数据库连接失败!");
}*/
return TRUE;
}
建议你在CMainFrame的OnCreate()中读取配置文件并建立数据库连接。