编辑: yyy888555 | 2019-07-15 |
pDoc->
Origin.x = recClient.Width()/2;
pDoc->
Origin.y = recClient.Height()/3;
//原点可能以变化,需重新计算各部件位置 pDoc->
CalPosition();
//画主动导轨 pDC->
MoveTo(pDoc->
Gui1[0]);
pDC->
LineTo(pDoc->
Gui1[1]);
pDC->
MoveTo(pDoc->
Gui1[2]);
pDC->
LineTo(pDoc->
Gui1[3]);
//画从动导轨 pDC->
MoveTo(pDoc->
Gui2[0]);
pDC->
LineTo(pDoc->
Gui2[1]);
pDC->
MoveTo(pDoc->
Gui2[2]);
pDC->
LineTo(pDoc->
Gui2[3]);
//换笔 penThick.CreatePen(PS_SOLID,3,RGB(255,0,255));
oldpen = pDC->
SelectObject(&
penThick);
//画主动块 pDC->
Polygon(pDoc->
Kuai1,4);
//画从动块 pDC->
Polygon(pDoc->
Kuai2,4);
pDC->
Polygon(pDoc->
Gan,4);
//画圆 CPoint Yuan_1[2], Yuan_2[2];
Yuan_1[0] = pDoc->
Yuan1[0];
Yuan_1[1] = pDoc->
Yuan1[1];
Yuan_2[0] = pDoc->
Yuan2[0];
Yuan_2[1] = pDoc->
Yuan2[1];
pDC->
Ellipse(CRect(Yuan_1[0], Yuan_1[1]));
pDC->
Ellipse(CRect(Yuan_2[0], Yuan_2[1]));
CPen pen;
pen.CreatePen(PS_SOLID,5, RGB(0, 0, 255));
oldpen = pDC->
SelectObject(&
pen);
//画轨迹 for (int j = 0;
j <
101;
j++) { pDC->
MoveTo(GuiJi[j]);
pDC->
LineTo(GuiJi[j+1]);
} //还原画笔 pDC->
SelectObject(oldpen);
} // CHK_772View printing BOOL CHK_772View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo);
} void CHK_772View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CHK_772View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } // CHK_772View diagnostics #ifdef _DEBUG void CHK_772View::AssertValid() const { CView::AssertValid();
} void CHK_772View::Dump(CDumpContext&
dc) const { CView::Dump(dc);
} CHK_772Doc* CHK_772View::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->
IsKindOf(RUNTIME_CLASS(CHK_772Doc)));
return (CHK_772Doc*)m_pDocument;
} #endif //_DEBUG // CHK_772View message handlers void CHK_772View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CHK_772Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(nChar=='
A'
) { pDoc->
dX -= 2;
//让主动块左移2像素 if ( pDoc->
dX <
-95) { pDoc->
dX += 2;
} } else if(nChar=='
D'
) { pDoc->
dX += 2;
//让主动块右移2像素 if (pDoc->
dX >
95) { pDoc->
dX -= 2;
} } pDoc->
CalPosition();
Invalidate(刷新客户区 CView::OnKeyDown(nChar, nRepCnt, nFlags);
} void CHK_772View::OnOpen() { // TODO: Add your command handler code here i = 0;
SetTimer(1, 100, NULL);
} void CHK_772View::OnClose() { // TODO: Add your command handler code here KillTimer(1);
} void CHK_772View::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CHK_772Doc* pDoc = GetDocument();
GuiJi[i] = pDoc->
Guiji;
i++;
if (i >
= 100) { KillTimer(1);
} CView::OnTimer(nIDEvent);
} 结论: 存在问题:关闭之后轨迹无法消失. 问题与讨论 由于技术有限,存在的问题也比较多,只能基本满足要求.存在最严重的问题就是关闭之后轨迹不会消失,还请老师多多指教. ........