📄 portconfigdlg.cpp
字号:
// PortConfigDlg.cpp : implementation file
//
#include "stdafx.h"
#include "netfinder.h"
#include "PortConfigDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CNetfinderApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CPortConfigDlg dialog
CPortConfigDlg::CPortConfigDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPortConfigDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPortConfigDlg)
m_add_portnum = 0;
//}}AFX_DATA_INIT
}
void CPortConfigDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPortConfigDlg)
DDX_Control(pDX, IDC_LIST1, m_portlist_display);
DDX_Text(pDX, IDC_EDIT1, m_add_portnum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPortConfigDlg, CDialog)
//{{AFX_MSG_MAP(CPortConfigDlg)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_REMOVE, OnRemove)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPortConfigDlg message handlers
BOOL CPortConfigDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
unsigned int i;
for(i = 0; i < theApp.m_numports; i++){
AddPort(theApp.m_ports[i]);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPortConfigDlg::AddPort(unsigned int port)
{
CString str;
int index;
str.Format("%i", port);
m_portlist_display.AddString(str);
index = m_portlist_display.FindStringExact(-1, str);
if(index != LB_ERR){
m_portlist_display.SetItemData(index, port);
} else {
AfxMessageBox("LB_ERR when adding port to list box");
}
}
void CPortConfigDlg::OnAdd()
{
// TODO: Add your control notification handler code here
UpdateData();
if((m_portlist_display.GetCount() + 1) > MAX_NUM_PORTS){
AfxMessageBox("Error: Exceeded Maximum Number of Ports");
return;
}
// Check for too many ports
if((m_portlist_display.GetCount() + 1) > MAX_NUM_PORTS){
AfxMessageBox("Error: Exceeded Maximum Number of Ports");
return;
}
// Check for duplicates
CString str;
str.Format("%i", m_add_portnum);
int index = m_portlist_display.FindStringExact(-1, str);
if(index != LB_ERR){
AfxMessageBox("Error: Duplicate Port");
return;
}
// Check for invalid port number
if((m_add_portnum < 1024) || (m_add_portnum > 65535)){
AfxMessageBox("Error: Invalid Port ( 1024 >= port >= 65535)");
return;
}
AddPort(m_add_portnum);
}
void CPortConfigDlg::OnOK()
{
// TODO: Add extra validation here
theApp.m_numports = m_portlist_display.GetCount();
unsigned int i;
for(i = 0; i < theApp.m_numports; i++){
theApp.m_ports[i] = m_portlist_display.GetItemData(i);
}
CDialog::OnOK();
}
void CPortConfigDlg::OnRemove()
{
// TODO: Add your control notification handler code here
int index;
index = m_portlist_display.GetCurSel();
if(index == LB_ERR){
AfxMessageBox("Please select a port to remove");
return;
}
m_portlist_display.DeleteString(index);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -