📄 resultofping.cpp
字号:
// ResultOfPing.cpp : 实现文件
//
#include "stdafx.h"
#include "NetExplorer.h"
#include "ResultOfPing.h"
#include ".\resultofping.h"
#include "ThreadFunc.h"
// CResultOfPing 对话框
IMPLEMENT_DYNAMIC(CResultOfPing, CDialog)
CResultOfPing::CResultOfPing(CWnd* pParent /*=NULL*/)
: CDialog(CResultOfPing::IDD, pParent)
, HostInformation(_T(""))
, ChosenIpString(_T(""))
{
this->IfCreate=true;
// this->DestIP=0;
this->NetMask=inet_addr("255.255.255.0");
}
CResultOfPing::~CResultOfPing()
{
}
void CResultOfPing::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, HostInformation);
DDX_Control(pDX, IDC_BUTTON2, CButtonStop);
DDX_Control(pDX, IDC_BUTTON1, CButtonStart);
DDX_Control(pDX, IDC_COMBO1, CComboBoxCtrl);
DDX_Control(pDX, IDC_EDIT1, CEditCtrl);
DDX_CBString(pDX, IDC_COMBO1, ChosenIpString);
}
BEGIN_MESSAGE_MAP(CResultOfPing, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedStartPing)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedStopPing)
ON_WM_CLOSE()
ON_MESSAGE(WM_PING,OnPing)
ON_MESSAGE(WM_PING_FINISH,OnPingFinish)
ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
ON_WM_CREATE()
ON_WM_CHAR()
END_MESSAGE_MAP()
// CResultOfPing 消息处理程序
LRESULT CResultOfPing::OnPing(WPARAM wp,LPARAM lp)
{
if(this->ThreadPara.Stop==false)
{
this->HostInformation.Append(this->Buffer);
memset(this->Buffer,0,128);
this->UpdateData(false);
this->CEditCtrl.LineScroll(this->CEditCtrl.GetLineCount());
}
return 0;
}
LRESULT CResultOfPing::OnPingFinish(WPARAM wp,LPARAM lp)
{
this->CButtonStop.EnableWindow(false);
this->ThreadPara.Stop=true;
this->HostInformation.Append("探测过程已经结束");
this->UpdateData(false);
this->CEditCtrl.LineScroll(this->CEditCtrl.GetLineCount());
return 0;
}
void CResultOfPing::OnBnClickedStartPing()
{
// TODO: 在此添加控件通知处理程序代码
this->UpdateData();
ULONG DestIP=inet_addr(this->ChosenIpString.GetBuffer());
if (DestIP==INADDR_NONE||DestIP==0)
{
this->MessageBox("输入错误,请重新输入!","Error",MB_OK|MB_ICONWARNING);
return;
}
this->CButtonStop.EnableWindow(true);
this->CButtonStart.EnableWindow(false);
////////////
this->ThreadPara.Buffer=this->Buffer;
this->ThreadPara.HostIP=DestIP;//this->ChosenIp;/////////////////////////////////////
this->ThreadPara.NetMask=this->NetMask;
this->ThreadPara.MessageHandler=this;
this->ThreadPara.Stop=false;
//CEditCtrl.sets
AfxBeginThread(MyPingProc,&(this->ThreadPara));
this->HostInformation.Append("探测过程开始……\r\n");
this->UpdateData(false);
}
void CResultOfPing::OnBnClickedStopPing()
{
// TODO: 在此添加控件通知处理程序代码
this->CButtonStop.EnableWindow(false);
this->ThreadPara.Stop=true;
this->HostInformation.Append("探测过程已经停止");
this->UpdateData(false);
this->CEditCtrl.LineScroll(this->CEditCtrl.GetLineCount());
}
void CResultOfPing::OnClose()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
this->HostInformation.Empty();
this->ThreadPara.Stop=true;
CDialog::OnClose();
this->IfCreate=true;
}
void CResultOfPing::OnCbnSelchangeCombo1()
{
// TODO: 在此添加控件通知处理程序代码
int Sel=this->CComboBoxCtrl.GetCurSel();
POSITION p=this->DestIP.GetHeadPosition();
for(int i=0;i<Sel;i++)
{
this->DestIP.GetNext(p);
}
this->ChosenIp=this->DestIP.GetAt(p);
}
int CResultOfPing::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
//
return 0;
}
void CResultOfPing::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDialog::OnChar(nChar, nRepCnt, nFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -