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

📄 mapdlg.cpp

📁 控制GSM模块获得当前数据库并进行定位
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MapDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Map.h"
#include "MapDlg.h"
#include "fstream.h"
#include "iostream.h"
#include "webbrowser2.h"
#include "Add_CELLID.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMapDlg dialog

CMapDlg::CMapDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMapDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMapDlg)
	m_autorefresh = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_rec_length=0;
	m_ReceiveData=_T("");
	m_mode=_T("");
	m_time=_T("");
	m_autorefresh=5;
}

void CMapDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMapDlg)
	DDX_Control(pDX, IDC_COMBO1, m_Comm);
	DDX_Control(pDX, IDC_LIST2, m_List);
	DDX_Control(pDX, IDC_MSCOMM1, m_MSComm);
	DDX_Text(pDX, IDC_AUTOREFRESH, m_autorefresh);
	DDV_MinMaxInt(pDX, m_autorefresh, 5, 1000);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMapDlg, CDialog)
	//{{AFX_MSG_MAP(CMapDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CELLID, OnCellid)
	ON_BN_CLICKED(IDC_CELLINFO, OnCellinfo)
	ON_BN_CLICKED(IDC_ADDCELL, OnAddcell)
	ON_BN_CLICKED(IDC_OPENCOM, OnOpencom)
	ON_BN_CLICKED(IDC_MANU, OnManu)
	ON_BN_CLICKED(IDC_AUTO, OnAuto)
	ON_WM_TIMER()
	ON_EN_CHANGE(IDC_AUTOREFRESH, OnChangeAutorefresh)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMapDlg message handlers

BOOL CMapDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	//ShowWindow(SW_SHOWMAXIMIZED);

	if(m_MSComm.GetPortOpen()) //如果串口是打开的,则行关闭串口
	{
		m_MSComm.SetPortOpen(FALSE);
	}

	CString   strSerialList[256];  // 临时定义 256 个字符串组,因为系统最多也就 256 个 
	HKEY hKey; 
	LPCTSTR data_Set="HARDWARE\\DEVICEMAP\\SERIALCOMM\\"; 
	long ret0 = (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, data_Set, 0, KEY_READ, &hKey)); 
	if(ret0 != ERROR_SUCCESS) 
	{
		AfxMessageBox("System error!");
		GetDlgItem(IDC_OPENCOM)->EnableWindow(FALSE);
		GetDlgItem(IDC_COMBO1)->EnableWindow(FALSE);
	}
	else
	{
		int i = 0; 
		CHAR Name[25]; 
		UCHAR szPortName[25]; 
		LONG Status; 
		DWORD dwIndex = 0; 
		DWORD dwName; 
		DWORD dwSizeofPortName; 
		DWORD Type; 
		dwName = sizeof(Name); 
		dwSizeofPortName = sizeof(szPortName); 
		do 
		{ 
			Status = RegEnumValue(hKey, dwIndex++, Name, &dwName, NULL, &Type, 
				  szPortName, &dwSizeofPortName); 

			if((Status == ERROR_SUCCESS)||(Status == ERROR_MORE_DATA)) 
			{ 
				strSerialList[i] = CString(szPortName);       // 串口字符串保存 
				i++;// 串口计数 
			} 
		} while((Status == ERROR_SUCCESS)||(Status == ERROR_MORE_DATA)); 
		RegCloseKey(hKey);

		for(int j=0;j<i;j++)
			m_Comm.AddString(strSerialList[j]);
	}

	m_List.InsertColumn(0,"基站序号", LVCFMT_LEFT,60,-1);
	m_List.InsertColumn(1,"chann",LVCFMT_LEFT,60,-1);
	m_List.InsertColumn(2,"场强信息", LVCFMT_LEFT,60,-1);
	m_List.InsertColumn(3,"LAC号", LVCFMT_LEFT,60,-1);
	m_List.InsertColumn(4,"CELL ID", LVCFMT_LEFT,60,-1);
	m_List.InsertColumn(5,"经度", LVCFMT_LEFT,80,-1);
	m_List.InsertColumn(6,"纬度", LVCFMT_LEFT,80,-1);
	m_List.InsertColumn(7,"具体地点", LVCFMT_LEFT,300,-1);
	m_row_number=0;

	CWebBrowser2 * pBrowse = (CWebBrowser2 *) GetDlgItem(IDC_EXPLORER1);
	COleVariant sLoc("http://map.baidu.com/");
	pBrowse->Navigate2(sLoc, NULL, NULL, NULL, NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMapDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMapDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMapDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMapDlg::InitalTC35i()
{
	m_SendData=_T("AT&F\r");
	Send_com();
	Sleep(500);
	CString str=GetCommstr();
	if(str!="AT&F\r\r\nOK\r\n")
	{
		AfxMessageBox("TC35i communication error!");
		m_OK=0;
		return;
	}
	m_SendData=_T("AT&D0\r");
	Send_com();
	Sleep(500);
	str=GetCommstr();
	if(str!="AT&D0\r\r\nOK\r\n")
	{
		AfxMessageBox("TC35i communication error!");
		m_OK=0;
		return;
	}
	m_SendData=_T("ATS0=1\r");
	Send_com();
	Sleep(500);
	str=GetCommstr();
	if(str!="ATS0=1\r\r\nOK\r\n")
	{
		AfxMessageBox("TC35i communication error!");
		m_OK=0;
		return;
	}
	m_SendData=_T("AT+IPR=9600\r");
	Send_com();
	Sleep(500);
	str=GetCommstr();
	if(str!="AT+IPR=9600\r\r\nOK\r\n")
	{
		AfxMessageBox("TC35i communication error!");
		m_OK=0;
		return;
	}
	m_SendData=_T("AT&W0\r");
	Send_com();
	Sleep(500);
	str=GetCommstr();
	if(str!="AT&W0\r\r\nOK\r\n")
	{
		AfxMessageBox("TC35i communication error!");
		m_OK=0;
		return;
	}
	m_SendData=_T("ATZ0\r");
	Send_com();
	Sleep(500);
	str=GetCommstr();
	if(str!="ATZ0\r\r\nOK\r\n")
	{
		AfxMessageBox("TC35i communication error!");
		m_OK=0;
		return;
	}
	GetDlgItem(IDC_CELLID)->EnableWindow(TRUE);
	GetDlgItem(IDC_CELLINFO)->EnableWindow(TRUE);
	m_SendData=_T("AT+CSQ\r");
	Send_com();
	Sleep(500);
	str=GetCommstr();
	char temp[100];
	strcpy(temp,(char*)LPCSTR(str));
	char tmp[3];
	tmp[0]=temp[14];
	tmp[1]=temp[15];
	tmp[2]=temp[16];
	tmp[3]='0';
	int db=int(atoi(tmp));
	if(db<14)
	{
		AfxMessageBox("信号小于14!\n请检查天线!");
	}
	GetDlgItem(IDC_AUTO)->EnableWindow(TRUE);
	GetDlgItem(IDC_MANU)->EnableWindow(TRUE);
	GetDlgItem(IDC_STATIC)->EnableWindow(TRUE);
	GetDlgItem(IDC_STATICRE)->EnableWindow(TRUE);
	GetDlgItem(IDC_STATICMI)->EnableWindow(TRUE);
	GetDlgItem(IDC_AUTOREFRESH)->EnableWindow(TRUE);

	((CButton *)GetDlgItem(IDC_MANU))->SetCheck(TRUE);
	((CButton *)GetDlgItem(IDC_AUTO))->SetCheck(FALSE);
}

BEGIN_EVENTSINK_MAP(CMapDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CMapDlg)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

/*void CMapDlg::OnOnCommMscomm1() 
{
	// TODO: Add your control notification handler code here
//	Sleep(500);   //视各厂家modem而定。不加则数据接受不全 
	VARIANT m_input; 
	char *str,*str1; 
	int k,nEvent,i; 
	CString str2; 
	m_ReceiveData=""; 
	nEvent=m_MSComm.GetCommEvent(); 
	switch(nEvent) 
	{ 
		case 2:                              	//收到大于RTHresshold个字符 
				k=m_MSComm.GetInBufferCount();     	//接收缓冲区的字符数目 
				if(k>0) 
				{ 
					m_input=m_MSComm.GetInput(); 
					str=(char*)(unsigned char*)m_input.parray->pvData; 
				} 
				i=0; 
				str1=str; 
				while(i<k) 
				{ 
					i++; 
					str1++; 
				} 
				*str1='\0';                               
				str2=(const char*)str;             	//清除字符串中的不必要字符 
				m_ReceiveData=(const char *)str; 
				m_rec_length=m_ReceiveData.GetLength();
			break; 
		case 3:       				//CTS线状态发生变化 
			break; 
		case 4:       				//DSR线状态发生变化 
			break; 
		case 5:       				//CD线状态发生变化 
			break; 
		case 6:       				//Ring Indicator发生变化 
			break; 
	} 
	Judge_Status();
}*/

void CMapDlg::Send_com()
{
	int count=m_SendData.GetLength();
	CByteArray m_Array;

	m_Array.RemoveAll();
	m_Array.SetSize(count);

⌨️ 快捷键说明

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