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

📄 mapdlg.cpp

📁 一个完整的数字硬盘录像机系统软件
💻 CPP
字号:
// MapDlg.cpp : implementation file
//

#include "stdafx.h"
#include "gtmpeg.h"
#include "MapDlg.h"
#include "ImageObject.h"
#include "PosTxtDlg.h"
#include "Chunnel.h"
#include "GtMpegWnd.h"
#include "HelpDlg.h"
#include "DeviceLstDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
CMapDlg::CMapDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMapDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMapDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_pMap=NULL;
	m_nPosNums=0;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CMapDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMapDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CMapDlg, CDialog)
	//{{AFX_MSG_MAP(CMapDlg)
	ON_WM_PAINT()
	ON_WM_LBUTTONDBLCLK()
	ON_BN_CLICKED(IDC_RESET, OnReset)
	ON_BN_CLICKED(IDC_ZONE_INIT, OnZoneInit)
	ON_BN_CLICKED(IDC_RESET2, OnReset2)
	ON_BN_CLICKED(IDC_HELP1, OnHelp)
	ON_BN_CLICKED(IDC_DEVICE_LST, OnDeviceLst)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CMapDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CString sPath=GetAppPath()+"电子地图.jpg";
	m_pMap=new CImageObject(sPath);
	CRect rect;
	GetClientRect(rect);
	rect.top=0;
    rect.bottom=rect.top+m_pMap->GetHeight()+15;
	rect.right=rect.left+m_pMap->GetWidth()+80;
	//ScreenToClient(rect);
	//ClientToScreen(rect);
	MoveWindow(rect);
	GetDlgItem(IDOK)->GetWindowRect(rect);
    rect.top=25;
	rect.bottom=rect.top+30;
	rect.left=m_pMap->GetWidth()+10;
	rect.right=rect.left+60;
	ScreenToClient(rect);
    GetDlgItem(IDOK)->MoveWindow(rect);
	//
	GetDlgItem(IDC_RESET)->GetWindowRect(rect);
    rect.top=25+30;
	rect.bottom=rect.top+30;
	rect.left=m_pMap->GetWidth()+10;
	rect.right=rect.left+60;
	ScreenToClient(rect);
    GetDlgItem(IDC_RESET)->MoveWindow(rect);

	//IDC_ZONE_INIT
	GetDlgItem(IDC_ZONE_INIT)->GetWindowRect(rect);
    rect.top=25+30+30;
	rect.bottom=rect.top+30;
	rect.left=m_pMap->GetWidth()+10;
	rect.right=rect.left+60;
	ScreenToClient(rect);
    GetDlgItem(IDC_ZONE_INIT)->MoveWindow(rect);
	//IDC_RESET2
	GetDlgItem(IDC_RESET2)->GetWindowRect(rect);
    rect.top=25+30+30+30;
	rect.bottom=rect.top+30;
	rect.left=m_pMap->GetWidth()+10;
	rect.right=rect.left+60;
	ScreenToClient(rect);
    GetDlgItem(IDC_RESET2)->MoveWindow(rect);
    //IDC_HELP
	GetDlgItem(IDC_HELP1)->GetWindowRect(rect);
    rect.top=25+30+30+30+30;
	rect.bottom=rect.top+30;
	rect.left=m_pMap->GetWidth()+10;
	rect.right=rect.left+60;
	ScreenToClient(rect);
    GetDlgItem(IDC_HELP1)->MoveWindow(rect);
    //IDC_DEVICE_LST
	GetDlgItem(IDC_DEVICE_LST)->GetWindowRect(rect);
    rect.top=25+30+30+30+30+30;
	rect.bottom=rect.top+30;
	rect.left=m_pMap->GetWidth()+10;
	rect.right=rect.left+60;
	ScreenToClient(rect);
    GetDlgItem(IDC_DEVICE_LST)->MoveWindow(rect);
    //CenterWindow();
//	m_TxtFile.Open("D:\\Map.txt",CFile::modeWrite);
	int PosNums=0;
    char strRet[MAX_PATH];
	for(int i=0;i<MAX_PATH;i++)
	    strRet[i]=0; 
	CString sSection,sKey,sIniFileName;
	sIniFileName=GetAppPath()+"GTMap.Ini";
    sSection="Map";
	sKey="MapPoints";
	GetPrivateProfileString(sSection,sKey,"",strRet,MAX_PATH,sIniFileName);
    CString sTmp=strRet;
    m_nPosNums=StringToInt(sTmp);
	sKey="Title";
	GetPrivateProfileString(sSection,sKey,"",strRet,MAX_PATH,sIniFileName);
	SetWindowText(strRet);
 	int nLink=GetPrivateProfileInt("Map","Link",0,sIniFileName);
	CGtMpegWnd* pGtWnd=(CGtMpegWnd*)theApp.m_pMainWnd;
	for(i=0;i<m_nPosNums;i++)
	{
	   CPoint point=GetPosPoint(i);
	   CString sCaption=GetPosCaption(i);
	   CAlarmLamp *pWnd=new CAlarmLamp;
	   pWnd->CreatePoint(sCaption,point,this,2000+i);
	   m_LampLst.Add(pWnd);
	   int nChunnel=GetChunnel(i);
       if(nLink==1&&nChunnel!=-1)
	   {
	      CUIntArray Zones;
		  GetPosZones(i,Zones);
		  for(int j=0;j<Zones.GetSize();j++)
		  {
		     CChunnel *pChunnel=pGtWnd->GetChunnel(nChunnel);
			 CZone *pZone=pChunnel->GetZone(Zones.GetAt(j)-1);
			 if(pZone->m_nType!=7)
			 {
			    CSecondary *pSecondary=NULL;
				if(pZone->GetBindSecondary()!=-1)
				{
				   pSecondary=pChunnel->GetSecondary(pZone->GetBindSecondary());
				   if(pSecondary->GetStates())
				   {
				      pWnd->SetSway(TRUE);
				   }
				}
				else if(pZone->m_nBindSecondary2!=-1)
				{
				   pSecondary=pChunnel->GetSecondary(pZone->m_nBindSecondary2);
				   if(pSecondary->GetStates())
				   {
				      pWnd->SetSway(TRUE);
				   }
				}
			 }
		  }
	   }
	}
	return TRUE;
}
//////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////
CPoint CMapDlg::GetPosPoint(int nIndex)
{
    CString sIniFileName;
	sIniFileName=GetAppPath()+"GtMap.ini";
	char strRet[MAX_PATH];
	for(int i=0;i<MAX_PATH;i++)
	    strRet[i]=0;
	CString sKey;
	CString sSection;
	sSection.Format("Pos_%d",nIndex+1);
	sKey="Point";
	GetPrivateProfileString(sSection,sKey,"",strRet,MAX_PATH,sIniFileName);
	CString sTmp,sTmp1,sTmp2;
	sTmp=strRet;
	int nFind;
	nFind=sTmp.Find(",");
	if(nFind==-1)
		return CPoint(0,0);
    sTmp1=sTmp.Left(nFind);
	sTmp2=sTmp.Right(sTmp.GetLength()-nFind-1);
	CPoint point;
	point.x=StringToInt(sTmp1);
	point.y=StringToInt(sTmp2);
	return point;
}
//////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////
CString CMapDlg::GetPosCaption(int nIndex)
{
    CString sIniFileName;
	sIniFileName=GetAppPath()+"GtMap.ini";
	char strRet[MAX_PATH];
	for(int i=0;i<MAX_PATH;i++)
	    strRet[i]=0;
	CString sKey;
	CString sSection;
	sSection.Format("Pos_%d",nIndex+1);
	sKey="Caption";
	GetPrivateProfileString(sSection,sKey,"",strRet,MAX_PATH,sIniFileName);
	CString sTmp,sTmp1,sTmp2;
	sTmp=strRet;
	return sTmp;
}
//////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////
CString CMapDlg::GetPosTxt(int nIndex)
{
    CString sIniFileName;
	sIniFileName=GetAppPath()+"GtMap.ini";
	char strRet[MAX_PATH];
	for(int i=0;i<MAX_PATH;i++)
	    strRet[i]=0;
	CString sKey;
	CString sSection;
	sSection.Format("Pos_%d",nIndex+1);
	sKey="Txt";
	GetPrivateProfileString(sSection,sKey,"",strRet,MAX_PATH,sIniFileName);
	CString sTmp;
	sTmp=strRet;
	return sTmp;
}
//////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////
void CMapDlg::WriteMap(int nIndex,CString sKey,CString sTxt)
{
   CString sIniFileName=GetAppPath()+"GtMap.ini";
   CString sSection;
   sSection.Format("Pos_%d",nIndex+1);
   WritePrivateProfileString(sSection,sKey,sTxt,sIniFileName);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CMapDlg::GetPosZones(int nIndex,CUIntArray &Zones)
{
   CString sIniFileName=GetAppPath()+"GtMap.ini";
   CString sSection;
   sSection.Format("Pos_%d",nIndex+1);
   char strRet[MAX_PATH];
   for(int i=0;i<MAX_PATH;i++)
	    strRet[i]=0;
	GetPrivateProfileString(sSection,"Zones","",strRet,MAX_PATH,sIniFileName);
	CString sTmp;
	sTmp=strRet;
	Zones.SetSize(0);
	int nFind=sTmp.Find(",");
	while(nFind!=-1)
	{
	   CString sTmp1=sTmp.Left(nFind);
	   if(sTmp1!="")
	      Zones.Add(StringToInt(sTmp1));
	   sTmp=sTmp.Right(sTmp.GetLength()-nFind-1);
	   nFind=sTmp.Find(",");
	}
	if(sTmp!="")
		Zones.Add(StringToInt(sTmp));
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CMapDlg::WritePosZones(int nIndex,CUIntArray &Zones)
{
   CString sIniFileName=GetAppPath()+"GtMap.ini";
   CString sSection;
   sSection.Format("Pos_%d",nIndex+1);
   CString sTxt="";
   for(int i=0;i<Zones.GetSize();i++)
   {
      CString sTmp;
	  sTmp.Format("%d",Zones.GetAt(i));
	  sTxt+=sTmp;
	  sTxt+=",";
   }
   WritePrivateProfileString(sSection,"Zones",sTxt,sIniFileName);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
int CMapDlg::GetChunnel(int nIndex)
{
    CString sIniFileName;
	sIniFileName=GetAppPath()+"GtMap.ini";
	char strRet[MAX_PATH];
	for(int i=0;i<MAX_PATH;i++)
	    strRet[i]=0;
	CString sSection;
	sSection.Format("Pos_%d",nIndex+1);
	GetPrivateProfileString(sSection,"Chunnel","-1",strRet,MAX_PATH,sIniFileName);
	CString sTmp;
	sTmp=strRet;
	if(sTmp=="")
		return -1;
	return StringToInt(sTmp);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CMapDlg::WriteChunnel(int nIndex,int nChunnel)
{
   CString sIniFileName=GetAppPath()+"GtMap.ini";
   CString sSection,sTxt;
   sSection.Format("Pos_%d",nIndex+1);
   sTxt.Format("%d",nChunnel);
   WritePrivateProfileString(sSection,"Chunnel",sTxt,sIniFileName);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CMapDlg::OnOK() 
{
	for(int i=0;i<m_LampLst.GetSize();i++)
	{
	   delete m_LampLst.GetAt(i);
	}
    m_LampLst.RemoveAll();
	CDialog::OnOK();
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
void CMapDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	if(m_pMap != NULL)
	{
	   	CRect rect;
		int nx=0,ny=0;
		m_pMap->Draw(&dc,nx,ny);
	}
	
}
//////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////
void CMapDlg::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
/*	CString sTxt;
	sTxt.Format("%d,%d",point.x,point.y);
	sTxt+="\r\n";
	m_TxtFile.WriteString(sTxt);*/
	CDialog::OnLButtonDblClk(nFlags, point);
}
//////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////
BOOL CMapDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
{
	NMHDR *Msg=(NMHDR *)lParam;
	if(wParam=2000)
	{
	    int nIndex=Msg->code-2000;
        CPosTxtDlg dlg(nIndex,this);
		if(dlg.DoModal()==IDOK)
		{
		   //m_LampLst.GetAt(nIndex)->SetCaption(GetPosCaption(nIndex));
		   //m_LampLst.GetAt(nIndex)->SetSway(TRUE);
		}
		return TRUE;
	}
	return CDialog::OnNotify(wParam, lParam, pResult);
}
//////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////
void CMapDlg::OnReset() 
{
	for(int i=0;i<m_nPosNums;i++)
	{
		m_LampLst.GetAt(i)->SetCaption(GetPosCaption(i));
		m_LampLst.GetAt(i)->SetSway(FALSE);
	}
	CString sIniFileName;
	sIniFileName=GetAppPath()+"GTMap.Ini";
	CGtMpegWnd* pGtWnd=(CGtMpegWnd*)theApp.m_pMainWnd;
 	int nLink=GetPrivateProfileInt("Map","Link",0,sIniFileName);
	for(i=0;i<m_nPosNums;i++)
	{
	   int nChunnel=GetChunnel(i);
       if(nLink==1&&nChunnel!=-1)
	   {
	      CUIntArray Zones;
		  GetPosZones(i,Zones);
		  for(int j=0;j<Zones.GetSize();j++)
		  {
		     CChunnel *pChunnel=pGtWnd->GetChunnel(nChunnel);
			 CZone *pZone=pChunnel->GetZone(Zones.GetAt(j)-1);
			 if(pZone->m_nType!=7)
			 {
			    CSecondary *pSecondary=NULL;
				if(pZone->GetBindSecondary()!=-1)
				{
				   pSecondary=pChunnel->GetSecondary(pZone->GetBindSecondary());
				   if(pSecondary->GetStates())
				   {
				      m_LampLst.GetAt(i)->SetSway(TRUE);
				   }
				}
				else if(pZone->m_nBindSecondary2!=-1)
				{
				   pSecondary=pChunnel->GetSecondary(pZone->m_nBindSecondary2);
				   if(pSecondary->GetStates())
				   {
				      m_LampLst.GetAt(i)->SetSway(TRUE);
				   }
				}
			 }
		  }
	   }
	}
}
///////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////
void CMapDlg::OnZoneInit() 
{
   CGtMpegWnd *pWnd=(CGtMpegWnd*)theApp.m_pMainWnd;
   pWnd->InitZoneSet();
	
}
///////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////
void CMapDlg::OnReset2() 
{
   CGtMpegWnd *pWnd=(CGtMpegWnd*)theApp.m_pMainWnd;
   pWnd->AlarmReset();
}
///////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////
void CMapDlg::OnHelp() 
{
   CHelpDlg dlg;
   dlg.DoModal();
}
///////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////
void CMapDlg::OnDeviceLst() 
{
   CDeviceLstDlg dlg(this);
   dlg.DoModal();
	   
}

⌨️ 快捷键说明

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