A function to automatically connect two controls on a dialog box (draw a line)

Source: Internet
Author: User

void Cgasbagcdlg::linetwoctrl (CPaintDC *dc,int leftid,int rightid,cgasbagcdlg *phd) {//201506161749 in Peking University 韩晓东 compilation// Function: can be called in OnPaint, connect two control//Parameter description: Parameter 1:onpaint brush, parameter two: control 1ID, Parameter three: control 2ID, parameter four: Current window pointer//writing PROBLEM: Parameter one is MFC's class object pointer, Passing MFC class objects can only be passed as pointers or references, and parameter four gets the context//indicator line through the this pointer CRect rectl,rectr;phd->getdlgitem (leftid)->getwindowrect (& RECTL);//Gets the position of the control relative to the screen phd->screentoclient (RECTL);//convert to relative position on dialog phd->getdlgitem (rightid)->getwindowrect (&rectr);//Gets the position of the control relative to the screen phd->screentoclient (RECTR);//Convert to the relative position on the dialog uint m_rowl=rectl.bottom-rectl.top;// Left indicator height UINT m_rowr=rectr.bottom-rectr.top;//Right indicator height uint m_width=rectr.left-rectl.right;//around indicator cross spacing int m_height= ( RECTL.BOTTOM-M_ROWL/2)-(RECTR.BOTTOM-M_ROWR/2);//left or indicator middle point height difference. Phd->updatedata (FALSE);d C->moveto (RECTL.RIGHT,RECTL.BOTTOM-M_ROWL/2);//Connect two control center points Dc->lineto ( RECTL.RIGHT+M_WIDTH/2,RECTL.BOTTOM-M_ROWL/2);//Point 1dc->lineto (rectl.right+m_width/2,rectl.bottom-m_rowl/2-m_ height);//Point 2dc->lineto (RECTR.LEFT,RECTR.TOP+M_ROWR/2);//DOT 3//connection Complete}

OnPaint () in the attached project:

void Cgasbagcdlg::onpaint () {CPAINTDC DC (this),//device context for painting//TODO: Add Message Handler code here//indicator lines// First level: 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);//Two-level 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);//three-level 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);//connection complete//Do not Call Cdialogex::onpaint ()} for the drawing message

  

A function to automatically connect two controls on a dialog box (draw a line)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.