⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nserver.cpp

📁 数据库服务
💻 CPP
字号:
// NServer.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "NServer.h"
#include "DlgMain.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CNServerApp

BEGIN_MESSAGE_MAP(CNServerApp, CWinApp)
	//{{AFX_MSG_MAP(CNServerApp)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CNServerApp construction

CNServerApp::CNServerApp()
{
	// TODO: add construction code here,
	m_ServerIP = "";
	m_ServerPort = 0;
	m_ClientList = NULL;
	m_pListen = NULL;
	m_IsStart = false;
	m_strMainPath = "c:\\";
	m_pMainDlg = NULL;
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CNServerApp object

CNServerApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CNServerApp initialization

BOOL CNServerApp::InitInstance()
{
	AfxEnableControlContainer();
	
	if (!AfxSocketInit())
	{
		AfxMessageBox(CG_IDS_SOCKETS_INIT_FAILED);
		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
	LoadConfig();

	CDlgMain dlg;
	m_pMainWnd = &dlg;
	m_pMainDlg = &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
	}

	SaveConfig();
	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

void CNServerApp::DeleteClient()
{
	Cclient *pList = NULL;
	if(m_ClientList == NULL) return;
	
	pList = m_ClientList;
	m_ClientList = m_ClientList->m_pNext;

	while(pList != NULL){
		pList->Close();
		delete pList;
		pList = m_ClientList;
		if(m_ClientList != NULL)
			m_ClientList = m_ClientList->m_pNext;
	}

	m_ClientList = NULL;
}

void CNServerApp::AddClient(Cclient *pClient)
{
	if(pClient == NULL) return ;

	pClient->m_pNext = m_ClientList;
	m_ClientList = pClient;
}

bool CNServerApp::LoadConfig()
{
	char Vals[100];
	
	HKEY hk;
	DWORD rc = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\MyAppServer\\",&hk);
	if(rc != ERROR_SUCCESS)	return false;
	
	DWORD lenIt = 100;
	DWORD dType;

	if(RegQueryValueEx(hk, "Server IP", NULL, &dType, (BYTE *)Vals, &lenIt) == ERROR_SUCCESS){
		m_ServerIP=(CString)Vals;
		if(strlen(m_ServerIP)<=0)	return false;
	}
	else
		return false ;

	lenIt = 100;
	if (RegQueryValueEx(hk, "Server Port", NULL, &dType, (BYTE *)&m_ServerPort, &lenIt) != ERROR_SUCCESS){
		m_ServerPort = 0;
		return false;
	}

	lenIt = 100;
	if(RegQueryValueEx(hk, "Main Path", NULL, &dType, (BYTE *)Vals, &lenIt) == ERROR_SUCCESS){
		m_strMainPath=(CString)Vals;
		if(strlen(m_strMainPath) <= 0)
			m_strMainPath = "c:\\";
	}
	else
		m_strMainPath = "c:\\";

	::RegCloseKey(hk);

	return true;
}

bool CNServerApp::SaveConfig()
{
	CString str = "";
	HKEY hKey;

    if (ERROR_SUCCESS != ::RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\MyAppServer\\", &hKey)) 
		return false;
	
	try{	

		RegSetValueEx(hKey, "Server IP",   0, REG_SZ, (LPBYTE)(LPCSTR)m_ServerIP, m_ServerIP.GetLength()+1);
		RegSetValueEx(hKey, "Server Port", NULL, REG_DWORD, (BYTE *)&m_ServerPort, sizeof(m_ServerPort));
		RegSetValueEx(hKey, "Main Path",   0, REG_SZ, (LPBYTE)(LPCSTR)m_strMainPath, m_strMainPath.GetLength()+1);
		
		::RegCloseKey(hKey);
		return true;
	}
	catch(...){
		return false;	
	}

}

void CNServerApp::AddLog(CString ComeCode,CString ComeName,CString LogCont)
{
	m_pMainDlg->AddLog(ComeCode,ComeName,LogCont);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -