⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remotemonitorview.cpp

📁 电缆故障监控系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	// TODO: Add your command handler code here
	//设置当前工具为 漫游 地图平移
	m_nCurTool=ID_PAN;
	HCURSOR hCursor;
    hCursor=AfxGetApp()->LoadCursor(IDC_PAN);
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)hCursor);


	int i;

    CDC* pDC = GetDC();
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	CRemotemonitorDoc* pDoc = GetDocument();

	for(i = pDoc->m_aObjects.GetSize()-1; i >= 0; i--)
	{
		m_usrCurrentObject = pDoc->m_aObjects[i];
		if(m_usrCurrentObject!=NULL)
		{
			m_usrCurrentObject->Selected(pDC, false);
			m_usrCurrentObject = NULL;
		}
	}
	ReleaseDC(pDC);//释放DC资源


}
void CRemotemonitorView::OnUpdatePan(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nCurTool== ID_PAN);
}
void CRemotemonitorView::OnArrow() 
{
	// TODO: Add your command handler code here
	m_nCurTool=ID_ARROW;
	HCURSOR hCursor;
    hCursor=AfxGetApp()->LoadStandardCursor(IDC_ARROW);
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)hCursor);

	int i;
    CDC* pDC = GetDC();
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	CRemotemonitorDoc* pDoc = GetDocument();

	for(i = pDoc->m_aObjects.GetSize()-1; i >= 0; i--)
	{
		m_usrCurrentObject = pDoc->m_aObjects[i];
		if(m_usrCurrentObject!=NULL)
		{
			m_usrCurrentObject->Selected(pDC, false);
			m_usrCurrentObject = NULL;
		}
	}
	ReleaseDC(pDC);//释放DC资源

}


void CRemotemonitorView::ChangetoArrow()//CMainFrame调用
{
   OnArrow();
}

void CRemotemonitorView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	float x,y;
	CPoint pt;
	CRect rect;
	GetClientRect(&rect);

//	CPoint Point=GetDeviceScrollPosition();
//	Point+=point;

    CDC* pDC = GetDC();
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	pDC->DPtoLP(&point);//转换当前点为逻辑位置坐标
	CRemotemonitorDoc* pDoc = GetDocument();

	CRect client;
	GetClientRect(&client);//获得客户区范围
	ClientToScreen(&client);//转化为屏幕坐标
	::ClipCursor(&client);//锁定鼠标移动范围


	switch(m_nCurTool)
	{

	case ID_ARROW:
	   ::ClipCursor(NULL);//锁定鼠标移动范围
       break;
	case ID_ZOOMIN:
        if((m_nScale+10)<=300)
		{
           m_nScale+=10;
	       CSize sizeTotal;
	       sizeTotal.cx=(long)(m_bmInfo.bmWidth*((float)m_nScale/100.0));
	       sizeTotal.cy = (long)(m_bmInfo.bmHeight*((float)m_nScale/100.0));
	       SetScrollSizes(MM_TEXT, sizeTotal);

           point.x=(long)(1.1*(float)(point.x));
           point.y=(long)(1.1*(float)(point.y));
		   if((point.x-rect.Width()/2)>=0)
			   point.x=point.x-rect.Width()/2;
		   else point.x=0;
		   if((point.y-rect.Height()/2)>=0)
			   point.y=point.y-rect.Height()/2;
		   else point.y=0;
		   ScrollToPosition(point);
           Invalidate(TRUE);
		   CStatic* pScaleStatic = &((CMainFrame*)AfxGetMainWnd())->m_scalestatic;
//		   CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
//           pWnd->m_nScale=m_nScale;
		   CString str;
		   str.Format("缩放比例:%d",m_nScale);
		   str+="%";
           pScaleStatic->SetWindowText(str);
		}
		break;
	case ID_ZOOMOUT:
		if((m_bmInfo.bmWidth*((float)((m_nScale-10.0)/100.0))>=rect.Width())||(m_bmInfo.bmHeight*((float)((m_nScale-10.0)/100.0))>=rect.Height()))
		{
           m_nScale-=10;
	       CSize sizeTotal;
	       sizeTotal.cx=(long)(m_bmInfo.bmWidth*((float)m_nScale/100.0));
	       sizeTotal.cy = (long)(m_bmInfo.bmHeight*((float)m_nScale/100.0));
	       SetScrollSizes(MM_TEXT, sizeTotal);

           point.x=(long)(0.9*(float)(point.x));
           point.y=(long)(0.9*(float)(point.y));
		   if((point.x-rect.Width()/2)>=0)
			   point.x=point.x-rect.Width()/2;
		   else point.x=0;
		   if((point.y-rect.Height()/2)>=0)
			   point.y=point.y-rect.Height()/2;
		   else point.y=0;
		   ScrollToPosition(point);
           Invalidate(TRUE);
		   CStatic* pScaleStatic = &((CMainFrame*)AfxGetMainWnd())->m_scalestatic;
//		   CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
//           pWnd->m_nScale=m_nScale;

		   CString str;
		   str.Format("缩放比例:%d",m_nScale);
		   str+="%";
           pScaleStatic->SetWindowText(str);
		}
		break;
	case ID_PAN:
		m_bMouseDown=TRUE;
		m_LastPt=point;
//		SetCapture();
		break;

	case ID_SELECT:
		x=(float)point.x/(float)(m_nScale/100.0);
		y=(float)point.y/(float)(m_nScale/100.0);
		pt.x=(int)(x+0.5);
		pt.y=(int)(y+0.5);
//		if(m_usrCurrentObject && (m_nMoveMode = m_usrCurrentObject->SelectAt(point.x, point.y)))
		if(m_usrCurrentObject && (m_nMoveMode = m_usrCurrentObject->SelectAt(pt.x, pt.y)))
		{//鼠标指针指向以选择的对象,不需再遍历全部对象
			m_usrCurrentObject->Selected(pDC, true);
			m_bMouseDown = TRUE;
		//	m_nCurrentColor = m_usrCurrentObject->GetPenColor();
		//	SetCursor(m_hcurMoving);//设置光标显示
			::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)(AfxGetApp()->LoadCursor(IDC_USERMOVING)));
			break;//跳出switch结构
		}
		int i;
		for(i = pDoc->m_aObjects.GetSize()-1; i >= 0; i--)
		{
			m_usrCurrentObject = pDoc->m_aObjects[i];
			m_nMoveMode = m_usrCurrentObject->SelectAt(pt.x, pt.y);
			if(m_nMoveMode)//判断是否选择当前图元
			{//选择某图元
				m_usrCurrentObject->Selected(pDC, true);
				m_bMouseDown = true;
			//	m_nCurrentColor = m_usrCurrentObject->GetPenColor();
			//	SetCursor(m_hcurMoving);//设置光标显示
			    ::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)(AfxGetApp()->LoadCursor(IDC_USERMOVING)));
				break;
			}
			else
			{
				m_usrCurrentObject->Selected(pDC, false);
			}
			m_usrCurrentObject = NULL;
			m_bMouseDown = false;
		}
		for(i--;i>=0; i--)
		{//清除其他图元的选择
			pDoc->m_aObjects[i]->Selected(pDC, false);
		}
		break;
	case ID_DELETE:
        break;
	case ID_DRAWLINE:
		m_bMouseDown = TRUE;
		m_usrCurrentObject = new CDrawLine(m_nCurrentPenColor,m_nTextColor,m_nCurrentPenWidth);
		x=(float)point.x/(float)(m_nScale/100.0);
		y=(float)point.y/(float)(m_nScale/100.0);
		pt.x=(int)(x+0.5);
		pt.y=(int)(y+0.5);
		m_nMoveMode = m_usrCurrentObject->NewPoint(pt.x, pt.y);
		break;
	case ID_DRAWCIRCLE:
		m_bMouseDown = TRUE;
		m_usrCurrentObject = new CDrawCircle(m_nCurrentPenColor,m_nCurrentFillColor,m_nTextColor);
		x=(float)point.x/(float)(m_nScale/100.0);
		y=(float)point.y/(float)(m_nScale/100.0);
		pt.x=(int)(x+0.5);
		pt.y=(int)(y+0.5);
		m_nMoveMode = m_usrCurrentObject->NewPoint(pt.x, pt.y);
		m_usrCurrentObject->Draw(pDC);
		break;

    default:
        break;	
	}
    ReleaseDC(pDC);//释放DC资源
	CScrollView::OnLButtonDown(nFlags, point);
}

void CRemotemonitorView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
//	CClientDC dc(this);
	float x,y;
	CPoint pt;
	CDC* pDC = GetDC();
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	if(m_bMouseDown)
	{
	    if(m_nCurTool==ID_PAN)
		{
			if((m_LastPt.x-point.x)<0) m_LastPt.x=0;
			else m_LastPt.x-=point.x;
			if((m_LastPt.y-point.y)<0) m_LastPt.y=0;
			else m_LastPt.y-=point.y;
			ScrollToPosition(m_LastPt);
			pDC->DPtoLP(&point);//转换当前点为逻辑位置坐标
			m_LastPt=point;
			//	   Invalidate(TRUE);有了ScrollToPosition实际上已标注了区域无效,无需再说一次
		}
		if(m_usrCurrentObject)
		{
			pDC->DPtoLP(&point);
			x=(float)point.x/(float)(m_nScale/100.0);
			y=(float)point.y/(float)(m_nScale/100.0);
			pt.x=(int)(x+0.5);
			pt.y=(int)(y+0.5);
			m_usrCurrentObject->MoveAt(pDC, m_nMoveMode, pt.x, pt.y);	
		}
	}

	ReleaseDC(pDC);//释放DC资源
	CScrollView::OnMouseMove(nFlags, point);
}
#include <math.h>
void CRemotemonitorView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CDC* pDC = GetDC();//获得DC
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	pDC->DPtoLP(&point);//转换当前点为逻辑位置坐标
	CRemotemonitorDoc* pDoc = GetDocument();

	switch(m_nCurTool)
	{
	case ID_ARROW:
	//	::ClipCursor(NULL);//释放鼠标锁定
	//	m_bMouseDown = false;//停止绘图
	//	SetCursor(m_hcurArrow);//恢复光标显示
	//	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)(AfxGetApp()->LoadStandardCursor(IDC_ARROW)));
	//	Invalidate();//刷新视图
		break;

	case ID_ZOOMIN:
	case ID_ZOOMOUT:
		::ClipCursor(NULL);//释放鼠标锁定
		break;
	case ID_PAN:
		m_bMouseDown=FALSE;
		::ClipCursor(NULL);//释放鼠标锁定
		Invalidate(TRUE);
		break;
	case ID_SELECT:
		::ClipCursor(NULL);//释放鼠标锁定
		m_bMouseDown = false;//停止绘图
	//	SetCursor(m_hcurArrow);//恢复光标显示
		::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)(AfxGetApp()->LoadCursor(IDC_SELECT)));
		if(m_usrCurrentObject)
		   pDoc->SetModifiedFlag(TRUE);

		Invalidate();//刷新视图
		break;

	case ID_DRAWLINE:
		::ClipCursor(NULL);//释放鼠标锁定
		if(m_usrCurrentObject)
		{
			if(m_usrCurrentObject->distance()<10)
				delete m_usrCurrentObject;
			else
				pDoc->m_aObjects.Add(m_usrCurrentObject);
		}
		m_bMouseDown = false;
		m_usrCurrentObject = NULL;
		pDoc->SetModifiedFlag(TRUE);
		Invalidate();//刷新视图
		break;


	case ID_DRAWCIRCLE:
		::ClipCursor(NULL);//释放鼠标锁定
		if(m_usrCurrentObject)
		  pDoc->m_aObjects.Add(m_usrCurrentObject);
		m_bMouseDown = false;
		m_usrCurrentObject = NULL;
		pDoc->SetModifiedFlag(TRUE);
		Invalidate();//刷新视图
		break;
	}
	ReleaseDC(pDC);//释放DC资源
	CScrollView::OnLButtonUp(nFlags, point);
}


void CRemotemonitorView::Viewpenproperties(BOOL bShow) 
{
	// TODO: Add your command handler code here
	if(bShow)
	{
		if(m_pPenProperties==NULL)
		{
			m_pPenProperties=new CPenProperties(this);
			m_pPenProperties->Create(IDD_PENPROPERTIES,this);
			m_pPenProperties->ShowWindow(SW_SHOW);
		}
		else 
			m_pPenProperties->SetActiveWindow();
	}
	else
	{
//		m_pPenProperties->DestroyWindow();
		delete m_pPenProperties;
		m_pPenProperties=NULL;
	}
}
void CRemotemonitorView::OnMapchange() 
{
	// TODO: Add your command handler code here
    CFileDialog fileopenbox(TRUE,NULL,NULL,OFN_HIDEREADONLY,"地图(*.bmp)|*.bmp|",NULL);	
	if(fileopenbox.DoModal()!=IDOK) return;
	m_strMapPathName=fileopenbox.GetPathName();

    SetRedraw(FALSE);
	if(m_hOldBitmap&&m_hMemoryDC)
	{
		SelectObject(m_hMemoryDC,m_hOldBitmap);
		m_hOldBitmap=NULL;
	}
	if(m_hBitmap)
	{
		DeleteObject(m_hBitmap);
        m_hBitmap=NULL;
	}
	if(m_hMemoryDC)
	{
		DeleteDC(m_hMemoryDC);
        m_hMemoryDC=NULL;
	}
	   initMemoryDC();
       m_nScale=100;
	   CStatic* pScaleStatic = &((CMainFrame*)AfxGetMainWnd())->m_scalestatic;
//	   CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
//	   pWnd->m_nScale=m_nScale;
	   
	   CString str;
	   str.Format("缩放比例:%d",m_nScale);
	   str+="%";
	   pScaleStatic->SetWindowText(str);
	   
	   SetRedraw(TRUE);	
	   Invalidate(TRUE);
//	}
}

void CRemotemonitorView::OnDrawline() 
{
	// TODO: Add your command handler code here
	m_nCurTool=ID_DRAWLINE;
	HCURSOR hCursor;
    hCursor=AfxGetApp()->LoadCursor(IDC_USERDRAW);
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)hCursor);
	int i;
    CDC* pDC = GetDC();
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	CRemotemonitorDoc* pDoc = GetDocument();

	for(i = pDoc->m_aObjects.GetSize()-1; i >= 0; i--)
	{
		m_usrCurrentObject = pDoc->m_aObjects[i];
		m_usrCurrentObject->Selected(pDC, false);
		m_usrCurrentObject = NULL;
	}
	ReleaseDC(pDC);//释放DC资源
	
}

void CRemotemonitorView::OnDrawcircle() 
{
	// TODO: Add your command handler code here
	m_nCurTool=ID_DRAWCIRCLE;
	HCURSOR hCursor;
    hCursor=AfxGetApp()->LoadCursor(IDC_USERDRAW);
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)hCursor);
	int i;
    CDC* pDC = GetDC();
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	CRemotemonitorDoc* pDoc = GetDocument();

	for(i = pDoc->m_aObjects.GetSize()-1; i >= 0; i--)
	{
		m_usrCurrentObject = pDoc->m_aObjects[i];
		m_usrCurrentObject->Selected(pDC, false);
		m_usrCurrentObject = NULL;
	}
	ReleaseDC(pDC);//释放DC资源
	
}

void CRemotemonitorView::OnUpdateDrawline(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
    CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
	pCmdUI->Enable(pWnd->m_bFlag);

	pCmdUI->SetCheck(m_nCurTool== ID_DRAWLINE);
	
}

void CRemotemonitorView::OnUpdateDrawcircle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
    CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
	pCmdUI->Enable(pWnd->m_bFlag);

	pCmdUI->SetCheck(m_nCurTool== ID_DRAWCIRCLE);
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -