444 lines
8.3 KiB
C++
Executable File
444 lines
8.3 KiB
C++
Executable File
// GPSMain.cpp : Defines the class behaviors for the application.
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "GPSMain.h"
|
||
#include "GPSMainDlg.h"
|
||
|
||
#ifdef _DEBUG
|
||
#define new DEBUG_NEW
|
||
#undef THIS_FILE
|
||
static char THIS_FILE[] = __FILE__;
|
||
#endif
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CGPSMainApp
|
||
|
||
BEGIN_MESSAGE_MAP(CGPSMainApp, CWinApp)
|
||
//{{AFX_MSG_MAP(CGPSMainApp)
|
||
// 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()
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CGPSMainApp construction
|
||
|
||
CGPSMainApp::CGPSMainApp()
|
||
: CWinApp()
|
||
{
|
||
// TODO: add construction code here,
|
||
// Place all significant initialization in InitInstance
|
||
m_Language = GetRegLanguage();//LANG_CHINESE;
|
||
m_IsBeep = GetRegBeep();
|
||
}
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// The one and only CGPSMainApp object
|
||
|
||
CGPSMainApp theApp;
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CGPSMainApp initialization
|
||
|
||
BOOL CGPSMainApp::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.
|
||
|
||
CGPSMainDlg 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;
|
||
}
|
||
|
||
int CGPSMainApp::ExitInstance()
|
||
{
|
||
// TODO: Add your specialized code here and/or call the base class
|
||
|
||
if(m_ResourceLib)
|
||
{
|
||
FreeLibrary(m_ResourceLib);
|
||
}
|
||
|
||
return CWinApp::ExitInstance();
|
||
}
|
||
|
||
int CGPSMainApp::GetLanguage()
|
||
{
|
||
return m_Language;
|
||
}
|
||
|
||
void CGPSMainApp::SetLanguage(int iLanguage)
|
||
{
|
||
m_Language = iLanguage;
|
||
SetRegLanguage(m_Language);
|
||
}
|
||
|
||
void CGPSMainApp::SetBeep(bool bBeep)
|
||
{
|
||
m_IsBeep = bBeep;
|
||
SetRegBeep(m_IsBeep);
|
||
}
|
||
|
||
bool CGPSMainApp::GetBeep()
|
||
{
|
||
return m_IsBeep;
|
||
}
|
||
|
||
void CGPSMainApp::PlayMsgSound(int iSound)
|
||
{
|
||
// <20><><EFBFBD><EFBFBD>wav<61>ļ<EFBFBD>
|
||
if (iSound == -1)
|
||
{
|
||
//PlaySound(L"default.wav",NULL,SND_FILENAME);
|
||
//MessageBeep(MB_OK);
|
||
}
|
||
else
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դwav
|
||
//PlaySound(MAKEINTRESOURCE(iSound),AfxGetResourceHandle(),SND_RESOURCE);
|
||
//MessageBeep(MB_ICONEXCLAMATION);
|
||
}
|
||
}
|
||
|
||
HINSTANCE CGPSMainApp::GetResourceLib()
|
||
{
|
||
return m_ResourceLib;
|
||
}
|
||
|
||
HINSTANCE CGPSMainApp::LoadLanguageRes(int iLanguage)
|
||
{
|
||
if (m_ResourceLib)
|
||
{
|
||
FreeLibrary(m_ResourceLib);
|
||
}
|
||
|
||
if (iLanguage == LANG_ENGLISH)
|
||
{
|
||
m_ResourceLib = LoadLibrary(L"LanguageENU.dll");
|
||
}
|
||
else if(iLanguage == LANG_CHINESE)
|
||
{
|
||
m_ResourceLib = LoadLibrary(L"LanguageCHS.dll");
|
||
}
|
||
|
||
return m_ResourceLib;
|
||
}
|
||
|
||
bool RunApplication(CString sFileName, CString sParam)
|
||
{
|
||
CFileStatus fStatus;
|
||
// <20>ж<EFBFBD><D0B6>ļ<EFBFBD><C4BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||
if(CFile::GetStatus(sFileName,fStatus))
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||
PROCESS_INFORMATION pl;
|
||
|
||
BOOL hResult;
|
||
|
||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>½<EFBFBD><C2BD><EFBFBD>
|
||
if(sParam.IsEmpty())
|
||
{
|
||
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
hResult = CreateProcess(sFileName,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&pl);
|
||
}
|
||
else
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
hResult = CreateProcess(sFileName,sParam,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&pl);
|
||
}
|
||
// <20>жϽ<D0B6><CFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
||
if(!hResult)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// <20>ȴ<EFBFBD><C8B4>½<EFBFBD><C2BD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD>̽<EFBFBD><CCBD><EFBFBD>
|
||
DWORD rc = WaitForSingleObject(pl.hProcess,INFINITE);
|
||
|
||
// <20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
bool CGPSMainApp::GetRegBeep()
|
||
{
|
||
HKEY hKey;
|
||
DWORD hResult,hType;
|
||
|
||
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
|
||
_T("SOFTWARE\\PDA")
|
||
,0,0,0,0,0,&hKey,&hType);
|
||
|
||
if (hResult == ERROR_SUCCESS)
|
||
{
|
||
// <20><><EFBFBD>ݴ<EFBFBD>С
|
||
DWORD dwSize = 4;
|
||
DWORD dwType = REG_DWORD;
|
||
|
||
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD>Ǵü<F2BFAAB8>
|
||
if (hType == REG_CREATED_NEW_KEY)
|
||
{
|
||
// Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
int lpData = 0;
|
||
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegSetValueEx(hKey,L"Beep",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
|
||
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
// <20><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
BYTE lpData;
|
||
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||
hResult = RegQueryValueEx(hKey,L"Beep",NULL,&dwType,(BYTE*)&lpData,&dwSize);
|
||
|
||
// <20>ж϶<D0B6>ȡ<EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||
if (hResult == ERROR_SUCCESS)
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
if (lpData == 0)
|
||
{
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
else if (hResult == ERROR_FILE_NOT_FOUND)
|
||
{
|
||
// Ĭ<>Ͻ<EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
int lpData = 0;
|
||
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegSetValueEx(hKey,L"Beep",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
|
||
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
// <20><>ȡʧ<C8A1>ܷ<EFBFBD><DCB7><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
||
return false;
|
||
}
|
||
}
|
||
|
||
int CGPSMainApp::GetRegLanguage()
|
||
{
|
||
HKEY hKey;
|
||
DWORD hResult,hType;
|
||
|
||
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
|
||
_T("SOFTWARE\\PDA")
|
||
,0,0,0,0,0,&hKey,&hType);
|
||
|
||
if (hResult == ERROR_SUCCESS)
|
||
{
|
||
// <20><><EFBFBD>ݴ<EFBFBD>С
|
||
DWORD dwSize = 4;
|
||
DWORD dwType = REG_DWORD;
|
||
|
||
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD>Ǵü<F2BFAAB8>
|
||
if (hType == REG_CREATED_NEW_KEY)
|
||
{
|
||
// Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
int lpData = LANG_CHINESE;
|
||
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegSetValueEx(hKey,L"DefaultLanguage",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
|
||
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return lpData;
|
||
}
|
||
else
|
||
{
|
||
// <20><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
BYTE lpData;
|
||
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||
hResult = RegQueryValueEx(hKey,L"DefaultLanguage",NULL,&dwType,(BYTE*)&lpData,&dwSize);
|
||
|
||
// <20>ж϶<D0B6>ȡ<EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||
if (hResult == ERROR_SUCCESS)
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
return lpData;
|
||
}
|
||
else if (hResult == ERROR_FILE_NOT_FOUND)
|
||
{
|
||
// Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
int lpData = LANG_CHINESE;
|
||
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegSetValueEx(hKey,L"DefaultLanguage",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
|
||
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
return lpData;
|
||
}
|
||
else
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><>ȡʧ<C8A1>ܷ<EFBFBD><DCB7><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
||
return LANG_CHINESE;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
|
||
return LANG_CHINESE;
|
||
}
|
||
}
|
||
|
||
bool CGPSMainApp::SetRegBeep(bool bBeep)
|
||
{
|
||
int lpData;
|
||
|
||
if (bBeep)
|
||
{
|
||
lpData = 1;
|
||
}
|
||
else
|
||
{
|
||
lpData = 0;
|
||
}
|
||
|
||
HKEY hKey;
|
||
DWORD hResult,hType;
|
||
|
||
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
|
||
_T("SOFTWARE\\PDA")
|
||
,0,0,0,0,0,&hKey,&hType);
|
||
|
||
if (hResult == ERROR_SUCCESS)
|
||
{
|
||
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegSetValueEx(hKey,L"Beep",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
|
||
|
||
// <20>ж϶<D0B6>ȡ<EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||
if (hResult == ERROR_SUCCESS)
|
||
{
|
||
m_IsBeep = bBeep;
|
||
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><>ȡʧ<C8A1>ܷ<EFBFBD><DCB7><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
|
||
return false;
|
||
}
|
||
}
|
||
|
||
bool CGPSMainApp::SetRegLanguage(int iLanguage)
|
||
{
|
||
int lpData = iLanguage;
|
||
|
||
HKEY hKey;
|
||
DWORD hResult,hType;
|
||
|
||
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
|
||
_T("SOFTWARE\\PDA")
|
||
,0,0,0,0,0,&hKey,&hType);
|
||
|
||
if (hResult == ERROR_SUCCESS)
|
||
{
|
||
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||
hResult = RegSetValueEx(hKey,L"DefaultLanguage",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
|
||
|
||
// <20>ж϶<D0B6>ȡ<EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||
if (hResult == ERROR_SUCCESS)
|
||
{
|
||
m_Language = iLanguage;
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><>ȡʧ<C8A1>ܷ<EFBFBD><DCB7><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// <20>ر<EFBFBD>
|
||
RegCloseKey(hKey);
|
||
|
||
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
|
||
return false;
|
||
}
|
||
}
|