我在练习画图,画直线,矩形,椭圆,我用到了虚框,开始画的时候有个虚框,但是画完后还有,
我的问题是怎么让画完图后虚框消失!
下面是我的程序:void CGraphicView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin=point;
m_bDraw=TRUE; m_pre.left=point.x;
m_pre.top=point.y;
m_pre.right=point.x;
m_pre.bottom=point.y;
m_new.left=point.x;
m_new.top=point.y;
m_new.right=point.x;
m_new.bottom=point.y;
CView::OnLButtonDown(nFlags, point);
}
void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bDraw=FALSE;
CClientDC dc(this);
CPen pen(PS_SOLID,3,RGB(255,0,0));
dc.SelectObject(&pen);
dc.SetROP2(R2_COPYPEN);
switch(m_nDrawType)
{
case 1:
dc.SetPixel(point,RGB(255,0,0));
break;
case 2:
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
break;
case 3:
dc.Rectangle(CRect(m_ptOrigin,point));
break;
case 4:
dc.Ellipse(CRect(m_ptOrigin,point));
break;
}
CView::OnLButtonUp(nFlags, point);
}
void CGraphicView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDraw)
{
CClientDC dc(this);
dc.SetROP2(R2_XORPEN); //设置虚框模式
dc.DrawFocusRect(&m_pre);
m_new.right=point.x;
m_new.bottom=point.y;
dc.DrawFocusRect(&m_new);//画新矩形
m_pre.right=m_new.right;
m_pre.bottom=m_new.bottom;
dc.SetROP2(R2_WHITE);
}
CView::OnMouseMove(nFlags, point);
}
我的问题是怎么让画完图后虚框消失!
下面是我的程序:void CGraphicView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin=point;
m_bDraw=TRUE; m_pre.left=point.x;
m_pre.top=point.y;
m_pre.right=point.x;
m_pre.bottom=point.y;
m_new.left=point.x;
m_new.top=point.y;
m_new.right=point.x;
m_new.bottom=point.y;
CView::OnLButtonDown(nFlags, point);
}
void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bDraw=FALSE;
CClientDC dc(this);
CPen pen(PS_SOLID,3,RGB(255,0,0));
dc.SelectObject(&pen);
dc.SetROP2(R2_COPYPEN);
switch(m_nDrawType)
{
case 1:
dc.SetPixel(point,RGB(255,0,0));
break;
case 2:
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
break;
case 3:
dc.Rectangle(CRect(m_ptOrigin,point));
break;
case 4:
dc.Ellipse(CRect(m_ptOrigin,point));
break;
}
CView::OnLButtonUp(nFlags, point);
}
void CGraphicView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDraw)
{
CClientDC dc(this);
dc.SetROP2(R2_XORPEN); //设置虚框模式
dc.DrawFocusRect(&m_pre);
m_new.right=point.x;
m_new.bottom=point.y;
dc.DrawFocusRect(&m_new);//画新矩形
m_pre.right=m_new.right;
m_pre.bottom=m_new.bottom;
dc.SetROP2(R2_WHITE);
}
CView::OnMouseMove(nFlags, point);
}
解决方案 »
- 达人搜索软件公布了源代码
- IOCP非常严重的问题,DisconnectEx关闭连接无响应。
- 关于英汉互译的翻译
- 添加Dlg类的时候出错
- RegisterHotKey如何在多个窗口中响应
- 求有效的进行宏定义的方向查找的方法
- 问一个比较简单的问题,关于传参数的。
- 为什么m_Edit.SetReadOnly(true)管用 m_Edit.ModifyStyle(0,ES_READONLY)不管用?
- 一个简单的画图程序,用scrollview,怎样调整滚动条?(在线等待)
- 怎样为对话框或其他控件设置背景图案?
- delete[] 指针出错。弹出access violation 窗口
- 寒冷冬天,请保护我们的计算机设备。有几点要注意。善意提醒,敬请留意。
而且就算是及时触发了也会造成屏幕闪烁。
使用内存绘图,因为在内存里面绘制后直接贴图到屏幕上,时间快,因此不会闪烁。
楼主可以参考下面的代码来试试:CDC *pdc=this->GetDC(); //这里是pdc 等同于楼主的&dc
CDC MenDC;
CBitmap bm;
CRect rt;
GetClientRect(&rt);
MenDC.CreateCompatibleDC(pdc);
bm.CreateCompatibleBitmap(pdc,rt.Width(),rt.Height());
MenDC.SelectObject(&bm);
//-------------------------------------------------------------------
//在这里使用MenDC来绘图,一定要是MenDC(内存DC)
//-------------------------------------------------------------------
pdc->BitBlt(0,0,rt.Width(),rt.Height(),&MenDC,0,0,SRCCOPY);
MenDC.DeleteDC();
bm.DeleteObject();
ReleaseDC(pdc);
if(m_bDraw)
{
CClientDC dc(this);
dc.SetROP2(R2_XORPEN);
dc.DrawFocusRect(&m_pre);
dc.SetROP2(R2_WHITE);
}
void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bDraw=FALSE;
CClientDC dc(this); dc.SetROP2(R2_XORPEN); //设置虚框模式
dc.DrawFocusRect(&m_pre); CPen pen(PS_SOLID,3,RGB(255,0,0));
dc.SelectObject(&pen);
dc.SetROP2(R2_COPYPEN);
switch(m_nDrawType)
{
case 1:
dc.SetPixel(point,RGB(255,0,0));
break;
case 2:
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
break;
case 3:
dc.Rectangle(CRect(m_ptOrigin,point));
break;
case 4:
dc.Ellipse(CRect(m_ptOrigin,point));
break;
}
CView::OnLButtonUp(nFlags, point);}void CGraphicView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDraw)
{
CClientDC dc(this);
dc.SetROP2(R2_XORPEN); //设置虚框模式
if (!m_pre.IsRectEmpty())
dc.DrawFocusRect(&m_pre);
m_new.right=point.x;
m_new.bottom=point.y;
if (!m_new.IsRectEmpty())
dc.DrawFocusRect(&m_new);//画新矩形
m_pre.right=m_new.right;
m_pre.bottom=m_new.bottom;
dc.SetROP2(R2_WHITE);
}
CView::OnMouseMove(nFlags, point);}