OSDN Git Service

Remove typedef of Translate_t and the declaration of struct
[xkeymacs/xkeymacs.git] / xkeymacs / xkeymacs.cpp
1 // xkeymacs.cpp : Defines the class behaviors for the application.\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "xkeymacs.h"\r
6 #include "Profile.h"\r
7 #include "MainFrm.h"\r
8 \r
9 #ifdef _DEBUG\r
10 #define new DEBUG_NEW\r
11 #undef THIS_FILE\r
12 static char THIS_FILE[] = __FILE__;\r
13 #endif\r
14 \r
15 /////////////////////////////////////////////////////////////////////////////\r
16 // CXkeymacsApp\r
17 \r
18 BEGIN_MESSAGE_MAP(CXkeymacsApp, CWinApp)\r
19         //{{AFX_MSG_MAP(CXkeymacsApp)\r
20                 // NOTE - the ClassWizard will add and remove mapping macros here.\r
21                 //    DO NOT EDIT what you see in these blocks of generated code!\r
22         //}}AFX_MSG_MAP\r
23 END_MESSAGE_MAP()\r
24 \r
25 /////////////////////////////////////////////////////////////////////////////\r
26 // CXkeymacsApp construction\r
27 \r
28 CXkeymacsApp::CXkeymacsApp()\r
29 {\r
30         m_hMutex = NULL;\r
31 }\r
32 \r
33 /////////////////////////////////////////////////////////////////////////////\r
34 // The one and only CXkeymacsApp object\r
35 \r
36 CXkeymacsApp theApp;\r
37 \r
38 /////////////////////////////////////////////////////////////////////////////\r
39 // CXkeymacsApp initialization\r
40 \r
41 BOOL CXkeymacsApp::InitInstance()\r
42 {\r
43 //      AfxEnableControlContainer();\r
44 \r
45         // Standard initialization\r
46         // If you are not using these features and wish to reduce the size\r
47         //  of your final executable, you should remove from the following\r
48         //  the specific initialization routines you do not need.\r
49 #ifdef _WIN64\r
50         m_hMutex = CreateMutex(FALSE, 0, CString(MAKEINTRESOURCE(AFX_IDS_APP_TITLE)) + _T("64"));\r
51 #else\r
52         m_hMutex = CreateMutex(FALSE, 0, CString(MAKEINTRESOURCE(AFX_IDS_APP_TITLE)));\r
53 #endif\r
54     if (GetLastError() == ERROR_ALREADY_EXISTS) {\r
55         CloseHandle(m_hMutex);\r
56                 m_hMutex = NULL;\r
57         return FALSE;\r
58     }\r
59 \r
60 #ifdef _AFXDLL\r
61         Enable3dControls();                     // Call this when using MFC in a shared DLL\r
62 #else\r
63         Enable3dControlsStatic();       // Call this when linking to MFC statically\r
64 #endif\r
65 \r
66         // Change the registry key under which our settings are stored.\r
67         SetRegistryKey(IDS_REGISTRY_KEY);\r
68 //\r
69 //      LoadStdProfileSettings();  // Load standard INI file options (including MRU)\r
70 \r
71         // Parse command line for standard shell commands, DDE, file open\r
72 //      CCommandLineInfo cmdInfo;\r
73 //      ParseCommandLine(cmdInfo);\r
74 \r
75         // Dispatch commands specified on the command line\r
76 //      if (!ProcessShellCommand(cmdInfo))\r
77 //              return FALSE;\r
78 \r
79         // The one and only window has been initialized, so show and update it.\r
80         m_pMainWnd = new CMainFrame;\r
81         m_pMainWnd->ShowWindow(SW_HIDE);\r
82         m_pMainWnd->UpdateWindow();\r
83         SetClassLongPtr(m_pMainWnd->m_hWnd, GCLP_HICON, (LONG_PTR)LoadIcon(IDR_MAINFRAME));\r
84 \r
85         // set registry key\r
86         CProfile::InitDllData();\r
87         CUtils::InitCUtils();\r
88 \r
89         return TRUE;\r
90 }\r
91 \r
92 \r
93 /////////////////////////////////////////////////////////////////////////////\r
94 // CAboutDlg dialog used for App About\r
95 \r
96 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)\r
97 {\r
98         //{{AFX_DATA_INIT(CAboutDlg)\r
99         m_szVersionInformation = _T("");\r
100         m_szLegalCopyright = _T("");\r
101         //}}AFX_DATA_INIT\r
102 \r
103         m_szLegalCopyright.Format(_T("Copyright (C) 2001-2006"));       // rough\r
104 \r
105         WORD wMajorVersion              = 0;\r
106         WORD wMinorVersion              = 0;\r
107         WORD wBuildVersion              = 0;\r
108         WORD wRevisionVersion   = 0;\r
109 \r
110         TCHAR szFileName[MAX_PATH] = {'\0'};\r
111         GetModuleFileName(NULL, szFileName, sizeof(szFileName));\r
112         DWORD dwHandle = 0;\r
113 \r
114         DWORD dwLen = GetFileVersionInfoSize(szFileName, &dwHandle);\r
115         if (dwLen) {\r
116                 LPVOID lpData = new BYTE[dwLen];\r
117                 if (GetFileVersionInfo(szFileName, dwHandle, dwLen, lpData)) {\r
118                         VS_FIXEDFILEINFO *pInfo;\r
119                         UINT uLen;\r
120                         if (VerQueryValue(lpData, _T("\\"), (LPVOID *)&pInfo, &uLen)) {\r
121                                 wMajorVersion           = (WORD)((pInfo->dwProductVersionMS >> 16) & 0xffff);\r
122                                 wMinorVersion           = (WORD)((pInfo->dwProductVersionMS      ) & 0xffff);\r
123                                 wBuildVersion           = (WORD)((pInfo->dwProductVersionLS >> 16) & 0xffff);\r
124                                 wRevisionVersion        = (WORD)((pInfo->dwProductVersionLS      ) & 0xffff);\r
125                         }\r
126 \r
127                         struct Translate {\r
128                                 WORD wLanguage;\r
129                                 WORD wCodePage;\r
130                         } *lpTranslate = NULL;\r
131                         UINT cbTranslate = 0;\r
132                         if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate) && sizeof(Translate) <= cbTranslate) {\r
133                                 LPVOID lpLegalCopyright = NULL;\r
134                                 UINT uLen = 0;\r
135                                 CString SubBlock;\r
136 \r
137                                 SubBlock.Format(_T("\\StringFileInfo\\%04x%04x\\LegalCopyright"), lpTranslate->wLanguage, lpTranslate->wCodePage);\r
138                                 if (VerQueryValue(lpData, SubBlock.GetBuffer(SubBlock.GetLength()), (LPVOID *)&lpLegalCopyright, &uLen) && uLen) {\r
139                                         m_szLegalCopyright.Format(_T("%s"), lpLegalCopyright);\r
140                                 }\r
141                         }\r
142                 }\r
143                 delete[] lpData;\r
144                 lpData = NULL;\r
145         }\r
146 \r
147         m_szVersionInformation.Format(_T("%s Version %d.%d"), CString(MAKEINTRESOURCE(AFX_IDS_APP_TITLE)), wMajorVersion, wMinorVersion);\r
148 \r
149         if (wBuildVersion) {\r
150                 CString sz;\r
151                 sz.Format(_T(".%d"), wBuildVersion);\r
152                 m_szVersionInformation += sz;\r
153 \r
154                 if (wRevisionVersion) {\r
155                         CString sz;\r
156                         sz.Format(_T(".%d"), wRevisionVersion);\r
157                         m_szVersionInformation += sz;\r
158                 }\r
159         }\r
160 }\r
161 \r
162 void CAboutDlg::DoDataExchange(CDataExchange *pDX)\r
163 {\r
164         CDialog::DoDataExchange(pDX);\r
165         //{{AFX_DATA_MAP(CAboutDlg)\r
166         DDX_Control(pDX, IDC_URL, m_cURL);\r
167         DDX_Text(pDX, IDC_VERSION_INFORMATION, m_szVersionInformation);\r
168         DDX_Text(pDX, IDC_LEGAL_COPYRIGHT, m_szLegalCopyright);\r
169         //}}AFX_DATA_MAP\r
170 }\r
171 \r
172 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)\r
173         //{{AFX_MSG_MAP(CAboutDlg)\r
174         ON_WM_CLOSE()\r
175         ON_BN_CLICKED(IDC_URL, OnUrl)\r
176         ON_WM_CTLCOLOR()\r
177         ON_WM_SETCURSOR()\r
178         //}}AFX_MSG_MAP\r
179 END_MESSAGE_MAP()\r
180 \r
181 /////////////////////////////////////////////////////////////////////////////\r
182 // CXkeymacsApp message handlers\r
183 \r
184 \r
185 int CXkeymacsApp::ExitInstance() \r
186 {\r
187         if (m_hMutex) {\r
188                 ReleaseMutex(m_hMutex);\r
189                 CloseHandle(m_hMutex);\r
190 \r
191                 m_pMainWnd->DestroyWindow();\r
192                 delete m_pMainWnd;\r
193                 m_pMainWnd = NULL;\r
194         }\r
195 \r
196         return CWinApp::ExitInstance();\r
197 }\r
198 \r
199 void CAboutDlg::OnOK() \r
200 {\r
201         CDialog::OnOK();\r
202 }\r
203 \r
204 \r
205 void CAboutDlg::OnClose() \r
206 {\r
207         CDialog::OnClose();\r
208 }\r
209 \r
210 void CAboutDlg::OnUrl() \r
211 {\r
212         CString szURL;\r
213         m_cURL.GetWindowText(szURL);\r
214 \r
215         ShellExecute(m_hWnd, NULL, szURL, NULL, NULL, SW_SHOWNORMAL);\r
216 }\r
217 \r
218 HBRUSH CAboutDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor) \r
219 {\r
220         HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);\r
221 \r
222         COLORREF crBlue = RGB(0, 0, 0xff);\r
223 \r
224         if (pWnd == &m_cURL) {\r
225                 pDC->SetTextColor(crBlue);\r
226         }\r
227 \r
228         return hbr;\r
229 }\r
230 \r
231 BOOL CAboutDlg::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message) \r
232 {\r
233         CRect rect;\r
234         m_cURL.GetWindowRect(rect);\r
235 \r
236         POINT p;\r
237         ::GetCursorPos(&p);\r
238 \r
239         if (rect.PtInRect(p)) {\r
240                 HCURSOR hCursor = (HCURSOR)LoadImage(theApp.m_hInstance, MAKEINTRESOURCE(IDC_HAND_CURSOR),\r
241                                                                                          IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
242                 SetCursor(hCursor);\r
243                 return TRUE;    \r
244         }\r
245 \r
246         return CDialog::OnSetCursor(pWnd, nHitTest, message);\r
247 }\r