www.pudn.com > SnmpToplog.rar > MySnmpDlg.cpp


// MySnmpDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "MySnmp.h" 
#include "MySnmpDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
#define SNMP_MSG WM_USER+100 
#define DAY       (24L*60L*60L) 
#define HOUR      (60L*60L) 
#define MINUTE    (60L) 
#define HUNDRED   (100L) 
 
#define LIST_SYSTEMINFO 0 //系统信息 
#define LIST_ROUTETABLE 1 //路由表 
#define LIST_ROUTESUBNET 2 //子网 
#define LIST_ROUTETUOPU 3 //拓扑图 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
typedef struct tagTipData 
{ 
	CPoint point; 
	CString strIP; 
}TipData; 
 
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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMySnmpDlg dialog 
 
CMySnmpDlg::CMySnmpDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CMySnmpDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CMySnmpDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
	m_nListType=-1; 
	m_RightRect.left=m_RightRect.right=m_RightRect.bottom=m_RightRect.top=0; 
	m_pTipDlg=NULL; 
} 
 
void CMySnmpDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CMySnmpDlg) 
	DDX_Control(pDX, IDC_LIST1, m_ctrlListCtrl); 
	DDX_Control(pDX, IDC_IPADDRESS1, m_ctrlIPAddress); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CMySnmpDlg, CDialog) 
	//{{AFX_MSG_MAP(CMySnmpDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_BUTTONSTART, OnButtonstart) 
	ON_BN_CLICKED(IDC_BUTTONSYSTEMINFO, OnButtonsysteminfo) 
	ON_BN_CLICKED(IDC_BUTTONROUTETABLE, OnButtonroutetable) 
	ON_BN_CLICKED(IDC_BUTTONSUBNETINFO, OnButtonsubnetinfo) 
	ON_BN_CLICKED(IDC_BUTTONTUOPU, OnButtontuopu) 
	ON_BN_CLICKED(IDC_BUTTONQUIT, OnButtonquit) 
	ON_BN_CLICKED(IDC_BUTTONABOUT, OnButtonabout) 
	ON_WM_CLOSE() 
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1) 
	ON_WM_LBUTTONDOWN() 
	ON_WM_TIMER() 
	//}}AFX_MSG_MAP 
	ON_MESSAGE(SNMP_MSG,OnReceive) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMySnmpDlg message handlers 
 
BOOL CMySnmpDlg::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_ctrlIPAddress.SetAddress(127,0,0,1); 
	m_ctrlIPAddress.SetFieldFocus(0); 
	CButton* pButton; 
	pButton=(CButton*)this->GetDlgItem(IDC_BUTTONSYSTEMINFO); 
	pButton->EnableWindow(FALSE); 
 
	pButton=(CButton*)this->GetDlgItem(IDC_BUTTONROUTETABLE); 
	pButton->EnableWindow(FALSE); 
 
	pButton=(CButton*)this->GetDlgItem(IDC_BUTTONSUBNETINFO); 
	pButton->EnableWindow(FALSE); 
 
	pButton=(CButton*)this->GetDlgItem(IDC_BUTTONTUOPU); 
	pButton->EnableWindow(FALSE); 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CMySnmpDlg::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 CMySnmpDlg::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 CMySnmpDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CMySnmpDlg::OnOK()  
{ 
	// TODO: Add extra validation here 
	 
//	CDialog::OnOK(); 
} 
 
void CMySnmpDlg::OnButtonstart()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(TRUE); 
	BYTE nField0,nField1,nField2,nField3; 
	m_ctrlIPAddress.GetAddress(nField0,nField1,nField2,nField3); 
	sprintf(m_IPAddress,"%d.%d.%d.%d",nField0,nField1,nField2,nField3); 
	m_Route.m_strAddress=m_IPAddress; 
	//MessageBox(m_IPAddress); 
	if(!InitSnmp()) 
	{ 
		return; 
	} 
	m_messageDlg.Create(IDD_DIALOG1); 
	m_messageDlg.CenterWindow(); 
	m_messageDlg.ShowWindow(SW_SHOW); 
 
	CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTONSTART); 
	pButton->EnableWindow(FALSE); 
	GetRouteInfo(); 
	////////////////////////////////////////////////////////////////////////// 
	//////////////////////////////////////////////////////////////////////////	 
} 
//初始化snmp 
BOOL CMySnmpDlg::InitSnmp() 
{ 
	SNMPAPI_STATUS lStat; 
	//Initialize WinSNMP 
	smiUINT32 nMajorVersion,nMinorVersion,nLevel,nTranslateMode,nRetransmitMode; 
	lStat=SnmpStartup(&nMajorVersion,&nMinorVersion,&nLevel,&nTranslateMode,&nRetransmitMode); 
	if(lStat==SNMPAPI_FAILURE) 
	{ 
		MessageBox("SnmpStartup Error!"); 
		return FALSE; 
	} 
	//设置传输模式 
	lStat=SnmpSetTranslateMode(SNMPAPI_UNTRANSLATED_V1); 
	if(lStat==SNMPAPI_FAILURE) 
	{ 
		MessageBox("SnmpSetTranslateMode Error!"); 
		return FALSE; 
	} 
	//设置重传模式 
	lStat=SnmpSetRetransmitMode(SNMPAPI_ON); 
	if (lStat==SNMPAPI_FAILURE)  
	{ 
		MessageBox("SnmpSetRetransmitMode Error!"); 
		return FALSE; 
	} 
	//创建会话 
	m_hSession=SnmpCreateSession(CMySnmpDlg::m_hWnd,SNMP_MSG,NULL,NULL); 
	if(m_hSession==SNMPAPI_FAILURE) 
	{ 
		MessageBox("SnmpCreateSession Error!"); 
		SnmpCleanup(); 
		return FALSE; 
	} 
	//创建实体句柄 
	m_hDstEntity=SnmpStrToEntity(m_hSession,m_IPAddress); 
	if(m_hDstEntity==SNMPAPI_FAILURE) 
	{ 
		MessageBox("SnmpStrToEntity Error!"); 
		SnmpCleanup(); 
		return FALSE; 
	} 
	//创建上下文句柄 
	smiOCTETS dcTx; 
	char community[]="public"; 
	dcTx.len=strlen(community); 
	dcTx.ptr=(smiLPBYTE)community; 
	m_hContext=SnmpStrToContext(m_hSession,&dcTx); 
	if(m_hContext==SNMPAPI_FAILURE) 
	{ 
		MessageBox("SnmpStrToContext Error!"); 
		SnmpCleanup(); 
		return FALSE; 
	} 
	//创建变量捆绑列表 
	m_hVBL=SnmpCreateVbl(m_hSession,NULL,NULL); 
	if(m_hVBL==SNMPAPI_FAILURE) 
	{ 
		MessageBox("SnmpCreateVbl Error!"); 
		SnmpCleanup(); 
		return FALSE; 
	} 
	return TRUE; 
} 
//开始获取路由器的各种信息 
void CMySnmpDlg::GetRouteInfo() 
{ 
	char sName[100]="1.3.6.1.2.1"; 
	smiOID dName; 
 
	if(SnmpStrToOid(sName,&dName)==SNMPAPI_FAILURE) 
	{ 
		CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTONSTART); 
		pButton->EnableWindow(TRUE); 
		m_messageDlg.ShowWindow(SW_HIDE); 
		m_messageDlg.DestroyWindow(); 
 
		MessageBox("SnmpStrToOid Error!"); 
		SnmpCleanup(); 
		return; 
	} 
	//添加到变量绑定列表 
	if(SnmpSetVb(m_hVBL,0,&dName,NULL)==SNMPAPI_FAILURE) 
	{ 
		CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTONSTART); 
		pButton->EnableWindow(TRUE); 
		m_messageDlg.ShowWindow(SW_HIDE); 
		m_messageDlg.DestroyWindow(); 
 
		MessageBox("SnmpSetVb Error!"); 
		SnmpCleanup(); 
		return; 
	} 
	//创建协议数据单元 
	HSNMP_PDU hPdu=SnmpCreatePdu(m_hSession,SNMP_PDU_GETNEXT,100,0,0,m_hVBL); 
	if(hPdu==SNMPAPI_FAILURE) 
	{ 
		CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTONSTART); 
		pButton->EnableWindow(TRUE); 
		m_messageDlg.ShowWindow(SW_HIDE); 
		m_messageDlg.DestroyWindow(); 
 
		MessageBox("SnmpCreatePdu Error!"); 
		SnmpCleanup(); 
		return; 
	} 
	//发送数据 
	if(SnmpSendMsg(m_hSession,0,m_hDstEntity,m_hContext,hPdu)==SNMPAPI_FAILURE) 
	{ 
		CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTONSTART); 
		pButton->EnableWindow(TRUE); 
		m_messageDlg.ShowWindow(SW_HIDE); 
		m_messageDlg.DestroyWindow(); 
 
		MessageBox("SnmpSendMsg Error!"); 
		SnmpCleanup(); 
		return; 
	} 
} 
void CMySnmpDlg::OnReceive() 
{ 
	//MessageBox("接受到数据");	 
	//接受数据 
	HSNMP_PDU hPdu; 
	if(SnmpRecvMsg(m_hSession,NULL,NULL,NULL,&hPdu)==SNMPAPI_FAILURE) 
	{ 
		CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTONSTART); 
		pButton->EnableWindow(TRUE); 
		m_messageDlg.ShowWindow(SW_HIDE); 
		m_messageDlg.DestroyWindow(); 
 
		MessageBox("SnmpRecvMsg Error!"); 
		SnmpCleanup(); 
		return; 
	} 
	//提取协议数据单元 
	smiINT32 lType, lErr, lIdx,lReqId; 
	HSNMP_VBL hVbl; 
	if(SnmpGetPduData(hPdu,&lType,&lReqId,&lErr,&lIdx,&hVbl)==SNMPAPI_FAILURE) 
	{ 
		CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTONSTART); 
		pButton->EnableWindow(TRUE); 
		m_messageDlg.ShowWindow(SW_HIDE); 
		m_messageDlg.DestroyWindow(); 
 
		MessageBox("SnmpGetPduData Error!"); 
		SnmpCleanup(); 
		return; 
	} 
	if(lErr!=0) 
	{ 
		CButton* pButton=(CButton*)GetDlgItem(IDC_BUTTONSTART); 
		pButton->EnableWindow(TRUE); 
		m_messageDlg.ShowWindow(SW_HIDE); 
		m_messageDlg.DestroyWindow(); 
		CString str; 
		str.Format("SNMP Error for RequestID = %d: Value = %d, Index =  %d\n", 
			lReqId, lErr, lIdx); 
		MessageBox(str); 
		SnmpCleanup(); 
		return ; 
	} 
	 
	smiUINT32 nVb; 
	nVb=SnmpCountVbl(hVbl); 
	smiOID dName; 
	smiVALUE dValue; 
	char szName[256]; 
	char szValue[256]; 
	for(smiUINT32 i=1;i<=nVb;i++) 
	{ 
		SnmpGetVb(hVbl,i,&dName,&dValue); 
		SnmpOidToStr(&dName,sizeof(szName),szName); //获取变量名 
		ValToStr(&dValue,sizeof(szValue),szValue); //获取变量值 
		////////////////////////////////////////////////////////////////////////// 
		Analyse(szName,szValue); //提取有用的信息,分别保存 
		if(IsBeginWith(szName,"1.3.6.1.2.1.5")) 
		{ 
			//表示所需的信息已经全部获取 
			////////////////////////////////////////////////////////////////////////// 
			OnFinish(); 
			//////////////////////////////////////////////////////////////////////////			 
			return; 
		} 
		////////////////////////////////////////////////////////////////////////// 
		m_hVBL=SnmpCreateVbl(m_hSession,NULL,NULL); //创建新的变量绑定列表 
		SnmpSetVb(m_hVBL,0,&dName,NULL); 
		HSNMP_PDU hPdu=SnmpCreatePdu(m_hSession,SNMP_PDU_GETNEXT,100,0,0,m_hVBL); 
		SnmpSendMsg(m_hSession,0,m_hDstEntity,m_hContext,hPdu); 
		 
	} 
} 
//将 
SNMPAPI_STATUS CMySnmpDlg::ValToStr(smiLPVALUE dValue, smiUINT32 nSize, LPSTR szValue) 
{ 
	smiUINT32 lDays = 0; 
	smiUINT32 lHours = 0; 
	smiUINT32 lMinutes = 0; 
	smiUINT32 lSeconds = 0; 
	smiUINT32 lHundreths = 0; 
	 
	switch(dValue->syntax) 
	{ 
	case SNMP_SYNTAX_INT : //sNumber 
		//		printf(" **sNumber** "); 
		smiINT sNumber; 
		sNumber=dValue->value.sNumber; 
		wsprintf(szValue,"%d",sNumber); 
		break; 
		 
	case SNMP_SYNTAX_UINT32 : //uNumber 
	case SNMP_SYNTAX_CNTR32 : 
	case SNMP_SYNTAX_GAUGE32 :	 
		//		printf(" **uNumber** "); 
		smiUINT32 uNumber; 
		uNumber=dValue->value.uNumber; 
		wsprintf(szValue,"%d",uNumber); 
		break; 
		 
	case SNMP_SYNTAX_CNTR64 : //hNumber 
		smiCNTR64 hNumber; 
		hNumber=dValue->value.hNumber; 
		wsprintf(szValue,"%d",hNumber); 
		break; 
	case SNMP_SYNTAX_TIMETICKS :		 
		if(dValue->value.uNumber!=0) 
		{ 
			lHundreths=dValue->value.uNumber % HUNDRED; 
			lSeconds=dValue->value.uNumber/HUNDRED; 
			if(lSeconds!=0) 
			{ 
				lDays=lSeconds/DAY; 
				lSeconds %= DAY; 
				if(lSeconds!=0) 
				{ 
					lHours = lSeconds / HOUR; 
					lSeconds %= HOUR; 
					if(lSeconds!=0) 
					{ 
						lMinutes = lSeconds / MINUTE; 
						lSeconds %= MINUTE; 
					} 
				} 
			} 
		} 
		wsprintf(szValue,"%lu,%lu:%lu:%lu.%lu", 
			lDays, lHours, lMinutes, lSeconds, lHundreths); 
		break; 
		 
	case SNMP_SYNTAX_OCTETS : //string 
	case SNMP_SYNTAX_OPAQUE : 
	case SNMP_SYNTAX_NSAPADDR : 
		//		printf(" **string** "); 
		smiOCTETS Mystring; 
		Mystring=dValue->value.string; 
		wsprintf(szValue,"%s",Mystring.ptr); 
		break; 
	case SNMP_SYNTAX_IPADDR : 
		//		printf("**IpAdress**");		 
		sprintf(szValue,"%d.%d.%d.%d", 
			*(dValue->value.string.ptr), 
			*(dValue->value.string.ptr+1), 
			*(dValue->value.string.ptr+2), 
			*(dValue->value.string.ptr+3)); 
		break; 
	case SNMP_SYNTAX_OID : //oid 
		//		printf(" **oid** "); 
		smiOID oid; 
		oid=dValue->value.oid; 
		SnmpOidToStr(&oid,100,szValue); 
		break; 
		 
	case SNMP_SYNTAX_NULL : //empty 
	case SNMP_SYNTAX_NOSUCHOBJECT : 
	case SNMP_SYNTAX_NOSUCHINSTANCE : 
	case SNMP_SYNTAX_ENDOFMIBVIEW : 
		//		printf(" **empty** "); 
		smiBYTE empty; 
		empty=dValue->value.empty; 
		wsprintf(szValue,"%s","No Value Returned"); 
		break; 
	default: //other 
		//		printf(" **other** "); 
		wsprintf(szValue,"%s","Other Type Value"); 
		break; 
	} 
	return TRUE; 
} 
//在这里分析变量名和变量值,提取有用的信息 
void CMySnmpDlg::Analyse(char *szName, char *szValue) 
{ 
	CString strValue(szValue); 
	if(IsBeginWith(szName,"1.3.6.1.2.1.1")) //获取的是系统信息 
	{		 
		m_Route.m_SystemInfo.Add(strValue); 
	} 
	if(IsBeginWith(szName,"1.3.6.1.2.1.4.21.1")) //路由表信息 
	{ 
		CString strName(szName); 
		m_Route.m_ipRouteTableName.Add(strName); 
		m_Route.m_ipRouteTableValue.Add(strValue); 
	} 
	if(IsBeginWith(szName,"1.3.6.1.2.1.4.21.1.1")) //获取的是ipRouteDest 
	{ 
		m_Route.m_ipRouteDest.Add(strValue); 
	} 
	if(IsBeginWith(szName,"1.3.6.1.2.1.4.21.1.8")) //获取的是ipRouteType 
	{ 
		m_Route.m_ipRouteType.Add(strValue); 
	} 
	if(IsBeginWith(szName,"1.3.6.1.2.1.4.21.1.11")) //获取的是ipRouteMask 
	{ 
		m_Route.m_ipRouteMask.Add(strValue); 
	}	 
} 
//判断某个字符传是否以某个字符串开头 
BOOL CMySnmpDlg::IsBeginWith(char *pString, char *pSubString) 
{ 
	if(pString==NULL || pSubString==NULL) 
		return FALSE; 
	CString strName(pString); 
	int nLen=strlen(pSubString); 
	if(strName.Left(nLen)==pSubString && strName.GetAt(nLen)=='.') 
		return TRUE; 
	return FALSE; 
} 
//获取路由器系统信息 
void CMySnmpDlg::OnButtonsysteminfo()  
{ 
	// TODO: Add your control notification handler code here 
	KillTimer(0); 
	m_ctrlListCtrl.ShowWindow(SW_SHOW); 
	m_Route.ShowSystemInfo(&m_ctrlListCtrl); 
	m_nListType=LIST_SYSTEMINFO; 
} 
//获取路由表信息 
void CMySnmpDlg::OnButtonroutetable()  
{ 
	// TODO: Add your control notification handler code here 
	KillTimer(0); 
	m_ctrlListCtrl.ShowWindow(SW_SHOW); 
	m_Route.ShowRouteTable(&m_ctrlListCtrl); 
	m_nListType=LIST_ROUTETABLE; 
	 
} 
//获取路由器子网信息 
void CMySnmpDlg::OnButtonsubnetinfo()  
{ 
	// TODO: Add your control notification handler code here 
	KillTimer(0); 
	m_ctrlListCtrl.ShowWindow(SW_SHOW); 
	m_Route.ShowSubNetInfo(&m_ctrlListCtrl); 
	m_nListType=LIST_ROUTESUBNET; 
} 
//查看拓扑图 
void CMySnmpDlg::OnButtontuopu()  
{ 
	// TODO: Add your control notification handler code here 
	//m_Route.ShowTouPu(); //这个函数也可以用 
	this->ShowTouPu(); 
	SetTimer(0,1000,NULL); //启动定时器 以实现定时更新 
	m_nListType=LIST_ROUTETUOPU; 
} 
 
void CMySnmpDlg::OnButtonquit()  
{ 
	// TODO: Add your control notification handler code here 
	m_Route.StopSearching(); 
	this->OnCancel(); 
} 
 
void CMySnmpDlg::OnButtonabout()  
{ 
	// TODO: Add your control notification handler code here 
	CAboutDlg dlg; 
	dlg.DoModal(); 
} 
//获取完全部信息后的处理工作 
void CMySnmpDlg::OnFinish() 
{ 
	m_messageDlg.ShowWindow(SW_HIDE); 
	m_messageDlg.DestroyWindow(); 
 
	CButton* pButton;	 
	pButton=(CButton*)this->GetDlgItem(IDC_BUTTONSYSTEMINFO); 
	pButton->EnableWindow(TRUE); 
	 
	pButton=(CButton*)this->GetDlgItem(IDC_BUTTONROUTETABLE); 
	pButton->EnableWindow(TRUE); 
	 
	pButton=(CButton*)this->GetDlgItem(IDC_BUTTONSUBNETINFO); 
	pButton->EnableWindow(TRUE); 
	 
	pButton=(CButton*)this->GetDlgItem(IDC_BUTTONTUOPU); 
	pButton->EnableWindow(TRUE); 
	 
	m_Route.ShowSystemInfo(&m_ctrlListCtrl); 
	m_Route.SearchActiveHosts();//开始搜索活动主机 
} 
 
void CMySnmpDlg::OnClose()  
{ 
	// TODO: Add your message handler code here and/or call default 
	m_Route.StopSearching(); 
	CDialog::OnClose(); 
} 
 
void CMySnmpDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	if(m_nListType==LIST_ROUTESUBNET) 
	{ 
		POSITION pos=m_ctrlListCtrl.GetFirstSelectedItemPosition(); 
		int nItem=m_ctrlListCtrl.GetNextSelectedItem(pos); 
 
		if(nItem!=-1) //表示选中有记录 显示该记录所对应的子网的活动主机情况 
		{ 
			char chIP[20]; 
			m_ctrlListCtrl.GetItemText(nItem,0,chIP,sizeof(chIP)); 
			CMySubNet* pSub=NULL; 
			for(int i=0;im_Address==chIP) 
					break; 
			} 
			if(pSub!=NULL) 
			{ 
				////////////////////////////////////////////////////////////////////////// 
				//在这里绘制该子网的活动主机 
				CActiveHostDlg dlg; 
				dlg.m_pActiveHosts=&(pSub->m_ActiveHosts); 
				pSub->m_pActiveHostDlg=&dlg; 
				dlg.DoModal(); 
				////////////////////////////////////////////////////////////////////////// 
			} 
		} 
	} 
	*pResult = 0; 
} 
#include  
void CMySnmpDlg::ShowTouPu() 
{ 
	////////////////////////////////////////////////////////////////////////// 
	for(int n=0;nSetBkMode(TRANSPARENT);//设置透明模式 
	double pi=3.1415926535; 
	pdc->Rectangle(&rect); 
	////////////////////////////////////////////////////////////////////////// 
	//绘制提示信息 
	CPoint p; 
	p.x=rect.left+30; 
	p.y=rect.top+20; 
	DrawHost(pdc,p,RGB(255,0,0)); 
	pdc->TextOut(p.x+15,p.y-8,"路由器"); 
	p.x=p.x+200; 
	DrawHost(pdc,p,RGB(0,255,0)); 
	pdc->TextOut(p.x+15,p.y-8,"子网"); 
	p.x=p.x+200; 
	DrawHost(pdc,p,RGB(0,0,255)); 
	pdc->TextOut(p.x+15,p.y-10,"活动主机"); 
	////////////////////////////////////////////////////////////////////////// 
	CPoint CenterPoint; 
	CenterPoint=rect.CenterPoint(); 
	//路由器的绘制 
	DrawHost(pdc,CenterPoint,RGB(255,0,0)); 
	pdc->TextOut(CenterPoint.x-30,CenterPoint.y+8,m_IPAddress); 
	 
	TipData* pdata=new TipData; 
	pdata->point=CenterPoint; 
	pdata->strIP=m_IPAddress; 
	m_TipDataArray.Add(pdata); 
	 
	//各个子网的绘制 
	int nSubNetCount=m_Route.m_SubNets.GetSize(); 
	for(int i=0;iSelectObject(&pen); 
		pdc->MoveTo(CenterPoint.x,CenterPoint.y); 
		pdc->LineTo(point.x,point.y); 
		pdc->SelectObject(poldPen); 
		 
		CMySubNet* pSubNet=(CMySubNet*)m_Route.m_SubNets.GetAt(i); 
		pdc->TextOut(point.x-30,point.y+8,pSubNet->m_Address); 
 
		TipData* pD=new TipData; 
		pD->point=point; 
		pD->strIP=pSubNet->m_Address; 
		m_TipDataArray.Add(pD); 
		 
		//各个活动主机的绘制 
		int nHostCount=pSubNet->m_ActiveHosts.GetSize(); 
		for(int nHost=0;nHostTextOut(temp.x-10,temp.y+8,pSubNet->m_ActiveHosts.GetAt(nHost)); 
			pdc->MoveTo(point); 
			pdc->LineTo(temp); 
 
			TipData* pTemp=new TipData; 
			pTemp->point=temp; 
			pTemp->strIP=pSubNet->m_ActiveHosts.GetAt(nHost); 
			m_TipDataArray.Add(pTemp); 
		} 
	}	 
} 
//绘制host 
void CMySnmpDlg::DrawHost(CDC *pdc, CPoint point, COLORREF crColor) 
{ 
	CBrush brush,*pold; 
	brush.CreateSolidBrush(crColor); 
	pold=pdc->SelectObject(&brush); 
	if(crColor==RGB(0,0,255)) 
		pdc->Rectangle(point.x-6,point.y-6,point.x+6,point.y+6); 
	else 
		pdc->Rectangle(point.x-10,point.y-10,point.x+10,point.y+10); 
	pdc->SelectObject(pold); 
} 
 
//单击鼠标消息相应函数 
void CMySnmpDlg::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if(m_RightRect.PtInRect(point)) 
	{ 
		for(int i=0;ipoint; 
			CRect rect(temp.x-10,temp.y-10,temp.x+10,temp.y+10); 
			if(rect.PtInRect(point)) 
			{ 
				CString str; 
				str.Format("选中的IP是:%s",pData->strIP); 
				SetWindowText(str); 
 
//				if(m_pTipDlg!=NULL) 
//				{ 
//					delete m_pTipDlg; 
//					m_pTipDlg=NULL; 
//				} 
//				m_pTipDlg=new CTipDlg; 
//				m_pTipDlg->Create(IDD_DIALOG2); 
//				m_pTipDlg->m_strIpAddress=pData->strIP; 
//			//	m_pTipDlg->ShowWindow(SW_SHOW); 
//				m_pTipDlg->SetWindowPos(this,point.x,point.y,100,100,SWP_SHOWWINDOW); 
				break; 
			} 
			else 
			{ 
				SetWindowText("MySnmp"); 
//				if(m_pTipDlg!=NULL) 
//				{ 
//					if(m_pTipDlg->IsWindowVisible()) 
//						m_pTipDlg->ShowWindow(SW_HIDE); 
//					delete m_pTipDlg; 
//					m_pTipDlg=NULL; 
//				} 
			} 
		} 
	} 
//	SendMessage(WM_PAINT); 
	CDialog::OnLButtonDown(nFlags, point); 
} 
 
void CMySnmpDlg::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if(m_nListType!=LIST_ROUTETUOPU) 
		KillTimer(0); 
	this->ShowTouPu(); 
	CDialog::OnTimer(nIDEvent); 
}