📄 regnetsetdlg.cpp
字号:
// RegNetSet.cpp : implementation file
//
#include "stdafx.h"
#include "wbQQClient.h"
#include "RegNetSetDlg.h"
#include "WbQQClientDlg.h"
#include "RegWizard.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
bool CRegNetSetDlg::bRegSuc = false;
/////////////////////////////////////////////////////////////////////////////
// CRegNetSetDlg property page
IMPLEMENT_DYNCREATE(CRegNetSetDlg, CPropertyPage)
CRegNetSetDlg::CRegNetSetDlg() : CPropertyPage(CRegNetSetDlg::IDD)
{
//{{AFX_DATA_INIT(CRegNetSetDlg)
m_nPort = 0;
m_IPAddr = _T("");
m_IPAddrChat = _T("");
m_nPortChat = 0;
//}}AFX_DATA_INIT
}
CRegNetSetDlg::~CRegNetSetDlg()
{
}
void CRegNetSetDlg::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRegNetSetDlg)
DDX_Text(pDX, IDC_EDIT_REG_PORT, m_nPort);
DDV_MinMaxInt(pDX, m_nPort, 0, 65535);
DDX_Text(pDX, IDC_EDIT_IPADDR, m_IPAddr);
DDX_Text(pDX, IDC_EDIT_CHAT_IPADDR, m_IPAddrChat);
DDX_Text(pDX, IDC_EDIT_CHAT_PORT, m_nPortChat);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRegNetSetDlg, CPropertyPage)
//{{AFX_MSG_MAP(CRegNetSetDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRegNetSetDlg message handlers
BOOL CRegNetSetDlg::OnSetActive()
{
// TODO: Add your specialized code here and/or call the base class
CPropertySheet* psheet = (CPropertySheet*) GetParent();
psheet->SetWizardButtons(PSWIZB_FINISH);
psheet->SetFinishText("完成");
return CPropertyPage::OnSetActive();
}
BOOL CRegNetSetDlg::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
InitNetSet();
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CRegNetSetDlg::OnWizardFinish()
{
// TODO: Add your specialized code here and/or call the base class
UpdateData(true);
SaveNetSet();
if (Register())
{
SetRegTrue();
}
else
{
SetRegFalse();
}
return CPropertyPage::OnWizardFinish();
}
bool CRegNetSetDlg::Register()
{
CRegWizard *pWiz = (CRegWizard*)GetParent();
return pWiz->Register();
}
void CRegNetSetDlg::OnCancel()
{
// TODO: Add your specialized code here and/or call the base class
CPropertyPage::OnCancel();
}
void CRegNetSetDlg::SetRegTrue() //静态函数,设置表态变量bRegSuc
{
bRegSuc = true;
}
void CRegNetSetDlg::SetRegFalse() //静态函数,设置表态变量bRegSuc
{
bRegSuc = false;
}
bool CRegNetSetDlg::SaveNetSet() //保存网络设置
{
CString fileName;
fileName.Format(".\\data\\netset.cfg");
FILE *pFile;
if ((pFile = fopen(fileName, "w")) != NULL)
{
fprintf(pFile, "%s,%d,%s,%d", m_IPAddr, m_nPort,
m_IPAddrChat, m_nPortChat);
fclose(pFile);
}
return true;
}
bool CRegNetSetDlg::InitNetSet() //读取网络设置并初始化
{
CString fileName;
fileName.Format(".\\data\\netset.cfg");
FILE *pFile;
if ((pFile = fopen(fileName, "r")) != NULL)
{
char ch = 's';
char IPAddr[20];
char port[10];
char IPAddrChat[20];
char portChat[10];
for (int i=0; ch != ','; i++)
{
ch = fgetc(pFile);
IPAddr[i] = ch;
}
IPAddr[--i] = '\0';
m_IPAddr.Format(IPAddr);
ch = 's';
for (i=0; ch != ','; i++)
{
ch=fgetc(pFile);
port[i] = ch;
}
port[--i] = '\0';
m_nPort = atoi(port);
ch = 's';
for (i=0; ch != ','; i++)
{
ch = fgetc(pFile);
IPAddrChat[i] = ch;
}
IPAddrChat[--i] = '\0';
m_IPAddrChat.Format(IPAddrChat);
ch = 's';
for (i=0; !feof(pFile); i++)
{
portChat[i] = fgetc(pFile);
}
portChat[--i] = '\0';
m_nPortChat = atoi(portChat);
fclose(pFile);
}
else
{
m_IPAddr = "127.0.0.1";
m_nPort = 1975;
m_IPAddrChat = "127.0.0.1";
m_nPortChat = 1976;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -