关于矩形框的绘制和移动

icefox225 2006-11-10 04:40:27
刚学VC++,自己写了个能画矩形框的函数,但是不知道怎么去移动他,因为我一点左键他就消失了!
代码如下:
void CLetMeSeeDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect RectClient;
this->GetClientRect(RectClient);
if(RectClient.PtInRect(point))
{
m_start = point;
m_left = m_start;
}
/* CString StrMsg;
StrMsg.Format("x is %d, y is %d " ,m_left.x,m_left.y);
MessageBox(StrMsg); */
CDialog::OnLButtonDown(nFlags, point);
}
void CLetMeSeeDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
CRect RectClient;
this->GetClientRect(RectClient);
if(RectClient.PtInRect(point))
{
m_end = point;
}
if(m_RectBtm.IsRectEmpty())
{
CClientDC dc(this->GetDlgItem(IDD_LETMESEE_DIALOG));
CPen pen(PS_SOLID,2,RGB(255, 0, 0)); //选择红色画笔
/*CPen *pOld=*/ dc.SelectObject(&pen);
CBrush *pBrush= CBrush::FromHandle((HBRUSH)GetStockObjec(NULL_BRUSH));
CBrush *poldBrush = dc.SelectObject(pBrush);
m_RectBtm=CRect(m_left,m_end);
ClientToScreen(m_RectBtm);
dc.Rectangle(m_RectBtm);
CPoint MiddlePoint = m_RectBtm.CenterPoint();
dc.SelectObject(poldBrush);
}
else
{
m_RectBtm.SetRectEmpty();
Invalidate();
}
CDialog::OnLButtonUp(nFlags, point);
}
...全文
207 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
icefox225 2006-11-13
  • 打赏
  • 举报
回复
不好意思,前几天双休,谢谢楼上的两位,我再试试看
wlwlxj 2006-11-10
  • 打赏
  • 举报
回复
直接看看我得代码吧
http://www.cppblog.com/wlwlxj/archive/2005/12/20/1914.aspx
skt01 2006-11-10
  • 打赏
  • 举报
回复
不错,要移动处理MOUSE_MOVE消息,一样调用Invalidate();只是画的位置要跟着鼠标位置变就行了
happyness44 2006-11-10
  • 打赏
  • 举报
回复
在左键up的时候调用Invalidate();然后在OnPaint()中画图
icefox225 2006-11-10
  • 打赏
  • 举报
回复
楼上的朋友的意思是不是我在左键up的时候调用Invalidate();然后在OnPaint()中画图么???
skt01 2006-11-10
  • 打赏
  • 举报
回复
呵呵,你在左键的时候直接画是不对的,应该调用Invalidate();然后在OnPaint()中画,

15,976

社区成员

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

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