📄 memorydemo.cpp
字号:
// MemoryDemo.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "MemoryDemo.h"
#include "MemoryDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMemoryDemoApp
BEGIN_MESSAGE_MAP(CMemoryDemoApp, CWinApp)
//{{AFX_MSG_MAP(CMemoryDemoApp)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CMemoryDemoApp construction
CMemoryDemoApp::CMemoryDemoApp()
: CWinApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
HANDLE handle = NULL;
ReadMemoryMap(handle,&m_PARA);
m_bIsOpenGPS = FALSE;
// ClearMemory();
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMemoryDemoApp object
CMemoryDemoApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMemoryDemoApp initialization
BOOL CMemoryDemoApp::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();
CMemoryDemoDlg 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 CMemoryDemoApp::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)
{
wcscmp(m_PARA.Para_Des_APP,_T("MemoryDemo.exe"));
wcscpy(m_PARA.Para_Des_APP_PATH,_T("\\"));
wcscpy(m_PARA.Para_Des_Title,_T("MemoryDemo"));
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 CMemoryDemoApp::WriteMapData()
{
HANDLE handle = NULL;
CString strTime = _T("");
CTime CurTime = CTime::GetCurrentTime();
strTime.Format(_T("%d-%02d-%02d %0d:%02d:%02d"),
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("MemoryDemo.exe"));
wcscpy(m_PARA.Para_Src_APP_PATH,_T("\\"));
wcscpy(m_PARA.Para_Src_Title,_T("MemoryDemo"));
wcscpy(m_PARA.Para_GPS_USE_DATETIME,strTime);
wcscpy(m_PARA.Para_Des_APP,_T("MemoryDemo.exe"));
wcscpy(m_PARA.Para_Des_APP_PATH,_T("\\"));
wcscpy(m_PARA.Para_Des_Title,_T("MemoryDemo"));
WriteMemoryMap(handle,&m_PARA);
}
BOOL CMemoryDemoApp::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"));
wcscmp(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 CMemoryDemoApp::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 + -