📄 memorydemo2dlg.cpp
字号:
// MemoryDemo2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "MemoryDemo2.h"
#include "MemoryDemo2Dlg.h"
#include "TestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMemoryDemo2Dlg dialog
//-------------------------------------------------------
//[Method] GetLanguageIDfromReg
//[Desp ] get the MioMap language setting from Registry.
//[Return] int : 0,non Big5; 1.Big5. -1,Invalid;
//[Create] 2006-7-19 Xiangjun Han
//[Modify]
//[Remark]
//-------------------------------------------------------
int GetLanguageIDfromReg()
{
HKEY _hkey ;
DWORD dwType ;
DWORD dwSize ;
DWORD dwLanguageID = -1;
if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_CURRENT_USER,
TEXT("MioMap\\Language"),
0,0,&_hkey))
{
return dwLanguageID;
}
else
{
dwType = 0;
dwSize = sizeof(DWORD);
if (ERROR_SUCCESS==RegQueryValueEx( _hkey, // subkey handle
TEXT("LANGUAGEID"), // value name
0, // must be zero
&dwType, // value type
(LPBYTE)&dwLanguageID, // pointer to value data
&dwSize)) // length of value data
{
}
RegCloseKey(_hkey);
}
return dwLanguageID;
}
//-------------------------------------------------------
//[Method] WriteLanguageIDtoReg
//[Desp ] Write the Miomap language setting info to registry.
//[Param ] int nLanguageID : -1,invalid. 0,non_BIG5;1,BIG5;
//[Return] BOOL :
//[Create] 2006-7-19 Xiangjun Han
//[Modify]
//[Remark]
//-------------------------------------------------------
BOOL WriteLanguageIDtoReg(int nLanguageID)
{
DWORD dw;
BOOL bReturn = TRUE;
HKEY _hkey ;
DWORD dwSize ;
if(ERROR_SUCCESS != RegCreateKeyEx(
HKEY_CURRENT_USER,
TEXT("MioMap\\Language"),
0,
REG_NONE,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL,
&_hkey,
&dw))
{
return FALSE;
}
else
{
dwSize = sizeof(DWORD);
if(ERROR_SUCCESS == RegSetValueEx(_hkey,
TEXT("LANGUAGEID"),
NULL,
REG_DWORD,
(byte*)&nLanguageID,
dwSize))
{
bReturn = TRUE;
}
else
{
bReturn = FALSE;
}
RegCloseKey(_hkey);
}
return bReturn;
}
CMemoryDemo2Dlg::CMemoryDemo2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMemoryDemo2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMemoryDemo2Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMemoryDemo2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMemoryDemo2Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMemoryDemo2Dlg, CDialog)
//{{AFX_MSG_MAP(CMemoryDemo2Dlg)
ON_WM_KILLFOCUS()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
ON_MESSAGE (WMMSG_CLOSE_GPS, OnReleaseGPS)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMemoryDemo2Dlg message handlers
BOOL CMemoryDemo2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
CMemoryDemo2App* ptheApp = (CMemoryDemo2App*) AfxGetApp();
if(ptheApp->m_bIsOpenGPS)
{
GetDlgItem(IDC_LABEL)->SetWindowText(_T("GPS is Opened by MemoryDemo2"));
}
else
{
GetDlgItem(IDC_LABEL)->SetWindowText(_T("MemoryDemo2: Failed to open GPS."));
}
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
HRESULT CMemoryDemo2Dlg::OnReleaseGPS(WPARAM wParam, LPARAM lParam)
{
CMemoryDemo2App* ptheApp = (CMemoryDemo2App*)AfxGetApp();
if(ptheApp->ReleaseGPS())
{
GetDlgItem(IDC_LABEL)->SetWindowText(_T("Got it, GPS has been released by MemoryDemo2"));
}
else
{
GetDlgItem(IDC_LABEL)->SetWindowText(_T("Got it, MemoryDemo2:failed to release GPS"));
}
return S_OK;
}
void CMemoryDemo2Dlg::OnKillFocus(CWnd* pNewWnd)
{
CDialog::OnKillFocus(pNewWnd);
CWnd* pwnd = GetForegroundWindow();
if(pwnd->m_hWnd != this->m_hWnd)
{
AfxMessageBox(L"hello");
}
// TODO: Add your message handler code here
}
void CMemoryDemo2Dlg::OnButton1()
{
// HKEY _hkey ;
// DWORD dwType ;
// DWORD dwSize ;
// DWORD isActive = 0;
//
// if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_CURRENT_USER,
// TEXT("MioMap\\Language"),
// 0,0,&_hkey))
// {
// return;
// }
// else
// {
//
// dwType = 0;
// dwSize = sizeof(DWORD);
// if (ERROR_SUCCESS==RegQueryValueEx( _hkey, // subkey handle
// TEXT("LANGUAGE"), // value name
// 0, // must be zero
// &dwType, // value type
// (LPBYTE)&isActive, // pointer to value data
// &dwSize)) // length of value data
// {
// CString strMessage;
// strMessage.Format(_T("%d"),isActive);
// AfxMessageBox(strMessage);
// }
//
// RegCloseKey(_hkey);
//
// }
// CString strMessage;
// strMessage.Format(_T("%d"),GetLanguageIDfromReg());
// AfxMessageBox(strMessage);
HWND hWnd = ::FindWindow(NULL, L"MemoryDemo");
if(hWnd != NULL)
{
::PostMessage(hWnd,WM_CLOSE,0,0);
}
else
{
CreateProcess(L"\\MemoryDemo.exe",NULL, NULL, NULL,
/*FALSE*/0, 0, NULL, NULL, NULL, NULL);
SetForegroundWindow();
}
}
void CMemoryDemo2Dlg::OnButton2()
{
// DWORD dw;
//
// HKEY _hkey ;
// DWORD dwSize ;
// DWORD isActive = 0;
//
// if(ERROR_SUCCESS != RegCreateKeyEx(
// HKEY_CURRENT_USER,
// TEXT("MioMap\\Language"),
// 0,
// REG_NONE,
// REG_OPTION_NON_VOLATILE,
// KEY_ALL_ACCESS, NULL,
// &_hkey,
// &dw))
// {
// AfxMessageBox(_T("NG"));
// }
// else
// {
// isActive = 8;
// dwSize = sizeof(DWORD);
// if(ERROR_SUCCESS == RegSetValueEx(_hkey,
// TEXT("LANGUAGE"),
// NULL,
// REG_DWORD,
// (byte*)&isActive,
// dwSize))
// {
// AfxMessageBox(_T("OK!"));
// }
// else
// {
// AfxMessageBox(_T("NG!"));
// }
//
// RegCloseKey(_hkey);
// }
WriteLanguageIDtoReg(208);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -