// Topology.cpp : implementation file
//插入Visual C++ Components-> ToolTip Support
#include "stdafx.h"#include "MyApp.h"#include "Topology.h"
#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif
/// Topology dialog#define IDC_MYBUTTON 0x900
Topology::Topology(CWnd* pParent /*=NULL*/) : CDialog(Topology::IDD, pParent){ //{{AFX_DATA_INIT(Topology) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT}
void Topology::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(Topology) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP}
BEGIN_MESSAGE_MAP(Topology, CDialog) //{{AFX_MSG_MAP(Topology) ON_WM_PAINT() ON_WM_TIMER() ON_WM_MOUSEMOVE() //}}AFX_MSG_MAPEND_MESSAGE_MAP()
/// Topology message handlersBOOL Topology::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);}
void Topology::OnPaint() { CPaintDC dc(this); // device context for painting int i;
CString str1;
for(i = 0;i< relat_x; i++) { str1.Format("Pid:%d; counter:%d; v1:%d; v2:%d; v3:%d v4:%d; v5:%d",relat[i][1],relat[i][2],relat[i][3],relat[i][4],relat[i][5],relat[i][6],relat[i][7]); if(GetDlgItem(IDC_MYBUTTON+relat[i][0]) != NULL) m_tooltip.AddTool(GetDlgItem(IDC_MYBUTTON+relat[i][0]),str1); } if(relat_x == 0) str1.Format("节点一共%d个,5秒刷新节点, 左键移动,右键删除!",relat_x); else str1.Format("节点一共%d个,5秒刷新节点, 左键移动,右键删除!",relat_x+1); GetDlgItem(IDC_STATIC_TOPO)->SetWindowText(str1);
dc.Rectangle(0,0,675,355); CString str; CRect btrect1,btrect2; for(i = 0;i< relat_x; i++) { if(GetDlgItem(IDC_MYBUTTON+relat[i][0]) != NULL && GetDlgItem(IDC_MYBUTTON+relat[i][1]) != NULL) { GetDlgItem(IDC_MYBUTTON+relat[i][0])->GetWindowRect(btrect1); ScreenToClient(btrect1); GetDlgItem(IDC_MYBUTTON+relat[i][1])->GetWindowRect(btrect2); ScreenToClient(btrect2);
//横向排列 dc.MoveTo(btrect2.right,(btrect2.bottom+btrect2.top)/2); dc.LineTo(btrect1.left,(btrect1.bottom+btrect1.top)/2); } } // TODO: Add your message handler code here // Do not call CDialog::OnPaint() for painting messages}
BOOL Topology::OnInitDialog() { CDialog::OnInitDialog();
EnableToolTips(TRUE); m_tooltip.Create(this); m_tooltip.Activate(TRUE);
GetDlgItem(IDC_STATIC_TOPO2)->SetWindowText("坐标信息"); // TODO: Use one of the following forms to add controls: //画节点按钮 SetTimer(6,5000,NULL); //更新节点链接关系 SetTimer(5,50000,NULL);
return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE}
void Topology::Paint_Btn(){ int i,j,k; bool idend = false; CString str; CPaintDC dc(this);
int index_x[10]; int id_data[10][50];
for(i = 0;i<10;i++) { index_x[i] = 0; for(j =0 ;j<50;j++) { id_data[i][j] = 0; } } //0号根节点 i = 1; index_x[0] = 1;
//更新层i的节点数index_x[i],以及相应的节点号id_data[] while(!idend) { idend = true; for(k =0;k<index_x[i-1];k++) { for(j = 0;j< relat_x; j++) { if(relat[j][1] == id_data[i-1][k]) { idend = false; id_data[i][index_x[i]++] = relat[j][0]; } } } i++; } //如果1层的节点数等于0,画出节点0按钮 if(i == 2) { if(GetDlgItem(IDC_MYBUTTON+id_data[0][0]) == NULL) { My_Button* mb = new My_Button; str.Format("%d",id_data[0][0]); mb->Create(_T(str),BS_PUSHBUTTON,CRect(20,20,40,40),this,IDC_MYBUTTON+id_data[0][0]); mb->ShowWindow(true); }
} //if(index_x[1] != 0) //如果1层的节点数不等于0,画出所有节点按钮 else { for(j = 0;j<(i-1);j++) { for(k = 0;k<index_x[j];k++) { if(GetDlgItem(IDC_MYBUTTON+id_data[j][k]) == NULL) { My_Button* mb = new My_Button; str.Format("%d",id_data[j][k]); mb->Create(_T(str),BS_PUSHBUTTON,CRect(j*50+20,k*50+20,j*50+40,k*50+40),this,IDC_MYBUTTON+id_data[j][k]); mb->ShowWindow(true); } }
} } }
void Topology::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CDialog::OnTimer(nIDEvent); if(nIDEvent == 6) Paint_Btn(); if(nIDEvent == 5) //Flash_Btn(); ;
}
void Topology::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CString topo_str; topo_str.Format("X:%d Y:%d",point.x,point.y); GetDlgItem(IDC_STATIC_TOPO2)->SetWindowText(topo_str); CDialog::OnMouseMove(nFlags, point);}
void Topology::Flash_Btn(){ relat_x = 0;
}