OSDN Git Service

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