void CRecView::OnDraw(CDC* pDC)
{
CRecDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc); if (!pDoc)
return;
// TODO: add draw code for native data here
p_x=50;
p_y=50;
pDC->Rectangle(p_x,p_y,p_x+150,p_y+150);
}
void CRecView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect(p_x,p_y,p_x+150,p_y+150);
BOOL a=rect.PtInRect(point);
if(a==1)
{
CString strOutPut;
strOutPut.Format("击中矩形");
MessageBox(strOutPut);
} p_x=point.x;
p_y=point.y;
CView::OnLButtonDown(nFlags, point);
}
能详细解释一下吗?怎么改才能达到效果?谢谢啦
{
CRecDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc); if (!pDoc)
return;
// TODO: add draw code for native data here
p_x=50;
p_y=50;
pDC->Rectangle(p_x,p_y,p_x+150,p_y+150);
}
void CRecView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect(p_x,p_y,p_x+150,p_y+150);
BOOL a=rect.PtInRect(point);
if(a==1)
{
CString strOutPut;
strOutPut.Format("击中矩形");
MessageBox(strOutPut);
} p_x=point.x;
p_y=point.y;
CView::OnLButtonDown(nFlags, point);
}
能详细解释一下吗?怎么改才能达到效果?谢谢啦
{
p_x=point.x;
p_y=point.y;Invalidate();
}
if (!pDoc)改为if(pDC)就可以了