📄 mypager.cpp
字号:
// myPager.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "myPager.h"
#include "myPagerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyPagerApp
BEGIN_MESSAGE_MAP(CMyPagerApp, CWinApp)
//{{AFX_MSG_MAP(CMyPagerApp)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CMyPagerApp construction
CMyPagerApp::CMyPagerApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMyPagerApp object
CMyPagerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMyPagerApp initialization
BOOL CMyPagerApp::InitInstance()
{
/* if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
*/
AfxEnableControlContainer();
AfxOleInit();///初始化COM库
////////////连接数据库//////////////
char v_sPath[100];
GetCurrentDirectory(50,v_sPath);
CString v_sTemp=v_sPath;
v_sTemp="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+v_sTemp+"\\pager.mdb";
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open((_bstr_t)v_sTemp,"","",adModeUnknown);
//上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,需要改为:Provider=Microsoft.Jet.OLEDB.3.51; }
// (1)通过JET数据库引擎对ACCESS2000数据库的连接
// m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\test.mdb","","",adModeUnknown);
// (2)通过DSN数据源对任何支持ODBC的数据库进行连接:
// m_pConnection->Open("Data Source=adotest;UID=sa;PWD=;","","",adModeUnknown);
// (3)不通过DSN对SQL SERVER数据库进行连接:
// m_pConnection->Open("driver={SQL Server};Server=127.0.0.1;DATABASE=vckbase;UID=sa;PWD=139","","",adModeUnknown);
// 其中Server是SQL服务器的名称,DATABASE是库的名称
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("数据库连接失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
return FALSE;
}
// 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.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// CUSER_LOGINDlg UserDlg;
// UserDlg.DoModal();
CMyPagerDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -