关于矩形框的绘制和移动
刚学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);
}