vc中我画了一个框,希望框随着鼠标的移动而移动,当鼠标左键按下时, 5
框就停在鼠标点击的位置,但是实现不了,望各位大师帮忙解答!谢谢!代码如下:voidCHongkuangsView::OnDraw(CDC*/*pDC*/){CHongku...
框就停在鼠标点击的位置,但是实现不了,望各位大师帮忙解答!谢谢!
代码如下:
void CHongkuangsView::OnDraw(CDC* /*pDC*/)
{
CHongkuangsDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(255,0,0));
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
CRect rect;
rect.left=centerpoint.x-rectsize/2;
rect.top=centerpoint.y-rectsize/2;
rect.right=centerpoint.x+rectsize/2;
rect.bottom=centerpoint.y+rectsize/2;
dc.Rectangle(rect);
}
void CHongkuangsView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
mousepoint=point;
RedrawWindow();
CView::OnMouseMove(nFlags, point);*/
}
void CHongkuangsView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
centerpoint=point;
CView::OnLButtonDown(nFlags, point);
} 展开
代码如下:
void CHongkuangsView::OnDraw(CDC* /*pDC*/)
{
CHongkuangsDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CClientDC dc(this);
CPen pen(PS_SOLID,1,RGB(255,0,0));
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBrush);
CRect rect;
rect.left=centerpoint.x-rectsize/2;
rect.top=centerpoint.y-rectsize/2;
rect.right=centerpoint.x+rectsize/2;
rect.bottom=centerpoint.y+rectsize/2;
dc.Rectangle(rect);
}
void CHongkuangsView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
mousepoint=point;
RedrawWindow();
CView::OnMouseMove(nFlags, point);*/
}
void CHongkuangsView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
centerpoint=point;
CView::OnLButtonDown(nFlags, point);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询