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

📄 demo3view.cpp

📁 Viaual C++实战演练一书的源代码,对于C++程序员有实际的借鉴意义.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	// TODO: Add your command handler code here
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurZoomOut);
	m_nMouseMode = IDT_ZOOMOUT;
}

void CDemo3View::OnMoving() 
{
	// TODO: Add your command handler code here
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurHand);
	m_nMouseMode = IDT_MOVING;
}

void CDemo3View::OnArrow() 
{
	// TODO: Add your command handler code here
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurArrow);
	m_nMouseMode = IDT_ARROW;
}

void CDemo3View::OnCalculate() 
{//计算两点距离
	// TODO: Add your command handler code here
	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurCross);
	m_nMouseMode = IDT_CALCULATE;
}

void CDemo3View::OnUpdateMenuitemLayer1(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CDemo3Doc* pDoc = GetDocument();

	if(!pDoc->m_aLayers.GetSize())
		pCmdUI->Enable(false);
	else
	{
		pCmdUI->Enable();
		pCmdUI->SetCheck(pDoc->m_aLayers.GetAt(0)->m_bCanDraw);
	}
}

void CDemo3View::OnUpdateMenuitemLayer2(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CDemo3Doc* pDoc = GetDocument();

	if(pDoc->m_aLayers.GetSize())
	{
		pCmdUI->Enable();
		pCmdUI->SetCheck(pDoc->m_aLayers.GetAt(1)->m_bCanDraw);
	}
}

void CDemo3View::OnUpdateMenuitemLayer3(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CDemo3Doc* pDoc = GetDocument();

	if(pDoc->m_aLayers.GetSize())
	{
		pCmdUI->Enable();
		pCmdUI->SetCheck(pDoc->m_aLayers.GetAt(2)->m_bCanDraw);
	}
}

void CDemo3View::OnUpdateMenuitemLayer4(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CDemo3Doc* pDoc = GetDocument();

	if(pDoc->m_aLayers.GetSize())
	{
		pCmdUI->Enable();
		pCmdUI->SetCheck(pDoc->m_aLayers.GetAt(3)->m_bCanDraw);
	}
}

void CDemo3View::OnMenuitemLayer1() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();

	if(pDoc->m_aLayers.GetSize())
	{
		pDoc->m_aLayers.GetAt(0)->m_bCanDraw ^= true;
		pDoc->DrawMap(pDoc->m_pMemDC);
		Invalidate(false);
	}
}

void CDemo3View::OnMenuitemLayer2() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();

	if(pDoc->m_aLayers.GetSize())
	{
		pDoc->m_aLayers.GetAt(1)->m_bCanDraw ^= true;
		pDoc->DrawMap(pDoc->m_pMemDC);
		Invalidate(false);
	}
}

void CDemo3View::OnMenuitemLayer3() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();

	if(pDoc->m_aLayers.GetSize())
	{
		pDoc->m_aLayers.GetAt(2)->m_bCanDraw ^= true;
		pDoc->DrawMap(pDoc->m_pMemDC);
		Invalidate(false);
	}
}

void CDemo3View::OnMenuitemLayer4() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();

	if(pDoc->m_aLayers.GetSize())
	{
		pDoc->m_aLayers.GetAt(3)->m_bCanDraw ^= true;
		pDoc->DrawMap(pDoc->m_pMemDC);
		Invalidate(false);
	}
}

void CDemo3View::OnFileClose() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();

	::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurArrow);//设置缺省光标显示
	m_nMouseMode = -1;//取消工具条选择
	pDoc->InitData();//初始化用户数据
	pDoc->SetLayerMenu(false);//清“图层”菜单
	pDoc->DrawMap(pDoc->m_pMemDC);//刷新海图
	Invalidate(false);//更新显示
	pDoc->CDocument::OnNewDocument();//关闭“文档”。必须关闭,否则下次无法打开同一个文档
	pDoc->SetTitle(NULL);
}

void CDemo3View::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	float maxx, maxy;
	long offsetx, offsety;
	long vwidth, vheight;
	CDemo3Doc* pDoc = GetDocument();
	//保存海图原设置
	maxx = pDoc->m_fMaxCX;
	maxy = pDoc->m_fMaxCY;
	offsetx = pDoc->m_nOffsetX;
	offsety = pDoc->m_nOffsetY;
	vwidth = pDoc->m_nViewWidth;
	vheight = pDoc->m_nVeiwHeight;
	//设置海图打印范围
	pDoc->m_nOffsetX = pInfo->m_rectDraw.left;//设置海图偏移
	pDoc->m_nOffsetY = pInfo->m_rectDraw.top;
	pDoc->m_nViewWidth = pInfo->m_rectDraw.right;//设置海图刷新范围
	pDoc->m_nVeiwHeight = pInfo->m_rectDraw.bottom;
	long mx = pInfo->m_rectDraw.Width();
	long my = pInfo->m_rectDraw.Height();
	float axy = maxx / maxy;
	if(my * axy < mx)
	{//打印纸过宽
		pDoc->m_fMaxCX = my*axy;
		pDoc->m_fMaxCY = my;
		pDoc->m_nOffsetX += (pInfo->m_rectDraw.right - pInfo->m_rectDraw.left - pDoc->m_fMaxCX)/2;
			//设置海图打印偏移量,在纸中间打印海图
	}
	else
	{//打印纸过长
		pDoc->m_fMaxCX = mx;
		pDoc->m_fMaxCY = mx/axy;
		pDoc->m_nOffsetY += (pInfo->m_rectDraw.bottom - pInfo->m_rectDraw.top - pDoc->m_fMaxCY)/2;
			//设置海图打印偏移量,在纸中间打印海图
	}

	//打印
	pDoc->DrawMap(pDC);//打印海图
	pDoc->m_pShips->Draw(pDC);//打印动态目标
	
	//恢复海图设置
	pDoc->m_nOffsetX = offsetx;
	pDoc->m_nOffsetY = offsety;
	pDoc->m_fMaxCX = maxx;
	pDoc->m_fMaxCY = maxy;
	pDoc->m_nViewWidth = vwidth;
	pDoc->m_nVeiwHeight = vheight;
	//CView::OnPrint(pDC, pInfo);
}

void CDemo3View::OnUpdateMoving(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable( GetDocument()->m_aLayers.GetSize()>0 );
	pCmdUI->SetCheck(m_nMouseMode == IDT_MOVING);//保持按钮按下状态
}

void CDemo3View::OnUpdateZoomin(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable( GetDocument()->m_aLayers.GetSize()>0 );
	pCmdUI->SetCheck(m_nMouseMode == IDT_ZOOMIN);//保持按钮按下状态
}

void CDemo3View::OnUpdateZoomout(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable( GetDocument()->m_aLayers.GetSize()>0 );
	pCmdUI->SetCheck(m_nMouseMode == IDT_ZOOMOUT);//保持按钮按下状态
}

void CDemo3View::OnUpdateArrow(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable( GetDocument()->m_aLayers.GetSize()>0 );
	pCmdUI->SetCheck(m_nMouseMode == IDT_ARROW);//保持按钮按下状态
}

void CDemo3View::OnUpdateCalculate(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable( GetDocument()->m_aLayers.GetSize()>0 );
	pCmdUI->SetCheck(m_nMouseMode == IDT_CALCULATE);//保持按钮按下状态
}


void CDemo3View::OnTemporary() 
{
	// TODO: Add your command handler code here
	GetDocument()->ProcessPendingLink(InternetAddress[0], InterNetTcpPort[0]);
}


BOOL CDemo3View::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class

	bool stat = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);

	CWnd::SetTimer(FRESHVIEWTIMER_ID, FRESHVIEWTIMER_TIME, NULL);//设置定时器
	//该函数必须在建立CWnd类后使用

	return stat;
}

BOOL CDemo3View::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	CWnd::KillTimer(FRESHVIEWTIMER_ID);
	
	return CView::DestroyWindow();
}

void CDemo3View::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(!m_bMapMoving)
	{
		Invalidate(false);
	}

	CView::OnTimer(nIDEvent);
}

void CDemo3View::OnUpdateDyna0(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CDemo3Doc* pDoc = GetDocument();

	pCmdUI->Enable(pDoc->m_nSelected != 0);
	pCmdUI->SetCheck(pDoc->m_nCanDisplay & 1);
}

void CDemo3View::OnUpdateDyna1(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CDemo3Doc* pDoc = GetDocument();

	pCmdUI->Enable(pDoc->m_nSelected != 1);
	pCmdUI->SetCheck(pDoc->m_nCanDisplay & 2);
}

void CDemo3View::OnUpdateDyna2(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CDemo3Doc* pDoc = GetDocument();

	pCmdUI->Enable(pDoc->m_nSelected != 2);
	pCmdUI->SetCheck(pDoc->m_nCanDisplay & 4);
}

void CDemo3View::OnUpdateDyna3(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CDemo3Doc* pDoc = GetDocument();

	pCmdUI->Enable(pDoc->m_nSelected != 3);
	pCmdUI->SetCheck(pDoc->m_nCanDisplay & 8);
}

void CDemo3View::OnDyna0() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();
	
	if(pDoc->m_nSelected < 0 || pDoc->m_nSelected > 3)
	{
		AfxMessageBox("未启动网络通信功能,无法选择该功能!");
		return;
	}

	CTcpSocket* pTcp;
	if(pTcp = pDoc->ProcessPendingLink(InternetAddress[0], InterNetTcpPort[0]))
	{//网络连接畅通,申请显示航迹
		REQUESTRESEND_20H r;
		r.bh = 0x20;
		r.corp = 1 << pDoc->m_nSelected;
		r.Request = (pDoc->m_nCanDisplay & 1) == 0;
		pTcp->Send((void*)&r, sizeof(r));
	}
	else
	{//清除显示标志
		pDoc->m_nCanDisplay  &= ~ 1;
	}
}

void CDemo3View::OnDyna1() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();
	
	if(pDoc->m_nSelected < 0 || pDoc->m_nSelected > 3)
	{
		AfxMessageBox("未启动网络通信功能,无法选择该功能!");
		return;
	}

	CTcpSocket* pTcp;
	if(pTcp = pDoc->ProcessPendingLink(InternetAddress[1], InterNetTcpPort[1]))
	{//网络连接畅通,申请显示航迹
		REQUESTRESEND_20H r;
		r.bh = 0x20;
		r.corp = 1 << pDoc->m_nSelected;
		r.Request = (pDoc->m_nCanDisplay & 2) == 0;
		pTcp->Send((void*)&r, sizeof(r));
	}
	else
	{//清除显示标志
		pDoc->m_nCanDisplay  &= ~ 2;
	}
}

void CDemo3View::OnDyna2() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();
	
	if(pDoc->m_nSelected < 0 || pDoc->m_nSelected > 3)
	{
		AfxMessageBox("未启动网络通信功能,无法选择该功能!");
		return;
	}

	CTcpSocket* pTcp;
	if(pTcp = pDoc->ProcessPendingLink(InternetAddress[2], InterNetTcpPort[2]))
	{//网络连接畅通,申请显示航迹
		REQUESTRESEND_20H r;
		r.bh = 0x20;
		r.corp = 1 << pDoc->m_nSelected;
		r.Request = (pDoc->m_nCanDisplay & 4) == 0;
		pTcp->Send((void*)&r, sizeof(r));
	}
	else
	{//清除显示标志
		pDoc->m_nCanDisplay  &= ~ 4;
	}
}

void CDemo3View::OnDyna3() 
{
	// TODO: Add your command handler code here
	CDemo3Doc* pDoc = GetDocument();
	
	if(pDoc->m_nSelected < 0 || pDoc->m_nSelected > 3)
	{
		AfxMessageBox("未启动网络通信功能,无法选择该功能!");
		return;
	}

	CTcpSocket* pTcp;
	if(pTcp = pDoc->ProcessPendingLink(InternetAddress[3], InterNetTcpPort[3]))
	{//网络连接畅通,申请显示航迹
		REQUESTRESEND_20H r;
		r.bh = 0x20;
		r.corp = 1 << pDoc->m_nSelected;
		r.Request = (pDoc->m_nCanDisplay & 8) == 0;
		pTcp->Send((void*)&r, sizeof(r));
	}
	else
	{//清除显示标志
		pDoc->m_nCanDisplay  &= ~ 8;
	}
}

⌨️ 快捷键说明

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