⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 routerbutton.cpp

📁 一个windows系统下查看网络拓扑结构的程序
💻 CPP
字号:
// RouterButton.cpp : 实现文件
//

#include "stdafx.h"
#include "NetExplorer.h"
#include "RouterButton.h"
#include ".\routerbutton.h"
#include "MainFrm.h"
#include "NetExplorerDoc.h"
#include "ReExplorerDialog.h"
#include "RouoterInfoDialog.h"
#include "FucntionGetRouterInfo.h"
#include "NetExplorerView.h"
#define WM_REEXPLORER (WM_USER+212)

// CRouterButton

IMPLEMENT_DYNAMIC(CRouterButton, CButton)
CRouterButton::CRouterButton()
{
	this->ResultOfPingDlg=NULL;
	this->RouterInfoDialog=NULL;
}

CRouterButton::~CRouterButton()
{
}


BEGIN_MESSAGE_MAP(CRouterButton, CButton)
	ON_WM_CREATE()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_ROUTERMENU_32783, OnGetRouterParticularInformation)
	ON_COMMAND(ID_ROUTERMENU_, OnPingAllHost)
	ON_COMMAND(ID_ROUTERMENU_32785, OnChangeGroupID)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_CHAR()
END_MESSAGE_MAP()



// CRouterButton 消息处理程序


BOOL CRouterButton::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类
	this->Tip.RelayEvent(pMsg); 
	return CButton::PreTranslateMessage(pMsg); 
}

int CRouterButton::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CButton::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	this->EnableToolTips();
	this->Tip.Create(this);
	this->Tip.Activate(true);
	this->Tip.SetMaxTipWidth(10);
	this->Tip.AddTool(this,this->TipString);
	return 0;
}

void CRouterButton::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	this->SetCapture();

	this->Eraser=false;
	CButton::OnLButtonDown(nFlags, point);
}

void CRouterButton::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	
	if(this->GetCapture()==this)
	{
		if(point.x>0&&point.x<this->Width&&point.y<this->Heigh&&point.y>0)
		{

		}
		else
		{
			SIZE t;
			t.cx=this->Width;
			t.cy=this->Heigh;
			
			point.x+=this->OldPositionX;
			point.y+=this->OldPositionY;
			if((point.x-50)%150<15)
			{
				point.x-=(point.x-50)%150;
			}
			if((point.y-30)%150<15)
			{
				point.y-=(point.y-30)%150;
			}
			if((point.x-50)%150>135)
			{
				point.x+=150-(point.x-50)%150;
			}
			if((point.y-30)%150>135)
			{
				point.y+=150-(point.y-30)%150;
			}
			this->OldPositionX=point.x;
			this->OldPositionY=point.y;
			CRect CP(point,t);
			this->MoveWindow(&CP);
		
		}
	}
	CButton::OnLButtonUp(nFlags, point);
	this->Father->Invalidate();

}

BOOL CRouterButton::MyCreate(CPoint CreatePoint, CBitmap &RouterBmp,char * PTipString,CWnd *Father)//CPoint *PReferencePoint,bool *PScrolled)

{
	static int nID=0;
	BITMAP Bmp;
	RouterBmp.GetBitmap(&Bmp);
	SIZE t;
	t.cx=Bmp.bmWidth+4;
	t.cy=Bmp.bmHeight+4;
	this->OldPositionX=CreatePoint.x;
	this->OldPositionY=CreatePoint.y;

	this->Heigh=t.cy;
	this->Width=t.cx;
	this->Father=Father;
	nID++;
	this->TipString=PTipString	;
	BOOL ReturnValue= this->Create(NULL,WS_CHILD|WS_VISIBLE|BS_BITMAP,CRect(CreatePoint,t),Father,nID);
	this->SetBitmap(RouterBmp);//

	//this->SetDlgItemText(nID,"df");
	
	this->OldPoint.x=t.cx;
	this->OldPoint.y=t.cy;
	return ReturnValue;
}

void CRouterButton::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if(this->GetCapture()==this)
	{
		if(point.x>0&&point.x<this->Width&&point.y<this->Heigh&&point.y>0)
		{
		}
		else
		{
			point.x+=this->OldPositionX;
			point.y+=this->OldPositionY;
			CClientDC dc(this->Father);
			dc.SetROP2(R2_NOT);
			if(this->Eraser)
			{
				dc.Rectangle(this->OldPoint.x+1,this->OldPoint.y+1,this->OldPoint.x+this->Width-1,this->OldPoint.y+this->Heigh-1);
				dc.Rectangle(this->OldPoint.x,this->OldPoint.y,this->OldPoint.x+this->Width,this->OldPoint.y+this->Heigh);
			}
			this->Eraser=true;
			dc.Rectangle(point.x+1,point.y+1,point.x+this->Width-1,point.y+this->Heigh-1);
			dc.Rectangle(point.x,point.y,point.x+this->Width,point.y+this->Heigh);
			this->OldPoint=point;
			this->Invalidate();
		}
		
	}
	CButton::OnMouseMove(nFlags, point);
}

BOOL CRouterButton::ChangeTipText(char * PTipString)
{
	CToolInfo tt;
	this->Tip.GetToolInfo(tt,this);
	tt.lpszText=PTipString;
	this->Tip.SetToolInfo(&tt);
	return 0;
}

void CRouterButton::OnRButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CMenu menu ,* pSubMenu; //定义下面要用到的cmenu对象
	menu.LoadMenu(IDR_MENU1); //装载自定义的右键菜单
	pSubMenu = menu.GetSubMenu(0);//获取第一个弹出菜单,所以第一个菜单必须有子菜单
	CPoint pt=point;
	ClientToScreen (&pt); 
	pSubMenu->TrackPopupMenu (TPM_LEFTALIGN, pt.x, pt.y, this); //在指定位置显示弹出菜单
	CButton::OnRButtonDown(nFlags, point);
}


void CRouterButton::OnGetRouterParticularInformation()
{
	// TODO: 在此添加命令处理程序代码
	CString StateInfo;
	StateInfo.Format("像目的服务器发送请求");
	CNetExplorerApp *PNetExplorerApp=(CNetExplorerApp *)AfxGetApp();
	CStatusBar* pStatus=(CStatusBar *)(PNetExplorerApp->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR));
	pStatus->SetPaneText(0,StateInfo.GetBuffer());
	if(this->RouterInfoDialog!=NULL)
	{
		if(this->RouterInfoDialog->ifCreate)
		{
			delete this->RouterInfoDialog;
			this->RouterInfoDialog=NULL;
		}
		else
		{
			return ;
		}
	}
 	this->RouterInfoDialog=new CRouoterInfoDialog();
	this->RouterInfoDialog->Create(IDD_DIALOG4,this);
	this->RouterInfoDialog->ShowWindow(SW_SHOW);
	this->RouterInfoDialog->UpdateWindow();
	CString BeginInfo;
	BeginInfo.Format("开始获得路由器“%s”相关信息",NetIpToString(this->ValidIp));
	this->RouterInfoDialog->AddInfo(BeginInfo);
	InfoParament *ThePar=new InfoParament;
	memcpy(ThePar->CommunityName,this->ValidCommunityName,64);
	ThePar->DestIP=this->ValidIp;
	ThePar->MessageReceiver=this->RouterInfoDialog;
	this->RouterInfoDialog->ifCreate=false;
	AfxBeginThread(GetInfoThreadFunc,ThePar);
	
}

void CRouterButton::OnPingAllHost()
{	
	// TODO: 在此添加命令处理程序代码
	if(this->ResultOfPingDlg!=NULL)
	{
		if(this->ResultOfPingDlg->IfCreate)
		{
			delete this->ResultOfPingDlg;
		}
		else
		{
			return;
		}
	}
	this->ResultOfPingDlg=new CResultOfPing;
	if(this->ResultOfPingDlg->IfCreate)
	{
		this->ResultOfPingDlg->Create(IDD_DIALOG1,this);
		POSITION P=this->IPList.GetHeadPosition();
		for(int i=0;i<this->IPList.GetCount();i++)
		{
			ULONG Tmp=this->IPList.GetNext(P);
			this->ResultOfPingDlg->DestIP.AddTail(Tmp);
			this->ResultOfPingDlg->CComboBoxCtrl.AddString(NetIpToString(Tmp));   
		}
		this->ResultOfPingDlg->CComboBoxCtrl.SetCurSel(0);
		P=this->IPList.GetHeadPosition();
		this->ResultOfPingDlg->ChosenIp=this->ResultOfPingDlg->DestIP.GetAt(P);
		this->ResultOfPingDlg->ShowWindow(SW_SHOW);
		this->ResultOfPingDlg->UpdateWindow();
		this->ResultOfPingDlg->IfCreate=false;
	}
}

void CRouterButton::OnChangeGroupID()
{
	// TODO: 在此添加命令处理程序代码,这个函数可以使用新的团体号继续探测工作
	
	if(this->IPList.GetCount()!=1)
	{
		this->MessageBox("对该路由器探测使用的团体号正确,不必重新探测!","Error",MB_OK|MB_ICONWARNING);
	}
	else
	{
		CNetExplorerDoc* P;
		P=(CNetExplorerDoc*)(((CMainFrame*)AfxGetMainWnd())->GetActiveView()->GetDocument());
		CReExplorerDialog Dlg;
		Dlg.CommunityName=P->GroupID;
		if(Dlg.DoModal()==IDOK)
		{
			if(P->GroupID==Dlg.CommunityName)
			{
				this->MessageBox("您输入的新团体号和旧的一样","Error",MB_OK|MB_ICONWARNING);
			}
			else
			{
				P->GroupID=Dlg.CommunityName;
				CPoint * POldPoint=new CPoint;
				POldPoint->x=this->OldPositionX;
				POldPoint->y=this->OldPositionY;
				CString *NewCommuntiyName=new CString(Dlg.CommunityName);
				CMainFrame *P2;
				P2=(CMainFrame *)AfxGetMainWnd();
				P2->GetActiveView()->SendMessage(WM_REEXPLORER,(WPARAM)POldPoint,(LPARAM)NewCommuntiyName);
			}
		}
		else
		{
			return ;
		}
	}
	
}

void CRouterButton::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	this->OnGetRouterParticularInformation();
	CButton::OnLButtonDblClk(nFlags, point);
}

void CRouterButton::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	((CNetExplorerView*)(this->Father))->OnChildrenChar(nChar, nRepCnt, nFlags);
	//CButton::OnChar(nChar, nRepCnt, nFlags);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -