鼠标移动,画两条交叉直线SetROP2问题 急!!!

yzhgr 2009-02-13 11:47:23
目的:当鼠标移动时,画两条交叉直线,但是不影响其他图形,移出时清除这两条交叉直线,进入区域时再绘制


void CDraw_BitView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC = GetDC();

if (point.x<=LEFTSPACE || point.x>=LX-RIGHTSPACE||point.y<=TOPSPACE || point.y>=LY-BOTTOMSPACE){

//这里想当鼠标移出指定区域时,清除移动时画出的两条直线,但不影响其他图像。
清除代码该怎么加?
return;
}

int nmoveOldDrawMode=pDC->SetROP2(R2_XORPEN);

pDC->SelectObject(&penthinwhite);

if (showing){


pDC->MoveTo(LEFTSPACE+XPBJSPACE,m_nowpoint.y);
pDC->LineTo(LX-RIGHTSPACE-XPBJSPACE,m_nowpoint.y);
pDC->MoveTo(m_nowpoint.x,TOPSPACE+XPBJSPACE);
pDC->LineTo(m_nowpoint.x,LY-BOTTOMSPACE-XPBJSPACE);
}

//m_ptPrev = point;
m_nowpoint=point;

pDC->MoveTo(LEFTSPACE+XPBJSPACE,m_nowpoint.y);
pDC->LineTo(LX-RIGHTSPACE-XPBJSPACE,m_nowpoint.y);
pDC->MoveTo(m_nowpoint.x,TOPSPACE+XPBJSPACE);
pDC->LineTo(m_nowpoint.x,LY-BOTTOMSPACE-XPBJSPACE);

pDC->SetROP2(nmoveOldDrawMode);

ReleaseDC(pDC);
CView::OnMouseMove(nFlags, point);
}
...全文
279 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzhouen 2009-02-18
  • 打赏
  • 举报
回复
if (showing){ //在指定区域之外,清除一次所画交叉直线
m_ptPrev = m_nowpoint;
int nmoveOldDrawMode=pDC->SetROP2(R2_NOT); //需要加上
pDC->MoveTo(LEFTSPACE+XPBJSPACE,m_ptPrev.y);
pDC->LineTo(LX-RIGHTSPACE-XPBJSPACE,m_ptPrev.y);
pDC->MoveTo(m_ptPrev.x,TOPSPACE+XPBJSPACE);
pDC->LineTo(m_ptPrev.x,LY-BOTTOMSPACE-XPBJSPACE);
pDC->SetROP2(nmoveOldDrawMode); //需要加上
showing=false;
yzhouen 2009-02-18
  • 打赏
  • 举报
回复
if (showing){ //在指定区域之外,清除一次所画交叉直线
m_ptPrev = m_nowpoint;
int nmoveOldDrawMode=pDC->SetROP2(R2_NOT); //需要加上
pDC->MoveTo(LEFTSPACE+XPBJSPACE,m_ptPrev.y);
pDC->LineTo(LX-RIGHTSPACE-XPBJSPACE,m_ptPrev.y);
pDC->MoveTo(m_ptPrev.x,TOPSPACE+XPBJSPACE);
pDC->LineTo(m_ptPrev.x,LY-BOTTOMSPACE-XPBJSPACE);
pDC->SetROP2(nmoveOldDrawMode); //需要加上
showing=false;
yzhgr 2009-02-18
  • 打赏
  • 举报
回复
UP一下
yzhgr 2009-02-17
  • 打赏
  • 举报
回复
我现在是能清除画的直线了,但是画的背景图被影响了,怎么回事?
void CDraw_BitView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC = GetDC();
CString str;
if (point.x<=LEFTSPACE || point.x>=LX-RIGHTSPACE||point.y<=TOPSPACE || point.y>=LY-BOTTOMSPACE){

if (showing){ //在指定区域之外,清除一次所画交叉直线
m_ptPrev = m_nowpoint;
pDC->MoveTo(LEFTSPACE+XPBJSPACE,m_ptPrev.y);
pDC->LineTo(LX-RIGHTSPACE-XPBJSPACE,m_ptPrev.y);
pDC->MoveTo(m_ptPrev.x,TOPSPACE+XPBJSPACE);
pDC->LineTo(m_ptPrev.x,LY-BOTTOMSPACE-XPBJSPACE);
showing=false;
}
return;
}
if (ShowLineMode){ //ShowLineMode为真表示鼠标移动是需要画交叉直线
int nmoveOldDrawMode=pDC->SetROP2(R2_NOT);

pDC->SelectObject(&penthinwhite);

if (showing){ //如果已经画过交叉直线,先清除直线的直线
pDC->MoveTo(LEFTSPACE+XPBJSPACE,m_nowpoint.y);
pDC->LineTo(LX-RIGHTSPACE-XPBJSPACE,m_nowpoint.y);
pDC->MoveTo(m_nowpoint.x,TOPSPACE+XPBJSPACE);
pDC->LineTo(m_nowpoint.x,LY-BOTTOMSPACE-XPBJSPACE);
}

m_nowpoint=point;

pDC->MoveTo(LEFTSPACE+XPBJSPACE,m_nowpoint.y);
pDC->LineTo(LX-RIGHTSPACE-XPBJSPACE,m_nowpoint.y);
pDC->MoveTo(m_nowpoint.x,TOPSPACE+XPBJSPACE);
pDC->LineTo(m_nowpoint.x,LY-BOTTOMSPACE-XPBJSPACE);

pDC->SetROP2(nmoveOldDrawMode);


showing=TRUE;

}
ReleaseDC(pDC);
CView::OnMouseMove(nFlags, point);
}


在ONDRAW中调用了画背景图函数

void CDraw_BitView::Draw_BackGround(int mode)
{
CDC *pdcView = this->GetDC();
CRect rt;
this->GetClientRect(&rt);

m_dcMemory.FillSolidRect(&rt, 0x00FFFFFF);
CFont fonts,fontn,fontb,fonts1;
VERIFY(fonts1.CreatePointFont(80, "宋体", &m_dcMemory));
VERIFY(fonts.CreatePointFont(90, "宋体", &m_dcMemory));
VERIFY(fontb.CreatePointFont(120, "宋体", &m_dcMemory));
VERIFY(fontn.CreatePointFont(100, "宋体", &m_dcMemory));

// CFont* def_font = pdcView->GetCurrentFont();

CString str;
CRect rc;
GetClientRect(&rc);
LX=rc.right;
LY=rc.bottom;

CBrush brush(RGB(0,0,0));
CRect rect;
GetClientRect(rect);
m_dcMemory.FillRect(rect,&brush);
m_dcMemory.SetBkColor(RGB(0, 0, 0));
m_dcMemory.SetTextColor(RGB(255, 255, 0));

m_dcMemory.SelectObject(&penthinZs);
//X轴
m_dcMemory.MoveTo(LEFTSPACE,TOPSPACE);
m_dcMemory.LineTo(LX-RIGHTSPACE,TOPSPACE);
m_dcMemory.LineTo(LX-RIGHTSPACE,LY-TOPSPACE);
m_dcMemory.LineTo(LEFTSPACE,LY-TOPSPACE);
m_dcMemory.LineTo(LEFTSPACE,TOPSPACE);


m_dcMemory.SetTextColor(RGB(255,255,255));
m_dcMemory.SelectObject(&penthinZs_x);
m_dcMemory.SelectObject(&fonts);
str.Format("%d",0);
m_dcMemory.TextOut(10,LY-BOTTOMSPACE-ZJSCOPE,str);
for (int j=1;j<VERSCOPE;j++){
m_dcMemory.MoveTo(LEFTSPACE,TOPSPACE+j*(LY-TOPSPACE-BOTTOMSPACE)/VERSCOPE);
m_dcMemory.LineTo(LX-RIGHTSPACE,TOPSPACE+j*(LY-TOPSPACE-BOTTOMSPACE)/VERSCOPE);
str.Format("%d",j*43200/VERSCOPE);
m_dcMemory.TextOut(10,LY-BOTTOMSPACE-j*(LY-TOPSPACE-BOTTOMSPACE)/VERSCOPE-ZJSCOPE,str);
}

str.Format("%d",j*43200/VERSCOPE);
m_dcMemory.TextOut(10,LY-BOTTOMSPACE-j*(LY-TOPSPACE-BOTTOMSPACE)/VERSCOPE-ZJSCOPE,str);


m_dcMemory.SelectObject(def_font);

str.Format("高度(M)");
m_dcMemory.TextOut(15,15,str);


m_dcMemory.SelectObject(def_font);


pdcView->BitBlt(0, 0, rt.Width(), rt.Height(), &m_dcMemory, 0, 0, SRCCOPY);

fonts.DeleteObject();
fontb.DeleteObject();
fontn.DeleteObject();
}
jinlingzwp 2009-02-13
  • 打赏
  • 举报
回复
设置反色,重绘
cnzdgs 2009-02-13
  • 打赏
  • 举报
回复
再重画一次就擦掉了,两次异或就等于没画。
mxw0922 2009-02-13
  • 打赏
  • 举报
回复
不在指定区域时,不画这两条线不就行了!
或者设定一个范围,在这个范围内才画这两条线。
还解决不了,发你段我实现的代码给你参考。
a_rockboy 2009-02-13
  • 打赏
  • 举报
回复
if (point.x <=LEFTSPACE || point.x>=LX-RIGHTSPACE||point.y <=TOPSPACE || point.y>=LY-BOTTOMSPACE){

//这里想当鼠标移出指定区域时,清除移动时画出的两条直线,但不影响其他图像。
清除代码该怎么加?
if (showing){

int nmoveOldDrawMode=pDC->SetROP2(R2_XORPEN);

pDC->SelectObject(&penthinwhite);

pDC->MoveTo(LEFTSPACE+XPBJSPACE,m_nowpoint.y);
pDC->LineTo(LX-RIGHTSPACE-XPBJSPACE,m_nowpoint.y);
pDC->MoveTo(m_nowpoint.x,TOPSPACE+XPBJSPACE);
pDC->LineTo(m_nowpoint.x,LY-BOTTOMSPACE-XPBJSPACE);

pDC->SetROP2(nmoveOldDrawMode);
}

return;
}
Hiiishe 2009-02-13
  • 打赏
  • 举报
回复
设置一个成员变量保存上次的坐标点,

在鼠标移动中先画上次再画本次,然后保存本次到成员变量,既可
发个代码你跑跑



void CCrossDrawer::OnMouseMove( UINT nFlag, CPoint pt, CView* pView )
{
::SetCursor(LoadCursor(0, MAKEINTRESOURCE(IDC_CROSS)));
pView->GetClientRect(&m_rectClient);
m_rectClient.NormalizeRect();
CClientDC dc(pView);
pView->OnPrepareDC(&dc);

CPen pen(PS_SOLID, 0, RGB(0,116,226));
CPen* pOldpen = dc.SelectObject(&pen);
int iOldRP2 = dc.SetROP2(R2_NOT);
if (m_ptPre.x != -999)
{
dc.BeginPath();
dc.MoveTo(CPoint(m_ptPre.x, m_rectClient.top));
dc.LineTo(CPoint(m_ptPre.x, m_rectClient.bottom));
dc.MoveTo(CPoint(m_rectClient.left, m_ptPre.y));
dc.LineTo(CPoint(m_rectClient.right, m_ptPre.y));
}
dc.BeginPath();
dc.MoveTo(CPoint(pt.x, m_rectClient.top));
dc.LineTo(CPoint(pt.x, m_rectClient.bottom));
dc.MoveTo(CPoint(m_rectClient.left, pt.y));
dc.LineTo(CPoint(m_rectClient.right, pt.y));
m_ptPre = pt;
dc.SetROP2(iOldRP2);
dc.SelectObject(pOldpen);
}

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧