目的:当鼠标移动时,画两条交叉直线,但是不影响其他图形,移出时清除这两条交叉直线,进入区域时再绘制
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);
}
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);
}
清除代码该怎么加?
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;
}
发个代码你跑跑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);
}
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();
}
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;
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;