鼠标拖动直线,怎么实现?

rurusanhe 2011-05-09 08:11:17
基于对话框程序,小弟想利用鼠标事件实现直线拖动效果,应该响应WM_LBUTTONDOWN,WM_MOUSEMOVE,WM_LBUTTONUP,消息吧?具体怎么实现就不知道怎么做了,请各位大侠指点一下!
...全文
231 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
a070104020016 2011-05-09
  • 打赏
  • 举报
回复
答案很好,借用一下,谢谢
anbam 2011-05-09
  • 打赏
  • 举报
回复
对话框
替换ondraw 为 onpaint
Eleven 2011-05-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 rurusanhe 的回复:]
引用 1 楼 visualeleven 的回复:
C/C++ code
BOOL bDown = FALSE;
CPoint m_ptStart;
CPoint m_ptEnd;

void CXXView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here ……
[/Quote]
差不多
rurusanhe 2011-05-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 visualeleven 的回复:]
C/C++ code
BOOL bDown = FALSE;
CPoint m_ptStart;
CPoint m_ptEnd;

void CXXView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
……
[/Quote]
谢谢大侠,挺详细的,再追问一下,我要在基于对话框的程序里实现,应该是一样的吧?!
Eleven 2011-05-09
  • 打赏
  • 举报
回复
BOOL bDown = FALSE;
CPoint m_ptStart;
CPoint m_ptEnd;

void CXXView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
bDown = TRUE;
m_ptStart = point;
CView::OnLButtonDown(nFlags, point);
}

void CXXView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
bDown = FALSE;
CView::OnLButtonUp(nFlags, point);
}

void CXXView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(bDown)
{
m_ptEnd = point;
InvalidateRect(NULL);
}
CView::OnMouseMove(nFlags, point);
}

void CXXView::OnDraw(CDC* pDC)
{
CAXDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->MoveTo(m_ptStart);
pDC->LineTo(m_ptEnd);
}

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧