void CMyView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default pDC=GetDC(); center=point; r=rand()%46+5;//r=5~50 color=RGB(rand()%256,rand()%256,rand()%256); br.CreateSolidBrush(color); pDC->SelectObject(&br); pDC->Ellipse(center.x-r,center.y-r,center.x+r,center.y+r); br.DeleteObject(); CView::OnLButtonDown(nFlags, point); } void CMyView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default SetTimer(1,200,NULL); CView::OnLButtonUp(nFlags, point); } void CMyView::rise() { center.y-=5; pDC=GetDC(); br.CreateSolidBrush(color); pDC->SelectObject(&br); pDC->Ellipse(center.x-r,center.y-r,center.x+r,center.y+r); br.DeleteObject(); } void CMyView::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if (nIDEvent==1){ CDC *pDC=GetDC(); CRect rect; GetClientRect(&rect); for(int i=0;i<5;i++){ br.CreateSolidBrush(color); pDC->SelectObject(&br); pDC->Ellipse(center.x-r,center.y-r,center.x+r,center.y+r); br.DeleteObject();} ReleaseDC(pDC); center.y-=5; }怎么改能让这个圆没有运动轨迹
时间: 2024-01-29 13:04:03 浏览: 99
要让圆没有运动轨迹,可以在每次重绘之前,先用背景色覆盖整个视图区域,然后再绘制圆。修改代码如下:
```
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pDC = GetDC();
center = point;
r = rand() % 46 + 5; //r=5~50
color = RGB(rand() % 256, rand() % 256, rand() % 256);
br.CreateSolidBrush(color);
pDC->SelectObject(&br);
pDC->Ellipse(center.x - r, center.y - r, center.x + r, center.y + r);
br.DeleteObject();
CView::OnLButtonDown(nFlags, point);
}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetTimer(1, 200, NULL);
CView::OnLButtonUp(nFlags, point);
}
void CMyView::rise()
{
center.y -= 5;
pDC = GetDC();
br.CreateSolidBrush(color);
pDC->SelectObject(&br);
pDC->Ellipse(center.x - r, center.y - r, center.x + r, center.y + r);
br.DeleteObject();
}
void CMyView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent == 1) {
CDC* pDC = GetDC();
CRect rect;
GetClientRect(&rect);
pDC->FillSolidRect(rect, GetSysColor(COLOR_WINDOW)); // 用背景色覆盖整个视图区域
for (int i = 0; i < 5; i++) {
br.CreateSolidBrush(color);
pDC->SelectObject(&br);
pDC->Ellipse(center.x - r, center.y - r, center.x + r, center.y + r);
br.DeleteObject();
}
ReleaseDC(pDC);
center.y -= 5;
}
}
```
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)