📄 netmsg.cpp
字号:
// NetMsg.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "NetMsg.h"
#include "NetMsgDlg.h"
#include "ChatDlg.h"
#include "FileTranDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNetMsgApp
BEGIN_MESSAGE_MAP(CNetMsgApp, CWinApp)
//{{AFX_MSG_MAP(CNetMsgApp)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CNetMsgApp construction
//##ModelId=3E322F9F0049
CNetMsgApp::CNetMsgApp() : m_mutexApp(FALSE, "___NetMsg___")
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CNetMsgApp object
CNetMsgApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CNetMsgApp initialization
//##ModelId=3E322F9F004A
BOOL CNetMsgApp::InitInstance()
{
//检查系统是否已经正在运行?
if (!m_mutexApp.Lock(100))
{
TRACE("App already running...\n");
return FALSE;
}
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// 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
//
//取得程序运行的目录
//
TCHAR exeFullPath[MAX_PATH]; // MAX_PATH在API中定义:128
char szDrive[_MAX_DRIVE]={0}, szDir[_MAX_DIR]={0}
, szFName[_MAX_FNAME]={0}, szExt[_MAX_EXT]={0};
GetModuleFileName(AfxGetInstanceHandle(), exeFullPath, sizeof(exeFullPath));
_splitpath(exeFullPath, szDrive, szDir, NULL, NULL);
m_strWorkDIR.Format("%s%s", szDrive, szDir);
::CoInitialize(NULL); // 初始化COM环境,for XML
//{{Init the system
bool bRet = false;
try
{
MSXML::IXMLDOMDocumentPtr xmlDoc(__uuidof(MSXML::DOMDocument));
xmlDoc->MSXML::IXMLDOMDocument::async = false; //同步加载XML文件
xmlDoc->MSXML::IXMLDOMDocument::load((const char *)(m_strWorkDIR + "conf\\config.xml"));
//读朋友功能的端口配置
CNetMsgDlg::shortFriendPort = atoi((const char *)xmlDoc->MSXML::IXMLDOMDocument::selectSingleNode("NMSystem/Friend/Port")->text);
//读聊天功能的端口配置
CChatDlg::shortChatPort = atoi((const char *)xmlDoc->MSXML::IXMLDOMDocument::selectSingleNode("NMSystem/Chat/Port")->text);
//读文件传输的端口配置
CFileTranDlg::shortFilePort= atoi((const char *)xmlDoc->MSXML::IXMLDOMDocument::selectSingleNode("NMSystem/File/Port")->text);
bRet = true;
}
catch(_com_error &err)
{
CString strErr = "加载config.xml失败";
strErr += (const char *)err.Description();
AfxMessageBox(strErr);
}
//}}
CNetMsgDlg 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;
}
//##ModelId=3E32A3070182
int CNetMsgApp::ExitInstance()
{
::CoUninitialize(); //Release COM environment
m_mutexApp.Unlock();
return CWinApp::ExitInstance();
}
//##ModelId=3E3430ED037D
const CString& CNetMsgApp::get_WorkDIR() const
{
return m_strWorkDIR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -