\r
BEGIN_MESSAGE_MAP(CXkeymacsApp, CWinApp)\r
//{{AFX_MSG_MAP(CXkeymacsApp)\r
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)\r
// NOTE - the ClassWizard will add and remove mapping macros here.\r
// DO NOT EDIT what you see in these blocks of generated code!\r
//}}AFX_MSG_MAP\r
- // Standard file based document commands\r
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)\r
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)\r
END_MESSAGE_MAP()\r
\r
/////////////////////////////////////////////////////////////////////////////\r
\r
CXkeymacsApp::CXkeymacsApp()\r
{\r
- m_Instance = FirstInstance;\r
+ m_hMutex = NULL;\r
+ m_bIsWow64 = FALSE;\r
}\r
\r
/////////////////////////////////////////////////////////////////////////////\r
// If you are not using these features and wish to reduce the size\r
// of your final executable, you should remove from the following\r
// the specific initialization routines you do not need.\r
-#ifdef _WIN64\r
- m_hMutex = CreateMutex(FALSE, 0, CString(MAKEINTRESOURCE(AFX_IDS_APP_TITLE)) + _T("64"));\r
-#else\r
m_hMutex = CreateMutex(FALSE, 0, CString(MAKEINTRESOURCE(AFX_IDS_APP_TITLE)));\r
-#endif\r
-\r
- if (::GetLastError() == ERROR_ALREADY_EXISTS) {\r
- m_Instance = SecondInstance;\r
- CloseHandle( m_hMutex );\r
- return FALSE;\r
- }\r
-\r
-#ifdef _AFXDLL\r
- Enable3dControls(); // Call this when using MFC in a shared DLL\r
-#else\r
- Enable3dControlsStatic(); // Call this when linking to MFC statically\r
-#endif\r
+ if (GetLastError() == ERROR_ALREADY_EXISTS) {\r
+ CloseHandle(m_hMutex);\r
+ m_hMutex = NULL;\r
+ return FALSE;\r
+ }\r
\r
// Change the registry key under which our settings are stored.\r
SetRegistryKey(IDS_REGISTRY_KEY);\r
SetClassLongPtr(m_pMainWnd->m_hWnd, GCLP_HICON, (LONG_PTR)LoadIcon(IDR_MAINFRAME));\r
\r
// set registry key\r
+ CUtils::InitCUtils();\r
+ if (!Create64bitProcess())\r
+ return FALSE;\r
CProfile::InitDllData();\r
\r
return TRUE;\r
}\r
\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CAboutDlg dialog used for App About\r
-\r
-CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)\r
+BOOL CXkeymacsApp::IsWow64()\r
{\r
- //{{AFX_DATA_INIT(CAboutDlg)\r
- m_szVersionInformation = _T("");\r
- m_szLegalCopyright = _T("");\r
- //}}AFX_DATA_INIT\r
-\r
- m_szLegalCopyright.Format(_T("Copyright (C) 2001-2006")); // rough\r
-\r
- WORD wMajorVersion = 0;\r
- WORD wMinorVersion = 0;\r
- WORD wBuildVersion = 0;\r
- WORD wRevisionVersion = 0;\r
-\r
- TCHAR szFileName[MAX_PATH] = {'\0'};\r
- GetModuleFileName(NULL, szFileName, sizeof(szFileName));\r
- DWORD dwHandle = 0;\r
-\r
- DWORD dwLen = GetFileVersionInfoSize(szFileName, &dwHandle);\r
- if (dwLen) {\r
- LPVOID lpData = new BYTE[dwLen];\r
- if (GetFileVersionInfo(szFileName, dwHandle, dwLen, lpData)) {\r
- VS_FIXEDFILEINFO *pInfo;\r
- UINT uLen;\r
- if (VerQueryValue(lpData, _T("\\"), (LPVOID *)&pInfo, &uLen)) {\r
- wMajorVersion = (WORD)((pInfo->dwProductVersionMS >> 16) & 0xffff);\r
- wMinorVersion = (WORD)((pInfo->dwProductVersionMS ) & 0xffff);\r
- wBuildVersion = (WORD)((pInfo->dwProductVersionLS >> 16) & 0xffff);\r
- wRevisionVersion = (WORD)((pInfo->dwProductVersionLS ) & 0xffff);\r
- }\r
-\r
- Translate_t *lpTranslate = NULL;\r
- UINT cbTranslate = 0;\r
- if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate) && sizeof(Translate_t) <= cbTranslate) {\r
- LPVOID lpLegalCopyright = NULL;\r
- UINT uLen = 0;\r
- CString SubBlock;\r
-\r
- SubBlock.Format(_T("\\StringFileInfo\\%04x%04x\\LegalCopyright"), lpTranslate->wLanguage, lpTranslate->wCodePage);\r
- if (VerQueryValue(lpData, SubBlock.GetBuffer(SubBlock.GetLength()), (LPVOID *)&lpLegalCopyright, &uLen) && uLen) {\r
- m_szLegalCopyright.Format(_T("%s"), lpLegalCopyright);\r
- }\r
- }\r
- }\r
- delete[] lpData;\r
- lpData = NULL;\r
- }\r
-\r
- m_szVersionInformation.Format(_T("%s Version %d.%d"), CString(MAKEINTRESOURCE(AFX_IDS_APP_TITLE)), wMajorVersion, wMinorVersion);\r
-\r
- if (wBuildVersion) {\r
- CString sz;\r
- sz.Format(_T(".%d"), wBuildVersion);\r
- m_szVersionInformation += sz;\r
-\r
- if (wRevisionVersion) {\r
- CString sz;\r
- sz.Format(_T(".%d"), wRevisionVersion);\r
- m_szVersionInformation += sz;\r
- }\r
- }\r
+ return m_bIsWow64;\r
}\r
\r
-void CAboutDlg::DoDataExchange(CDataExchange *pDX)\r
+BOOL CXkeymacsApp::Create64bitProcess()\r
{\r
- CDialog::DoDataExchange(pDX);\r
- //{{AFX_DATA_MAP(CAboutDlg)\r
- DDX_Control(pDX, IDC_URL, m_cURL);\r
- DDX_Text(pDX, IDC_VERSION_INFORMATION, m_szVersionInformation);\r
- DDX_Text(pDX, IDC_LEGAL_COPYRIGHT, m_szLegalCopyright);\r
- //}}AFX_DATA_MAP\r
+ typedef BOOL (WINAPI *PFIsWow64Process)(HANDLE, PBOOL);\r
+ PFIsWow64Process func = (PFIsWow64Process)GetProcAddress(GetModuleHandle(_T("kernel32")), _T("IsWow64Process"));\r
+ if (!func)\r
+ return TRUE; // IsWow64Process not exists\r
+ if (!func(GetCurrentProcess(), &m_bIsWow64))\r
+ return FALSE; // error\r
+ if (!m_bIsWow64)\r
+ return TRUE; // do nothing\r
+ \r
+ TCHAR szFileName[MAX_PATH];\r
+ if (!GetModuleFileName(NULL, szFileName, sizeof(szFileName)))\r
+ return FALSE;\r
+ TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szFile[_MAX_FNAME], szExt[_MAX_EXT];\r
+ if (_tsplitpath_s(szFileName, szDrive, szDir, szFile, szExt) ||\r
+ _tcscat_s(szFile, _T("64")) ||\r
+ _tmakepath_s(szFileName, szDrive, szDir, szFile, szExt))\r
+ return FALSE;\r
+\r
+ STARTUPINFO si;\r
+ ZeroMemory(&si, sizeof(si));\r
+ si.cb = sizeof(si);\r
+ PROCESS_INFORMATION pi;\r
+ ZeroMemory(&pi, sizeof(pi));\r
+ if (!CreateProcess(szFileName, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))\r
+ return FALSE;\r
+ // close unused handles\r
+ CloseHandle(pi.hProcess);\r
+ CloseHandle(pi.hThread);\r
+ return TRUE;\r
}\r
\r
-BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)\r
- //{{AFX_MSG_MAP(CAboutDlg)\r
- ON_WM_CLOSE()\r
- ON_BN_CLICKED(IDC_URL, OnUrl)\r
- ON_WM_CTLCOLOR()\r
- ON_WM_SETCURSOR()\r
- //}}AFX_MSG_MAP\r
-END_MESSAGE_MAP()\r
-\r
-// App command to run the dialog\r
-void CXkeymacsApp::OnAppAbout()\r
+BOOL CXkeymacsApp::SendIPCMessage(DWORD msg)\r
{\r
- CAboutDlg aboutDlg;\r
- aboutDlg.DoModal();\r
+ if (!m_bIsWow64)\r
+ return TRUE;\r
+ DWORD ack, read;\r
+ return CallNamedPipe(IPC_PIPE, &msg, sizeof(msg), &ack, sizeof(DWORD), &read, 10000);\r
}\r
\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CXkeymacsApp message handlers\r
-\r
-\r
int CXkeymacsApp::ExitInstance() \r
{\r
- if (m_Instance == FirstInstance) {\r
- ReleaseMutex( m_hMutex );\r
- CloseHandle( m_hMutex );\r
+ if (m_hMutex) {\r
+ ReleaseMutex(m_hMutex);\r
+ CloseHandle(m_hMutex);\r
\r
m_pMainWnd->DestroyWindow();\r
delete m_pMainWnd;\r
\r
return CWinApp::ExitInstance();\r
}\r
-\r
-void CAboutDlg::OnOK() \r
-{\r
- CDialog::OnOK();\r
-}\r
-\r
-\r
-void CAboutDlg::OnClose() \r
-{\r
- CDialog::OnClose();\r
-}\r
-\r
-void CAboutDlg::OnUrl() \r
-{\r
- CString szURL;\r
- m_cURL.GetWindowText(szURL);\r
-\r
- ShellExecute(m_hWnd, NULL, szURL, NULL, NULL, SW_SHOWNORMAL);\r
-}\r
-\r
-HBRUSH CAboutDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor) \r
-{\r
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);\r
-\r
- COLORREF crBlue = RGB(0, 0, 0xff);\r
-\r
- if (pWnd == &m_cURL) {\r
- pDC->SetTextColor(crBlue);\r
- }\r
-\r
- return hbr;\r
-}\r
-\r
-BOOL CAboutDlg::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message) \r
-{\r
- CRect rect;\r
- m_cURL.GetWindowRect(rect);\r
-\r
- POINT p;\r
- ::GetCursorPos(&p);\r
-\r
- if (rect.PtInRect(p)) {\r
- HCURSOR hCursor = (HCURSOR)LoadImage(theApp.m_hInstance, MAKEINTRESOURCE(IDC_HAND_CURSOR),\r
- IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
- SetCursor(hCursor);\r
- return TRUE; \r
- }\r
-\r
- return CDialog::OnSetCursor(pWnd, nHitTest, message);\r
-}\r