【发布时间】:2012-02-08 05:00:50
【问题描述】:
这几天一直在学习MFC,想在VC++6.0和VS2010都用MoveTo()和LineTo()函数画线,但是在vs2010好像不行,我只加了两个窗口消息处理程序,WM_LBUTTONDOWN 和 WM_LBUTTONUP,在单文档项目中。 这是VC++6.0中的代码:
CPoint m_ptOrign;
void CStyleView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrign=point;
CView::OnLButtonDown(nFlags, point);
}
void CStyleView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.MoveTo(m_ptOrign);
dc.LineTo(point);
CView::OnLButtonUp(nFlags, point);
}
这是vs2010中的代码:
CPoint m_ptOrign;
void CStyleView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrign=point;
CView::OnLButtonDown(nFlags, point);
}
void CStyleView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.MoveTo(m_ptOrign);
dc.LineTo(point);
CView::OnLButtonUp(nFlags, point);
}
我添加到两个项目中的代码是一样的。当我松开左键时,该行立即出现在vc++6.0项目中,但它没有出现在vs 2010 mfc项目中。
如果 vs 2010 项目窗口的大小或位置发生变化,则会出现该行。
但是当我在 vs 2010 项目中使用dc.Rectangle(CRect(m_ptOrign,point)) 时,它运行良好。
不知道为什么.....
还有,如果我使用
CBrush *pBbrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
dc.SelectObject(pBbrush);
dc.Rectangle(CRect(m_ptOrign,point))
在vs2010中,又不行了,像画线的情况
【问题讨论】:
-
你为什么期望
NULL_BRUSH来绘制任何东西? -
默认笔刷是白色。笔刷不影响矩形的边框。如果我不更换画笔,矩形将被填充一些颜色。如果我在同一点绘制两个矩形,(第一个小,第二个大或者它们很接近),小一个将完全被覆盖或擦除大的,小的就看不见了screen.@CodyGray
标签: visual-c++ mfc