📄 pshtwiz1.cpp
字号:
//this file is part of eMule
//Copyright (C)2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdafx.h"
#include <afxinet.h>
#include "emule.h"
#include "enbitmap.h"
#include "OtherFunctions.h"
#include "Preferences.h"
#include "emuledlg.h"
#include "Statistics.h"
#include "ListenSocket.h"
#include "ClientUDPSocket.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
///////////////////////////////////////////////////////////////////////////////
// CDlgPageWizard dialog
class CDlgPageWizard : public CPropertyPageEx
{
DECLARE_DYNCREATE(CDlgPageWizard)
// Construction
public:
CDlgPageWizard();
CDlgPageWizard(UINT nIDTemplate, LPCTSTR pszCaption = NULL, LPCTSTR pszHeaderTitle = NULL, LPCTSTR pszHeaderSubTitle = NULL)
: CPropertyPageEx(nIDTemplate)
{
if (pszCaption)
{
m_strCaption = pszCaption; // "convenience storage"
m_psp.pszTitle = m_strCaption;
m_psp.dwFlags |= PSP_USETITLE;
}
if (pszHeaderTitle && pszHeaderTitle[0] != _T('\0'))
{
m_strHeaderTitle = pszHeaderTitle;
m_psp.dwSize = sizeof(m_psp);
}
if (pszHeaderSubTitle && pszHeaderSubTitle[0] != _T('\0'))
{
m_strHeaderSubTitle = pszHeaderSubTitle;
m_psp.dwSize = sizeof(m_psp);
}
}
~CDlgPageWizard(){}
// Dialog Data
// Overrides
public:
virtual BOOL OnSetActive();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
CString m_strCaption;
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(CDlgPageWizard, CPropertyPageEx)
BEGIN_MESSAGE_MAP(CDlgPageWizard, CPropertyPageEx)
END_MESSAGE_MAP()
CDlgPageWizard::CDlgPageWizard()
: CPropertyPageEx()
{
}
void CDlgPageWizard::DoDataExchange(CDataExchange* pDX)
{
CPropertyPageEx::DoDataExchange(pDX);
}
BOOL CDlgPageWizard::OnSetActive()
{
CPropertySheetEx* pSheet = (CPropertySheetEx*)GetParent();
if (pSheet->IsWizard())
{
int iPages = pSheet->GetPageCount();
int iActPage = pSheet->GetActiveIndex();
DWORD dwButtons = 0;
if (iActPage > 0)
dwButtons |= PSWIZB_BACK;
if (iActPage < iPages)
dwButtons |= PSWIZB_NEXT;
if (iActPage == iPages-1)
{
if (pSheet->m_psh.dwFlags & PSH_WIZARDHASFINISH)
dwButtons &= ~PSWIZB_NEXT;
dwButtons |= PSWIZB_FINISH;
}
pSheet->SetWizardButtons(dwButtons);
}
return CPropertyPageEx::OnSetActive();
}
///////////////////////////////////////////////////////////////////////////////
// CPPgWiz1Welcome dialog
class CPPgWiz1Welcome : public CDlgPageWizard
{
DECLARE_DYNAMIC(CPPgWiz1Welcome)
public:
CPPgWiz1Welcome();
CPPgWiz1Welcome(UINT nIDTemplate, LPCTSTR pszCaption = NULL, LPCTSTR pszHeaderTitle = NULL, LPCTSTR pszHeaderSubTitle = NULL)
: CDlgPageWizard(nIDTemplate, pszCaption, pszHeaderTitle, pszHeaderSubTitle)
{
}
virtual ~CPPgWiz1Welcome();
virtual BOOL OnInitDialog();
// Dialog Data
enum { IDD = IDD_WIZ1_WELCOME };
protected:
CFont m_FontTitle;
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNAMIC(CPPgWiz1Welcome, CDlgPageWizard)
BEGIN_MESSAGE_MAP(CPPgWiz1Welcome, CDlgPageWizard)
END_MESSAGE_MAP()
CPPgWiz1Welcome::CPPgWiz1Welcome()
: CDlgPageWizard(CPPgWiz1Welcome::IDD)
{
}
CPPgWiz1Welcome::~CPPgWiz1Welcome()
{
}
void CPPgWiz1Welcome::DoDataExchange(CDataExchange* pDX)
{
CDlgPageWizard::DoDataExchange(pDX);
}
BOOL CPPgWiz1Welcome::OnInitDialog()
{
CFont fontVerdanaBold;
fontVerdanaBold.CreatePointFont(120, _T("Verdana Bold"));
LOGFONT lf;
fontVerdanaBold.GetLogFont(&lf);
lf.lfWeight = FW_BOLD;
m_FontTitle.CreateFontIndirect(&lf);
CStatic* pStatic = (CStatic*)GetDlgItem(IDC_WIZ1_TITLE);
pStatic->SetFont(&m_FontTitle);
CDlgPageWizard::OnInitDialog();
InitWindowStyles(this);
GetDlgItem(IDC_WIZ1_TITLE)->SetWindowText(GetResString(IDS_WIZ1_WELCOME_TITLE));
GetDlgItem(IDC_WIZ1_ACTIONS)->SetWindowText(GetResString(IDS_WIZ1_WELCOME_ACTIONS));
GetDlgItem(IDC_WIZ1_BTN_HINT)->SetWindowText(GetResString(IDS_WIZ1_WELCOME_BTN_HINT));
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// CPPgWiz1General dialog
class CPPgWiz1General : public CDlgPageWizard
{
DECLARE_DYNAMIC(CPPgWiz1General)
public:
CPPgWiz1General();
CPPgWiz1General(UINT nIDTemplate, LPCTSTR pszCaption = NULL, LPCTSTR pszHeaderTitle = NULL, LPCTSTR pszHeaderSubTitle = NULL)
: CDlgPageWizard(nIDTemplate, pszCaption, pszHeaderTitle, pszHeaderSubTitle)
{
m_iAutoConnectAtStart = 1; //VeryCD版,修改两处默认
m_iAutoStart = 1;
}
virtual ~CPPgWiz1General();
virtual BOOL OnInitDialog();
// Dialog Data
enum { IDD = IDD_WIZ1_GENERAL };
CString m_strNick;
int m_iAutoConnectAtStart;
int m_iAutoStart;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNAMIC(CPPgWiz1General, CDlgPageWizard)
BEGIN_MESSAGE_MAP(CPPgWiz1General, CDlgPageWizard)
END_MESSAGE_MAP()
CPPgWiz1General::CPPgWiz1General()
: CDlgPageWizard(CPPgWiz1General::IDD)
{
m_iAutoConnectAtStart = 1; //VeryCD版,修改两处默认
m_iAutoStart = 1;
}
CPPgWiz1General::~CPPgWiz1General()
{
}
void CPPgWiz1General::DoDataExchange(CDataExchange* pDX)
{
CDlgPageWizard::DoDataExchange(pDX);
DDX_Text(pDX, IDC_NICK, m_strNick);
DDX_Check(pDX, IDC_AUTOCONNECT, m_iAutoConnectAtStart);
DDX_Check(pDX, IDC_AUTOSTART, m_iAutoStart);
}
BOOL CPPgWiz1General::OnInitDialog()
{
CDlgPageWizard::OnInitDialog();
InitWindowStyles(this);
((CEdit*)GetDlgItem(IDC_NICK))->SetLimitText(thePrefs.GetMaxUserNickLength());
GetDlgItem(IDC_NICK_FRM)->SetWindowText(GetResString(IDS_ENTERUSERNAME));
GetDlgItem(IDC_AUTOCONNECT)->SetWindowText(GetResString(IDS_FIRSTAUTOCON));
GetDlgItem(IDC_AUTOSTART)->SetWindowText(GetResString(IDS_WIZ_STARTWITHWINDOWS));
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// CPPgWiz1Ports & Connections test dialog
class CPPgWiz1Ports : public CDlgPageWizard
{
DECLARE_DYNAMIC(CPPgWiz1Ports)
public:
CPPgWiz1Ports();
CPPgWiz1Ports(UINT nIDTemplate, LPCTSTR pszCaption = NULL, LPCTSTR pszHeaderTitle = NULL, LPCTSTR pszHeaderSubTitle = NULL)
: CDlgPageWizard(nIDTemplate, pszCaption, pszHeaderTitle, pszHeaderSubTitle)
{
}
void ValidateShownPorts();
virtual ~CPPgWiz1Ports();
virtual BOOL OnInitDialog();
afx_msg void OnStartConTest();
afx_msg void OnEnChangeUDPDisable();
afx_msg void OnEnChangeUDP();
afx_msg void OnEnChangeTCP();
void OnPortChange(uint8 tcpport);
CString m_sTestURL,m_sUDP,m_sTCP;
uint16 GetTCPPort();
uint16 GetUDPPort();
// Dialog Data
enum { IDD = IDD_WIZ1_PORTS };
protected:
CString lastudp;
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNAMIC(CPPgWiz1Ports, CDlgPageWizard)
CPPgWiz1Ports::CPPgWiz1Ports()
: CDlgPageWizard(CPPgWiz1Ports::IDD)
{
}
CPPgWiz1Ports::~CPPgWiz1Ports()
{
}
void CPPgWiz1Ports::DoDataExchange(CDataExchange* pDX)
{
CDlgPageWizard::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPPgWiz1Ports)
DDX_Text(pDX, IDC_TCP, m_sTCP);
DDX_Text(pDX, IDC_UDP, m_sUDP);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPPgWiz1Ports, CDlgPageWizard)
//{{AFX_MSG_MAP(CPPgWiz1Ports)
ON_BN_CLICKED(IDC_STARTTEST, OnStartConTest)
ON_BN_CLICKED(IDC_UDPDISABLE, OnEnChangeUDPDisable)
ON_EN_CHANGE(IDC_TCP, OnEnChangeTCP)
ON_EN_CHANGE(IDC_UDP, OnEnChangeUDP)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CPPgWiz1Ports::OnEnChangeTCP() {
OnPortChange(1);
}
void CPPgWiz1Ports::OnEnChangeUDP() {
OnPortChange(0);
}
uint16 CPPgWiz1Ports::GetTCPPort() {
CString buffer;
GetDlgItem(IDC_TCP)->GetWindowText(buffer);
return _tstoi(buffer);
}
uint16 CPPgWiz1Ports::GetUDPPort() {
uint16 udp=0;
CString buffer;
if (!IsDlgButtonChecked(IDC_UDPDISABLE)) {
GetDlgItem(IDC_UDP)->GetWindowText(buffer);
udp=_tstoi(buffer); //GetUDPPort();
}
return udp;
}
/*
uint16 CPPgWiz1Ports::GetTCPPort() {
return _tstoi(m_sTCP);
}
uint16 CPPgWiz1Ports::GetUDPPort() {
if (IsDlgButtonChecked(IDC_UDPDISABLE))
return 0;
else
return _tstoi(m_sUDP);
}
*/
void CPPgWiz1Ports::OnPortChange(uint8 tcpport) {
bool flag= (theApp.IsPortchangeAllowed() &&
(
(theApp.listensocket->GetConnectedPort()!=GetTCPPort() || theApp.listensocket->GetConnectedPort()==0)
||
(theApp.clientudp->GetConnectedPort()!=GetUDPPort() || theApp.clientudp->GetConnectedPort()==0 )
)
);
GetDlgItem(IDC_STARTTEST)->EnableWindow(flag);
}
void CPPgWiz1Ports::OnStartConTest() {
uint16 tcp=GetTCPPort();
uint16 udp=GetUDPPort();
if (tcp==0)
return;
if ( (tcp!=theApp.listensocket->GetConnectedPort() || udp!=theApp.clientudp->GetConnectedPort() ) ) {
if (!theApp.IsPortchangeAllowed()) {
AfxMessageBox(GetResString(IDS_NOPORTCHANGEPOSSIBLE));
return;
}
// set new ports
thePrefs.port=tcp;
thePrefs.udpport=udp;
theApp.listensocket->Rebind() ;
theApp.clientudp->Rebind();
}
TriggerPortTest(tcp,udp);
}
BOOL CPPgWiz1Ports::OnInitDialog()
{
CDlgPageWizard::OnInitDialog();
InitWindowStyles(this);
lastudp = m_sUDP;
// disable changing ports to prevent harm
SetDlgItemText(IDC_PORTINFO , GetResString(IDS_PORTINFO) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -