标签:
void CGasBagCDlg::Linetwoctrl(CPaintDC *dc,int leftid,int rightid,CGasBagCDlg *phd) { //201506161749中北大学韩晓东编制 //功能:可在onpaint中调用,连接两个控件 //参数说明:参数1:onpaint画笔,参数二:控件1ID,参数三:控件2ID,参数四:当前窗口指针 //编写中的问题:参一是MFC的类对象指针,传递MFC类对象只能以指针或引用方式传递,参四可通过this指针获取上下文 //指标连线 CRect rectL,rectR; phd->GetDlgItem(leftid)->GetWindowRect(&rectL);//获取控件相对于屏幕的位置 phd->ScreenToClient(rectL);//转化为对话框上的相对位置 phd->GetDlgItem(rightid)->GetWindowRect(&rectR);//获取控件相对于屏幕的位置 phd->ScreenToClient(rectR);//转化为对话框上的相对位置 UINT m_rowL=rectL.bottom-rectL.top;//左指标高度 UINT m_rowR=rectR.bottom-rectR.top;//右指标高度 UINT m_width=rectR.left-rectL.right;//左右指标横间距 INT m_height=(rectL.bottom-m_rowL/2)-(rectR.bottom-m_rowR/2);//左或指标中间点高度差。 phd->UpdateData(FALSE); dc->MoveTo(rectL.right,rectL.bottom-m_rowL/2);//连接两个控件中心点 dc->LineTo(rectL.right+m_width/2,rectL.bottom-m_rowL/2);//点1 dc->LineTo(rectL.right+m_width/2,rectL.bottom-m_rowL/2-m_height);//点2 dc->LineTo(rectR.left,rectR.top+m_rowR/2);//点3 //连线完毕 }
附项目中onpaint():
void CGasBagCDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 //指标连线 //一级: Linetwoctrl(&dc,IDC_A_STATIC,IDC_B1_STATIC,this); Linetwoctrl(&dc,IDC_A_STATIC,IDC_B2_STATIC,this); Linetwoctrl(&dc,IDC_A_STATIC,IDC_B3_STATIC,this); Linetwoctrl(&dc,IDC_A_STATIC,IDC_B4_STATIC,this); //二级 Linetwoctrl(&dc,IDC_B1_STATIC,IDC_C11_STATIC,this); Linetwoctrl(&dc,IDC_B1_STATIC,IDC_C12_STATIC,this); Linetwoctrl(&dc,IDC_B2_STATIC,IDC_C21_STATIC,this); Linetwoctrl(&dc,IDC_B2_STATIC,IDC_C22_STATIC,this); Linetwoctrl(&dc,IDC_B3_STATIC,IDC_C31_STATIC,this); Linetwoctrl(&dc,IDC_B3_STATIC,IDC_C32_STATIC,this); Linetwoctrl(&dc,IDC_B4_STATIC,IDC_C41_STATIC,this); Linetwoctrl(&dc,IDC_B4_STATIC,IDC_C42_STATIC,this); Linetwoctrl(&dc,IDC_B4_STATIC,IDC_C43_STATIC,this); //三级 Linetwoctrl(&dc,IDC_C11_STATIC,IDC_D111_STATIC,this); Linetwoctrl(&dc,IDC_C11_STATIC,IDC_D112_STATIC,this); Linetwoctrl(&dc,IDC_C11_STATIC,IDC_D113_STATIC,this); Linetwoctrl(&dc,IDC_C12_STATIC,IDC_D121_STATIC,this); Linetwoctrl(&dc,IDC_C12_STATIC,IDC_D122_STATIC,this); Linetwoctrl(&dc,IDC_C12_STATIC,IDC_D123_STATIC,this); Linetwoctrl(&dc,IDC_C12_STATIC,IDC_D124_STATIC,this); Linetwoctrl(&dc,IDC_C21_STATIC,IDC_D211_STATIC,this); Linetwoctrl(&dc,IDC_C21_STATIC,IDC_D212_STATIC,this); Linetwoctrl(&dc,IDC_C21_STATIC,IDC_D213_STATIC,this); Linetwoctrl(&dc,IDC_C22_STATIC,IDC_D221_STATIC,this); Linetwoctrl(&dc,IDC_C22_STATIC,IDC_D222_STATIC,this); Linetwoctrl(&dc,IDC_C22_STATIC,IDC_D223_STATIC,this); Linetwoctrl(&dc,IDC_C31_STATIC,IDC_D311_STATIC,this); Linetwoctrl(&dc,IDC_C31_STATIC,IDC_D312_STATIC,this); //连线完毕 // 不为绘图消息调用 CDialogEx::OnPaint() }
标签:
原文地址:http://www.cnblogs.com/freesblog/p/4581980.html