MFC 我想在对话框中实现鼠标实时绘图,麻烦大神看看我哪错了
主要代码如下,可是执行后对话框里一点反应都没有voidCTcpClientDlg::OnMouseMove(UINTnFlags,CPointpoint){CDC*pDc...
主要代码如下,可是执行后对话框里一点反应都没有
void CTcpClientDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CDC* pDc = GetDC();
CBrush newBrush;
CPen newPen;
newBrush.CreateSolidBrush(RGB(255,0,0));
newPen.CreatePen(PS_SOLID,5,RGB(255,0,0));
pDc->SelectObject(newBrush);
pDc->SelectObject(newPen);
pDc->LineTo(point.x,point.y);
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDialog::OnMouseMove(nFlags, point);
} 展开
void CTcpClientDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CDC* pDc = GetDC();
CBrush newBrush;
CPen newPen;
newBrush.CreateSolidBrush(RGB(255,0,0));
newPen.CreatePen(PS_SOLID,5,RGB(255,0,0));
pDc->SelectObject(newBrush);
pDc->SelectObject(newPen);
pDc->LineTo(point.x,point.y);
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDialog::OnMouseMove(nFlags, point);
} 展开
1个回答
展开全部
void CTcpClientDlg::OnMouseMove(UINT nFlags, CPoint point)
{
static CPoint pt(-1,-1);
CDC* pDc = GetDC();
CBrush newBrush;
CPen newPen;
newBrush.CreateSolidBrush(RGB(255,0,0));
newPen.CreatePen(PS_SOLID,5,RGB(255,0,0));
CBrush *pb = (CBrush*)pDc->SelectObject(&newBrush);
CPen *pp = (CPen*)pDc->SelectObject(&newPen);
if(pt.x == -1)
pDc->MoveTo(point.x,point.y);
else
{
pDc->MoveTo(pt.x,pt.y);
pDc->LineTo(point.x,point.y);
}
pt = point;
pDc->SelectObject(pb);
pDc->SelectObject(pp);
ReleaseDC(pDc);
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDialog::OnMouseMove(nFlags, point);
}
你的代码应该是能绘制的,不过有些其他方面的小问题。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询