【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-Two.cpp,希望本篇文章对您学习有所帮助。
// Two.cpp : 定义应用程序的类行为。
//
#include "stdafx.h"
#include "Two.h"
#include "TwoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTwoApp
BEGIN_MESSAGE_MAP(CTwoApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
// CTwoApp 构造
CTwoApp::CTwoApp()
{
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的一个 CTwoApp 对象
CTwoApp theApp;
// CTwoApp 初始化
BOOL CTwoApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControls()。否则,将无法创建窗口。
/* InitCommonControls();
CWinApp::InitInstance();
AfxEnableControlContainer();
AfxOleInit(); */
AfxEnableControlContainer();
AfxOleInit();
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的
注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
SetRegistryKey(_T("应用
程序向导生成的本地应用程序"));
//建立和数据库的连接
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(hr))
{
m_pConnection->ConnectionTimeout=5;
hr = m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=employee.mdb","","",adModeUnknown);///连接数据库
//hr=m_pConnection->Open("Data Source=employee_DS;UID=;PWD=;","","",adModeUnknown);
}
}
catch(_com_error e)
{ CString errormessage;
errormessage.Format("连接数据库失败\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
return FALSE;
}
CTwoDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE;
}