📄 ncap.cpp
字号:
// Ncap.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Ncap.h"
#include "NcapDlg.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNcapApp
BEGIN_MESSAGE_MAP(CNcapApp, CWinApp)
//{{AFX_MSG_MAP(CNcapApp)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CNcapApp construction
CNcapApp::CNcapApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CNcapApp object
CNcapApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CNcapApp initialization
//-------------------------------------------------------------------------------------------------
// 主程序初始化:读取配置文件数据,数据库连接,读取系统初始化参数。
//-------------------------------------------------------------------------------------------------
BOOL CNcapApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
::CoInitialize(NULL); //初始化com
//读取配置文件数据:config.ini
CString v_sDatabase_name,v_sDatabase_user,v_sDatabase_password;
char v_cBuffer[128];
a_iDatabase_Type=GetPrivateProfileInt("DATABASE_TYPE","DATABASE_TYPE",0,".\\config.ini");
//获得数据库类型
GetPrivateProfileString("DATABASE_SERVER","DATABASE_SERVER",NULL,v_cBuffer,128,".\\config.ini");
a_sDatabase_Ip.Format("%s",v_cBuffer); //数据库服务器地址
GetPrivateProfileString("DATABASE_NAME","DATABASE_NAME",NULL,v_cBuffer,128,".\\config.ini");
a_sDatabase_Name.Format("%s",v_cBuffer); //获得数据库名称
GetPrivateProfileString("DATABASE_USER","DATABASE_USER",NULL,v_cBuffer,128,".\\config.ini");
a_sDatabase_User.Format("%s",v_cBuffer); //获得数据库用户
GetPrivateProfileString("DATABASE_PASSWORD","DATABASE_PASSWORD",NULL,v_cBuffer,128,".\\config.ini");
a_sDatabase_Password.Format("%s",v_cBuffer); //获得数据库密码
if (a_sDatabase_Name.IsEmpty()) //参数设置失败
{
MessageBox(NULL,"\r\n\r\n config.ini 配置文件读取错误 !!! \r\n\r\n","信息提示",MB_OK);
//显示错误信息
return false; //错误返回
}
a_sXunit="t";
//读取数据库初始化数据
try
{
ADOConn v_cAdoConn; // 数据库实例
v_cAdoConn.OnInitADOConn(a_iDatabase_Type,a_sDatabase_Ip,a_sDatabase_Name,a_sDatabase_User,a_sDatabase_Password);
// 连接数据库
if (!v_cAdoConn.m_bFlag)
return false; //错误返回
}
catch(_com_error e) //捕捉异常
{
CString errormessage;
errormessage.Format(" 数据库连接失败! \r\n\r\n 错误信息:%s%s",e.ErrorMessage()," ");
MessageBox(NULL,errormessage,"信息提示",MB_OK); //显示错误信息
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
CNcapDlg 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 + -