//我用图形模式中的 SetROP2(R2_XORPEN)来设置虚框模式
//通调用DrawFocusRect()函数来画!
//问题是从左上角右下角可以画虚框的,但是由右到左,下到上就没有虚框了!这是什么原因呢?
//代码如下:
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);
}
解决方案 »
- 一个关于MFC中的edit控件的问题
- 关于List Control 重写ClistCtrl类
- 今天捡了 20 块钱,与兄弟们分享,散分!
- VC6.0下配置boost库使用正则表达式(转)
- vista改变运行程序的目录名称后出现如下socket问题?
- 监控程序的写法?
- 高价寻求AHPP之类的html加密软件的源代码或可以编写这类软件的高手
- 再放一百分,一个关于OpenGL的问题,在线等待
- 急救:windows98下vc如何获知硬件中断
- 如何让模式或无模式对话框在程序执行中自动关闭??
- vs2008下编译的MFC程序如何才能禁止可视化效果??
- 现在想在数据库表中寻找是否存在与已有的某一条记录完全相同的记录。
画出虚框 最好是直接使用MovoTo和LineTo划线!
{
if(m_bDraw)
{
CClientDC dc(this);
dc.SetROP2(R2_XORPEN); //设置虚框模式
dc.DrawFocusRect(&m_pre);
if (m_ptOrigin.x < point.x)
{
m_new.left = m_ptOrigin.x;
m_new.right = point.x;
}
else
{
m_new.left = point.x;
m_new.right = m_ptOrigin.x;
}
if (m_ptOrigin.y < point.y)
{
m_new.top = m_ptOrigin.y;
m_new.bottom = point.y;
}
else
{
m_new.top = point.y;
m_new.bottom = m_ptOrigin.y;
}
dc.DrawFocusRect(&m_new);//画新矩形
m_pre = m_new;
dc.SetROP2(R2_WHITE);
}
CView::OnMouseMove(nFlags, point);
}
实际上是绘制函数的问题,而不是举行本身