我在Dialog上画两个矩形,然后用线将它们连起来,但是线总是连得不对,请高手指点一下,解决后马上结帖,我的代码是这样的:
CClientDC dc(this);
CPoint cPoint1,cPoint2;
CRect rect;
rect.left=0;
rect.top=0;
rect.bottom=60;
rect.right=80;
dc.Rectangle(&rect);
cPoint1.x=(rect.right+rect.left)/2;
cPoint1.y=rect.bottom;
rect.OffsetRect(0,100);
dc.Rectangle(&rect); cPoint2.x=(rect.right+rect.left)/2;
cPoint2.y=rect.top;
dc.MoveTo(cPoint1);
dc.LineTo(cPoint2);
CClientDC dc(this);
CPoint cPoint1,cPoint2;
CRect rect;
rect.left=0;
rect.top=0;
rect.bottom=60;
rect.right=80;
dc.Rectangle(&rect);
cPoint1.x=(rect.right+rect.left)/2;
cPoint1.y=rect.bottom;
rect.OffsetRect(0,100);
dc.Rectangle(&rect); cPoint2.x=(rect.right+rect.left)/2;
cPoint2.y=rect.top;
dc.MoveTo(cPoint1);
dc.LineTo(cPoint2);
CPoint cPoint1,cPoint2;
CRect rect;
rect.left=0;
rect.top=0;
rect.bottom=60;
rect.right=80;
dc.Rectangle(&rect);
cPoint1.x=(rect.right+rect.left)/2;
cPoint1.y=rect.bottom;
rect.OffsetRect(0,100);
dc.Rectangle(&rect); cPoint2.x=(rect.right+rect.left)/2;
cPoint2.y=rect.top; m_pen.CreatePen(PS_SOLID,1,RGB(255,255,255));
dc.SelectObject(&m_pen); dc.MoveTo(cPoint1);
dc.LineTo(cPoint2);
CRect rect;
rect.left=0;
rect.top=0;
rect.bottom=60;
rect.right=80;
CListBox* lpList1=new CListBox;
CListBox* lpList2=new CListBox;lpList1->Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL|WS_HSCROLL,rect, this, uList_id);
CPoint cPoint1,cPoint2;
cPoint1.x=(rect.right+rect.left)/2;
cPoint1.y=rect.bottom;
rect.OffsetRect(0,100);
lpList2->Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL|WS_HSCROLL,rect, this, uList_id2);
cPoint2.x=(rect.right+rect.left)/2;
cPoint2.y=rect.top;
CClientDC dc(this);
dc.MoveTo(cPoint1);
dc.LineTo(cPoint2);
这样就总是差一点点连到上一个矩形。
dc.LPtoDP(&cPoint2);
dc.MoveTo(cPoint1);
dc.LineTo(cPoint2);