// RouteTraceDlg.cpp : implementation file
//
#include "stdafx.h"
#include "RouteTrace.h"
#include "RouteTraceDlg.h"
#include "afxmt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
struct SubThreadInfo
{
CDialog* pDialog;
CListCtrl* list;
CStatic* state;
CString IPStr;
int Maxhot;
} Info;
CEvent eventStopRoute;
//-----------------路由跟踪线程---------------
UINT ThreadRoute(LPVOID pParam)
{
SubThreadInfo* pInfo = (SubThreadInfo*)pParam;
CRouteTraceDlg* pThreadDlg = (CRouteTraceDlg*)pInfo->pDialog;
CICMP m_icmp;
CString IPStr=pInfo->IPStr;
CString sTTL;
int nTtl;
m_icmp.Initialize();
for(nTtl=1;nTtl<=pInfo->Maxhot;nTtl++)
{
if(m_icmp.SetTTL(nTtl)==0)
return 0;
sTTL.Format("%d",nTtl);
if(m_icmp.SendICMPPack((char *)(LPCSTR)IPStr))
m_icmp.RecvICMPPack();
{
int i=pInfo->list->InsertItem(0,sTTL);
pInfo->list->SetItemText(i,1,m_icmp.routeaddr);
pInfo->list->SetItemText(i,2,m_icmp.RouteState);
pInfo->state->SetWindowText(m_icmp.m_strInfo);
Sleep(100);
}
if(m_icmp.routestate==0)
break;
if(WaitForSingleObject(eventStopRoute.m_hObject, 0) == WAIT_OBJECT_0)
break;
}
pThreadDlg->Routeflag=TRUE;
return 0;
}
//////////////////////////////////////////////////////
class CAboutDlg : public CDialog
{
public:
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()
/////////////////////////////////////////////////////////////////////////////
// CRouteTraceDlg dialog
CRouteTraceDlg::CRouteTraceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRouteTraceDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRouteTraceDlg)
m_maxhot = 30;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CRouteTraceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRouteTraceDlg)
DDX_Control(pDX, IDC_COMBO, m_comb);
DDX_Control(pDX, IDC_STATE, m_statectl);
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Text(pDX, IDC_MAXHOT, m_maxhot);
DDV_MinMaxInt(pDX, m_maxhot, 1, 500);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRouteTraceDlg, CDialog)
//{{AFX_MSG_MAP(CRouteTraceDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_TRACE, OnTrace)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRouteTraceDlg message handlers
BOOL CRouteTraceDlg::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
m_list.InsertColumn(0,"标号",LVCFMT_CENTER,60,0);
m_list.InsertColumn(1,"路由器地址",HDF_CENTER,200,0);
m_list.InsertColumn(2,"状态",HDF_CENTER,100,0);
ListView_SetExtendedListViewStyleEx(m_list.m_hWnd, LVS_EX_FULLROWSELECT, 0xFFFFFFFF);
return TRUE; // return TRUE unless you set the focus to a control
}
void CRouteTraceDlg::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 CRouteTraceDlg::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 CRouteTraceDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRouteTraceDlg::OnTrace()
{
CString str;
UpdateData(TRUE);
CWnd * pWnd;
pWnd = GetDlgItem(IDC_COMBO);
pWnd->GetWindowText(str);
if(str.IsEmpty()) {
MessageBox("请输入地址!");
pWnd->SetFocus();
return;
}
if (m_comb.FindStringExact(-1, str) == CB_ERR)
m_comb.AddString(str);
m_list.DeleteAllItems();
if(Routeflag)
{
Routeflag=FALSE;
Info.IPStr=str;
Info.pDialog=this;
Info.Maxhot=m_maxhot;
Info.list=(&m_list);
Info.state=(&m_statectl);
AfxBeginThread(ThreadRoute, &Info);
}
}
void CRouteTraceDlg::OnStop()
{
if(!Routeflag)
{
eventStopRoute.SetEvent();
}
}
void CRouteTraceDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
m_icmp.Uninitialize();
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ICMP实现路由跟踪.rar (25个子文件)
使用ICMP实现路由跟踪
RouteTrace
StdAfx.h 1010B
Icmp.plg 2KB
RouteTrace.h 1KB
RouteTrace.dsw 543B
RESOURCE.H 963B
RouteTrace.cpp 2KB
RES
RouteTrace.ico 1KB
RouteTrace.rc2 402B
ICMP.H 2KB
Icmp.cpp 5KB
Icmp.dsp 3KB
RouteTrace.dsp 4KB
RouteTraceDlg.h 1KB
Debug
vc60.pdb 76KB
vc60.idb 201KB
Icmp.obj 29KB
Icmp.pch 4.96MB
Icmp.pdb 25KB
RouteTraceDlg.cpp 6KB
Icmp.ncb 33KB
Icmp.opt 48KB
StdAfx.cpp 212B
RouteTrace.clw 1KB
RouteTrace.rc 6KB
Icmp.dsw 516B
共 25 条
- 1
悠哉稻草人
- 粉丝: 4
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页