📄 arpreqdlg.cpp
字号:
// arpReqDlg.cpp : implementation file
//
#include "stdafx.h"
#include "arpReq.h"
#include "arpReqDlg.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <iphlpapi.h>
#include ".\arpreqdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
BOOL SendArpReq();
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CArpReqDlg dialog
CArpReqDlg::CArpReqDlg(CWnd* pParent /*=NULL*/)
: CDialog(CArpReqDlg::IDD, pParent)
, m_pSendArpReqThread(NULL)
{
//{{AFX_DATA_INIT(CArpReqDlg)
m_3kms = -1;
m_1kms = -1;
m_300ms = -1;
m_100ms = -1;
m_EndNum = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CArpReqDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CArpReqDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
DDX_Control(pDX, IDC_IPADDRESS1, m_IpAddr);
DDX_Radio(pDX, IDC_RADIO1, m_3kms);
DDX_Radio(pDX, IDC_RADIO2, m_1kms);
DDX_Radio(pDX, IDC_RADIO3, m_300ms);
DDX_Radio(pDX, IDC_RADIO4, m_100ms);
DDX_Text(pDX, IDC_END_NUM, m_EndNum);
DDV_MinMaxUInt(pDX, m_EndNum, 1, 254);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CArpReqDlg, CDialog)
//{{AFX_MSG_MAP(CArpReqDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(IPN_FIELDCHANGED, IDC_IPADDRESS1, OnIpAddrFieldchanged)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_PAUSE, OnPause)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_SEND_ARP_REQ, OnSendArpReq)
ON_EN_UPDATE(IDC_END_NUM, OnUpdateEndNum)
//}}AFX_MSG_MAP
ON_NOTIFY(NM_CUSTOMDRAW, IDC_PROGRESS1, OnNMCustomdrawProgress1)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CArpReqDlg message handlers
BOOL CArpReqDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
/*
HRESULT hr;
IPAddr ipAddr;
ULONG pulMac[2];
ULONG ulLen;
ipAddr = inet_addr ("192.168.25.31");
memset (pulMac, 0xff, sizeof (pulMac));
ulLen = 6;
hr = SendARP (ipAddr, 0, pulMac, &ulLen);
*/
return TRUE; // return TRUE unless you set the focus to a control
}
void CArpReqDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CArpReqDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CArpReqDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CArpReqDlg::OnIpAddrFieldchanged(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CArpReqDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
}
void CArpReqDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
}
void CArpReqDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
}
void CArpReqDlg::OnRadio4()
{
// TODO: Add your control notification handler code here
}
void CArpReqDlg::OnPause()
{
// TODO: Add your control notification handler code here
}
void CArpReqDlg::OnStop()
{
// TODO: Add your control notification handler code here
}
void CArpReqDlg::OnSendArpReq()
{
// TODO: Add your control notification handler code here
_param gParam;
gParam.endNum = m_EndNum;
gParam.ipAddr = &m_IpAddr;
m_pSendArpReqThread=AfxBeginThread(
SendArpReq,
&gParam,
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED,
NULL);
ASSERT(m_pSendArpReqThread);
m_pSendArpReqThread->m_bAutoDelete=FALSE;
m_pSendArpReqThread->ResumeThread();
if( m_EndNum>255 || m_EndNum<0 )
{
AfxMessageBox("数字介于0-255");
}
else
{
m_pSendArpReqThread->Run();
}
if( m_pSendArpReqThread!=NULL )
{
DWORD dwExitCode= -1;
VERIFY(GetExitCodeThread(*m_pSendArpReqThread,&dwExitCode));
if(dwExitCode == STILL_ACTIVE )
{
return;
}
delete m_pSendArpReqThread;
m_pSendArpReqThread=NULL;
}
}
UINT SendArpReq( LPVOID pParam )
{
_param* p = (_param*)pParam;
IPAddr ipAddr;
ULONG pulMac[2];
ULONG ulLen;
BYTE ip[4];
p->ipAddr->GetAddress( ip[0],ip[1],ip[2],ip[3] );
p->ipAddr->SetAddress( ip[3],ip[2],ip[1],ip[0] );
p->ipAddr->GetAddress( ipAddr );
p->ipAddr->SetAddress( ip[0],ip[1],ip[2],ip[3] );
//ipAddr = inet_addr ("192.168.1.188");
memset (pulMac, 0xff, sizeof (pulMac));
ulLen = 6;
UINT hr;
UINT i = UINT(ip[3]);
if( p->endNum >i )
{
for( ; i < p->endNum+1 ; i++ )
{
hr = SendARP (ipAddr, 0, pulMac, &ulLen);
ip[3]++;
p->ipAddr->SetAddress( ip[3],ip[2],ip[1],ip[0] );
p->ipAddr->GetAddress( ipAddr );
p->ipAddr->SetAddress( ip[0],ip[1],ip[2],ip[3]-1 );
Sleep(500);
}
}
else
{
AfxMessageBox("终点小于起点错误");
}
return 0;
}
void CArpReqDlg::OnUpdateEndNum()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
BOOL berr;
m_EndNum = GetDlgItemInt(IDC_END_NUM, &berr, FALSE);
if(berr == NULL)
{
AfxMessageBox("出错了!");
}
}
void CArpReqDlg::OnNMCustomdrawProgress1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -