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

📄 memorydemo2.cpp

📁 在WinCE环境下,不同的AP可能需要共享数据,信息,该例子就是几个不同的AP来读写同一块内存的例子.
💻 CPP
字号:
// MemoryDemo2.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "MemoryDemo2.h"
#include "MemoryDemo2Dlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMemoryDemo2App

BEGIN_MESSAGE_MAP(CMemoryDemo2App, CWinApp)
	//{{AFX_MSG_MAP(CMemoryDemo2App)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMemoryDemo2App construction

CMemoryDemo2App::CMemoryDemo2App()
	: CWinApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
	m_bIsOpenGPS = FALSE;
	HANDLE handle = NULL;
	ReadMemoryMap(handle,&m_PARA);

}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMemoryDemo2App object

CMemoryDemo2App theApp;

/////////////////////////////////////////////////////////////////////////////
// CMemoryDemo2App initialization

BOOL CMemoryDemo2App::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.
	m_bIsOpenGPS = OpenGPS();
	CMemoryDemo2Dlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
BOOL CMemoryDemo2App::OpenGPS()
{
	BOOL bReturn = TRUE;
	HANDLE handle = NULL;
	CString strGPSFlag = m_PARA.Para_GPS_USE_FLAG;
	CString strSrcApp		= _T("");
	CString strSrcAppTitle	= _T("");
	HWND    hwndSrcApp  = NULL;
	// no App use GPS port
	if(strGPSFlag != _T("1"))
	{
		WriteMapData();
		bReturn = TRUE;
	}
	else // some APP used GPS port 
	{
		strSrcAppTitle = m_PARA.Para_Src_Title;
		strSrcApp      = m_PARA.Para_Src_APP;
		bReturn = IsRun(strSrcApp);
		if(bReturn)
		{
			wcscpy(m_PARA.Para_Des_APP,_T("MemoryDemo2.exe"));
			wcscpy(m_PARA.Para_Des_APP_PATH,_T("\\"));
			wcscpy(m_PARA.Para_Des_Title,_T("MemoryDemo2"));
			WriteMemoryMap(handle,&m_PARA);
			hwndSrcApp = ::FindWindow(NULL, strSrcAppTitle);
			if(hwndSrcApp != NULL)
			{
				::SendMessage(hwndSrcApp, WMMSG_CLOSE_GPS, 0, 0);
			}
			Sleep(1000);
			ReadMemoryMap(handle,&m_PARA);

			strGPSFlag = m_PARA.Para_GPS_USE_FLAG;
			bReturn = (strGPSFlag == _T("0"));
			if(bReturn)
			{
				WriteMapData();
			}
 		}
	}
	return bReturn;
}

void CMemoryDemo2App::WriteMapData()
{
	HANDLE handle = NULL;
	CString	strTime = _T("");
	CTime CurTime = CTime::GetCurrentTime();
	strTime.Format(_T("%d-%0d-%0d %0d:%0d:%0d"),
					   CurTime.GetYear(),
					   CurTime.GetMonth(),
					   CurTime.GetDay(),
					   CurTime.GetHour(),
					   CurTime.GetMinute(),
					   CurTime.GetSecond());

	wcscpy(m_PARA.Para_GPS_USE_FLAG,_T("1"));
	wcscpy(m_PARA.Para_Src_APP,_T("MemoryDemo2.exe"));
	wcscpy(m_PARA.Para_Src_APP_PATH,_T("\\"));
	wcscpy(m_PARA.Para_Src_Title,_T("MemoryDemo2"));
	wcscpy(m_PARA.Para_GPS_USE_DATETIME,strTime);
	wcscpy(m_PARA.Para_Des_APP,_T("MemoryDemo2.exe"));
	wcscpy(m_PARA.Para_Des_APP_PATH,_T("\\"));
	wcscpy(m_PARA.Para_Des_Title,_T("MemoryDemo2"));
	WriteMemoryMap(handle,&m_PARA);
}

BOOL CMemoryDemo2App::ReleaseGPS()
{
	BOOL bReturn = TRUE;
	HANDLE handle = NULL;
	CString strDesApp		= _T("");
	CString strDesAppTitle	= _T("");
// 	HWND    hwndDesApp  = NULL;
	// no App use GPS port
	strDesAppTitle = m_PARA.Para_Des_Title;
	strDesApp      = m_PARA.Para_Des_APP;
	bReturn = IsRun(strDesApp);
	if(bReturn)
	{
		wcscpy(m_PARA.Para_GPS_USE_FLAG,_T("0"));
		wcscpy(m_PARA.Para_Src_APP,_T(""));
		wcscpy(m_PARA.Para_Src_APP_PATH,_T(""));
		wcscpy(m_PARA.Para_Src_Title,_T(""));

		WriteMemoryMap(handle,&m_PARA);
//		hwndSrcApp = ::FindWindow(NULL, strSrcAppTitle);
//		if(hwndSrcApp != NULL)
//		{
//			::SendMessage(hwndSrcApp, WMMSG_CLOSE_GPS, 0, 0);
//		}
	}
	return bReturn;
}

int CMemoryDemo2App::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	ClearMemory();
	return CWinApp::ExitInstance();
}

⌨️ 快捷键说明

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