1 // Profile.cpp: implementation of the CProfile class
\r
3 //////////////////////////////////////////////////////////////////////
\r
6 #include "xkeymacs.h"
\r
9 #include "DotXkeymacs.h"
\r
11 #include <Shlwapi.h>
\r
12 #include <TlHelp32.h>
\r
17 static char THIS_FILE[]=__FILE__;
\r
18 #define new DEBUG_NEW
\r
21 struct CommandTypeName
\r
27 static const CommandTypeName CommandTypes[] = {
\r
29 {SHIFT, _T("Shift+")},
\r
30 {CONTROL, _T("Ctrl+")},
\r
31 {CONTROL+SHIFT, _T("Ctrl+Shift+")},
\r
32 {META, _T("Meta+")},
\r
33 {META+SHIFT, _T("Meta+Shift+")},
\r
34 {CONTROL+META, _T("Ctrl+Meta+")},
\r
35 {CONTROL+META+SHIFT, _T("Ctrl+Meta+Shift+")},
\r
36 {CONTROLX+NONE, _T("Ctrl+X ")},
\r
37 {CONTROLX+SHIFT, _T("Ctrl+X Shift+")},
\r
38 {CONTROLX+CONTROL, _T("Ctrl+X Ctrl+")},
\r
39 {CONTROLX+CONTROL+SHIFT, _T("Ctrl+X Ctrl+Shift+")},
\r
40 {CONTROLX+META, _T("Ctrl+X Meta+")},
\r
41 {CONTROLX+META+SHIFT, _T("Ctrl+X Meta+Shift+")},
\r
42 {CONTROLX+CONTROL+META, _T("Ctrl+X Ctrl+Meta+")},
\r
43 {CONTROLX+CONTROL+META+SHIFT, _T("Ctrl+X Ctrl+Meta+Shift+")},
\r
46 static const KeyName KeyNames[] = {
\r
48 {VK_LBUTTON, _T("Left mouse button")},
\r
49 {VK_RBUTTON, _T("Right mouse button")},
\r
50 {VK_CANCEL, _T("Break")},
\r
51 {VK_MBUTTON, _T("Middle mouse button")},
\r
52 {0x05, _T("X1 mouse button")}, // VK_XBUTTON1
\r
53 {0x06, _T("X2 mouse button")}, // VK_XBUTTON2
\r
54 {0x07, _T("Undefined")},
\r
55 {VK_BACK, _T("Backspace")},
\r
56 {VK_TAB, _T("Tab")},
\r
57 {0x0a, _T("Reserved")},
\r
58 {0x0b, _T("Reserved")},
\r
59 {VK_CLEAR, _T("Clear")},
\r
60 {VK_RETURN, _T("Enter")},
\r
61 {0x0e, _T("Undefined")},
\r
62 {0x0f, _T("Undefined")},
\r
63 {VK_SHIFT, _T("Shift")},
\r
64 {VK_CONTROL, _T("Ctrl")},
\r
65 {VK_MENU, _T("Alt")},
\r
66 {VK_PAUSE, _T("Pause")},
\r
67 {VK_CAPITAL, _T("Caps Lock")},
\r
68 {VK_KANA, _T("Kana")}, // {VK_HANGUEL, "Hanguel"}, {VK_HANGUL, "Hangul"},
\r
69 {0x16, _T("Undefined")},
\r
70 {VK_JUNJA, _T("Junja")},
\r
71 {VK_FINAL, _T("Final")},
\r
72 {VK_KANJI, _T("Kanji")}, // {VK_HANJA, "Hanja"},
\r
73 {0x1a, _T("Undefined")},
\r
74 {VK_ESCAPE, _T("Esc")},
\r
75 {VK_CONVERT, _T("Convert")}, //
\95Ï
\8a·
\r
76 {VK_NONCONVERT, _T("Nonconvert")}, //
\96³
\95Ï
\8a·
\r
77 {VK_ACCEPT, _T("Accept")},
\r
78 {VK_MODECHANGE, _T("Mode change")},
\r
79 {VK_SPACE, _T("Space")},
\r
80 {VK_PRIOR, _T("Page Up")},
\r
81 {VK_NEXT, _T("Page Down")},
\r
82 {VK_END, _T("End")},
\r
83 {VK_HOME, _T("Home")},
\r
84 {VK_LEFT, _T("Left")},
\r
86 {VK_RIGHT, _T("Right")},
\r
87 {VK_DOWN, _T("Down")},
\r
88 {VK_SELECT, _T("Select")},
\r
89 {VK_PRINT, _T("Print")},
\r
90 {VK_EXECUTE, _T("Execute")},
\r
91 {VK_SNAPSHOT, _T("Print Screen")},
\r
92 {VK_INSERT, _T("Ins")},
\r
93 {VK_DELETE, _T("Del")},
\r
94 {VK_HELP, _T("Help")},
\r
105 {0x3a, _T("Undefined")},
\r
106 {0x3b, _T("Undefined")},
\r
107 {0x3c, _T("Undefined")},
\r
108 {0x3d, _T("Undefined")},
\r
109 {0x3e, _T("Undefined")},
\r
110 {0x3f, _T("Undefined")},
\r
111 {0x40, _T("Undefined")},
\r
138 {VK_LWIN, _T("Left Windows")},
\r
139 {VK_RWIN, _T("Right Windows")},
\r
140 {VK_APPS, _T("Application")},
\r
141 {0x5e, _T("Reserved")},
\r
142 {0x5f, _T("Sleep")}, // VK_SLEEP
\r
143 {VK_NUMPAD0, _T("Num 0")},
\r
144 {VK_NUMPAD1, _T("Num 1")},
\r
145 {VK_NUMPAD2, _T("Num 2")},
\r
146 {VK_NUMPAD3, _T("Num 3")},
\r
147 {VK_NUMPAD4, _T("Num 4")},
\r
148 {VK_NUMPAD5, _T("Num 5")},
\r
149 {VK_NUMPAD6, _T("Num 6")},
\r
150 {VK_NUMPAD7, _T("Num 7")},
\r
151 {VK_NUMPAD8, _T("Num 8")},
\r
152 {VK_NUMPAD9, _T("Num 9")},
\r
153 {VK_MULTIPLY, _T("Num *")},
\r
154 {VK_ADD, _T("Num +")},
\r
155 {VK_SEPARATOR, _T("Separator")},
\r
156 {VK_SUBTRACT, _T("Num -")},
\r
157 {VK_DECIMAL, _T("Num .")},
\r
158 {VK_DIVIDE, _T("Num /")},
\r
168 {VK_F10, _T("F10")},
\r
169 {VK_F11, _T("F11")},
\r
170 {VK_F12, _T("F12")},
\r
171 {VK_F13, _T("F13")},
\r
172 {VK_F14, _T("F14")},
\r
173 {VK_F15, _T("F15")},
\r
174 {VK_F16, _T("F16")},
\r
175 {VK_F17, _T("F17")},
\r
176 {VK_F18, _T("F18")},
\r
177 {VK_F19, _T("F19")},
\r
178 {VK_F20, _T("F20")},
\r
179 {VK_F21, _T("F21")},
\r
180 {VK_F22, _T("F22")},
\r
181 {VK_F23, _T("F23")},
\r
182 {VK_F24, _T("F24")},
\r
183 {0x88, _T("Unassigned")},
\r
184 {0x89, _T("Unassigned")},
\r
185 {0x8a, _T("Unassigned")},
\r
186 {0x8b, _T("Unassigned")},
\r
187 {0x8c, _T("Unassigned")},
\r
188 {0x8d, _T("Unassigned")},
\r
189 {0x8e, _T("Unassigned")},
\r
190 {0x8f, _T("Unassigned")},
\r
191 {VK_NUMLOCK, _T("Num Lock")},
\r
192 {VK_SCROLL, _T("Scroll Lock")},
\r
193 {0x92, _T("OEM specific")},
\r
194 {0x93, _T("OEM specific")},
\r
195 {0x94, _T("OEM specific")},
\r
196 {0x95, _T("OEM specific")},
\r
197 {0x96, _T("OEM specific")},
\r
198 {0x97, _T("Unassigned")},
\r
199 {0x98, _T("Unassigned")},
\r
200 {0x99, _T("Unassigned")},
\r
201 {0x9a, _T("Unassigned")},
\r
202 {0x9b, _T("Unassigned")},
\r
203 {0x9c, _T("Unassigned")},
\r
204 {0x9d, _T("Unassigned")},
\r
205 {0x9e, _T("Unassigned")},
\r
206 {0x9f, _T("Unassigned")},
\r
207 {VK_LSHIFT, _T("Left Shift")},
\r
208 {VK_RSHIFT, _T("Right Shift")},
\r
209 {VK_LCONTROL, _T("Left Ctrl")},
\r
210 {VK_RCONTROL, _T("Right Ctrl")},
\r
211 {VK_LMENU, _T("Left Alt")},
\r
212 {VK_RMENU, _T("Right Alt")},
\r
213 {0xa6, _T("Browser Back")}, // VK_BROWSER_BACK
\r
214 {0xa7, _T("Browser Forward")}, // VK_BROWSER_FORWARD
\r
215 {0xa8, _T("Browser Refresh")}, // VK_BROWSER_REFRESH
\r
216 {0xa9, _T("Browser Stop")}, // VK_BROWSER_STOP
\r
217 {0xaa, _T("Browser Search")}, // VK_BROWSER_SEARCH
\r
218 {0xab, _T("Browser Favorites")}, // VK_BROWSER_FAVORITES
\r
219 {0xac, _T("Browser Start")}, // VK_BROWSER_HOME
\r
220 {0xad, _T("Volume Mute")}, // VK_VOLUME_MUTE
\r
221 {0xae, _T("Volume Down")}, // VK_VOLUME_DOWN
\r
222 {0xaf, _T("Volume Up")}, // VK_VOLUME_UP
\r
223 {0xb0, _T("Next Track")}, // VK_MEDIA_NEXT_TRACK
\r
224 {0xb1, _T("Previous Track")}, // VK_MEDIA_PREV_TRACK
\r
225 {0xb2, _T("Stop Media")}, // VK_MEDIA_STOP
\r
226 {0xb3, _T("Play/Pause Media")}, // VK_MEDIA_PLAY_PAUSE
\r
227 {0xb4, _T("Start Mail")}, // VK_LAUNCH_MAIL
\r
228 {0xb5, _T("Select Media")}, // VK_LAUNCH_MEDIA_SELECT
\r
229 {0xb6, _T("Start Application 1")}, // VK_LAUNCH_APP1
\r
230 {0xb7, _T("Start Application 2")}, // VK_LAUNCH_APP2
\r
231 {0xb8, _T("Reserved")},
\r
232 {0xb9, _T("Reserved")},
\r
233 {0xba, _T(";")}, // VK_OEM_1
\r
234 // {0xba, _T(":")}, // VK_OEM_1 // for Japanese keyboard
\r
235 {0xbb, _T("+")}, // VK_OEM_PLUS
\r
236 // {0xbb, _T(";")}, // VK_OEM_PLUS // for Japanese keyboard
\r
237 {0xbc, _T(",")}, // VK_OEM_COMMA
\r
238 {0xbd, _T("-")}, // VK_OEM_MINUS
\r
239 {0xbe, _T(".")}, // VK_OEM_PERIOD
\r
240 {0xbf, _T("/")}, // VK_OEM_2
\r
241 {0xc0, _T("`")}, // VK_OEM_3
\r
242 // {0xc0, _T("@")}, // VK_OEM_3 // for Japanese keyboard
\r
243 {0xc1, _T("Reserved")},
\r
244 {0xc2, _T("Reserved")},
\r
245 {0xc3, _T("Reserved")},
\r
246 {0xc4, _T("Reserved")},
\r
247 {0xc5, _T("Reserved")},
\r
248 {0xc6, _T("Reserved")},
\r
249 {0xc7, _T("Reserved")},
\r
250 {0xc8, _T("Reserved")},
\r
251 {0xc9, _T("Reserved")},
\r
252 {0xca, _T("Reserved")},
\r
253 {0xcb, _T("Reserved")},
\r
254 {0xcc, _T("Reserved")},
\r
255 {0xcd, _T("Reserved")},
\r
256 {0xce, _T("Reserved")},
\r
257 {0xcf, _T("Reserved")},
\r
258 {0xd0, _T("Reserved")},
\r
259 {0xd1, _T("Reserved")},
\r
260 {0xd2, _T("Reserved")},
\r
261 {0xd3, _T("Reserved")},
\r
262 {0xd4, _T("Reserved")},
\r
263 {0xd5, _T("Reserved")},
\r
264 {0xd6, _T("Reserved")},
\r
265 {0xd7, _T("Reserved")},
\r
266 {0xd8, _T("Unassigned")},
\r
267 {0xd9, _T("Unassigned")},
\r
268 {0xda, _T("Unassigned")},
\r
269 {0xdb, _T("[")}, // VK_OEM_4
\r
270 {0xdc, _T("Backslash")}, // VK_OEM_5
\r
271 {0xdd, _T("]")}, // VK_OEM_6
\r
272 {0xde, _T("'")}, // VK_OEM_7
\r
273 {0xdf, _T("OEM specific")}, // VK_OEM_8
\r
274 {0xe0, _T("Reserved")},
\r
275 {0xe1, _T("OEM specific")},
\r
276 {0xe2, _T("Backslash for 106 keyboard")}, // VK_OEM_102
\r
277 {0xe3, _T("OEM specific")},
\r
278 {0xe4, _T("OEM specific")},
\r
279 {0xe5, _T("Process")}, // VK_PROCESSKEY
\r
280 {0xe6, _T("OEM specific")},
\r
281 {0xe7, _T("Packet")}, // VK_PACKET
\r
282 {0xe8, _T("Unassigned")},
\r
283 {0xe9, _T("OEM specific")},
\r
284 {0xea, _T("OEM specific")},
\r
285 {0xeb, _T("OEM specific")},
\r
286 {0xec, _T("OEM specific")},
\r
287 {0xed, _T("OEM specific")},
\r
288 {0xee, _T("OEM specific")},
\r
289 {0xef, _T("OEM specific")},
\r
290 {0xf0, _T("Eisu")}, //
\89p
\90\94\r
291 {0xf1, _T("OEM specific")},
\r
292 {0xf2, _T("Hiragana")}, //
\82Ð
\82ç
\82ª
\82È
\r
293 {0xf3, _T("Hankaku/Zenkaku 0xf3")}, // "
\94¼
\8ap/
\91S
\8ap"
\r
294 {0xf4, _T("Hankaku/Zenkaku 0xf4")}, // "
\94¼
\8ap/
\91S
\8ap"
\r
295 {0xf5, _T("OEM specific")},
\r
296 {VK_ATTN, _T("Attn")},
\r
297 {VK_CRSEL, _T("CrSel")},
\r
298 {VK_EXSEL, _T("ExSel")},
\r
299 {VK_EREOF, _T("Erace EOF")},
\r
300 {VK_PLAY, _T("Play")},
\r
301 {VK_ZOOM, _T("Zoom")},
\r
302 {VK_NONAME, _T("Noname")},
\r
303 {VK_PA1, _T("PA1")},
\r
304 {VK_OEM_CLEAR, _T("OEM Clear")},
\r
308 CData CProfile::m_Data[MAX_APP];
\r
309 TASK_LIST CProfile::m_TaskList[MAX_TASKS];
\r
310 DWORD CProfile::m_dwTasks;
\r
312 enum { INITIAL_SIZE = 51200 };
\r
313 enum { EXTEND_SIZE = 25600 };
\r
315 void CProfile::Item2AppName(CString *const sz)
\r
317 if (IsTheString(*sz, IDS_DEFAULT_TITLE)) {
\r
318 sz->LoadString(IDS_DEFAULT);
\r
321 if (IsTheString(*sz, IDS_DIALOG_TITLE)) {
\r
322 sz->LoadString(IDS_DIALOG);
\r
325 int nStart, nEnd, nCount;
\r
327 nStart = sz->ReverseFind(_T('(')) + 1;
\r
328 nEnd = sz->Find(_T(')'), nStart) - 1;
\r
329 nCount = (nEnd + 1) - nStart;
\r
330 *sz = sz->Mid(nStart, nCount);
\r
333 int CProfile::IsNotSameString(CComboBox *const pApplication, const CString szListItem)
\r
335 CString szItem, szList;
\r
336 szList = szListItem;
\r
337 Item2AppName(&szList);
\r
339 for (int i = 0; i < pApplication->GetCount(); ++i) {
\r
340 pApplication->GetLBText(i, szItem);
\r
341 Item2AppName(&szItem);
\r
342 if (!_tcsicmp(szItem, szList)) {
\r
350 int CProfile::CountSeparator(const CString szMainString, const CString szSeparator)
\r
355 while ((index = szMainString.Find(szSeparator, index)) != -1) {
\r
363 void CProfile::GetNthString(CString *const szAppName, const CString szWindowName, const CString szSeparator, int n)
\r
368 index = szWindowName.Find(szSeparator, index + 1);
\r
373 nStart = index + szSeparator.GetLength();
\r
378 int nEnd = szWindowName.Find(szSeparator, nStart);
\r
380 nEnd = szWindowName.GetLength();
\r
383 *szAppName = szWindowName.Mid(nStart, nEnd - nStart);
\r
386 void CProfile::GetAppName(CString *const szAppName, LPCTSTR pWindowName)
\r
388 CString szWindowName(pWindowName);
\r
389 CString szSeparator(MAKEINTRESOURCE(IDS_SEPARATE_WINDOWTITLE));
\r
390 int nWord = CountSeparator(szWindowName, szSeparator) + 1;
\r
393 GetNthString(szAppName, szWindowName, szSeparator, nWord);
\r
394 if (szAppName->GetAt(0) == _T('[')
\r
395 || szAppName->Find(_T('.'), 0) != -1 // for Microsoft Project
\r
396 || szAppName->Find(_T(']'), 0) != -1) { // for the file name like [foo - bar]
\r
403 *szAppName = szWindowName;
\r
406 BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
\r
408 CComboBox *pApplication = (CComboBox*)lParam;
\r
409 PTASK_LIST pTask = CProfile::m_TaskList;
\r
411 TCHAR szWindowName[WINDOW_TEXT_LENGTH];
\r
412 TCHAR szClassName[CLASS_NAME_LENGTH];
\r
413 WINDOWPLACEMENT wpl;
\r
415 wpl.length = sizeof(WINDOWPLACEMENT);
\r
416 ::GetWindowText(hWnd, szWindowName, sizeof(szWindowName));
\r
417 GetClassName(hWnd, szClassName, sizeof(szClassName));
\r
420 // Get Process Name
\r
421 DWORD dwProcessId = 0;
\r
422 GetWindowThreadProcessId(hWnd, &dwProcessId);
\r
424 for (i = 0; i < CProfile::m_dwTasks; ++i) {
\r
425 if (pTask[i].dwProcessId == dwProcessId) {
\r
427 // Get Application Name
\r
428 if (szWindowName[0] == '\0') {
\r
431 if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_B2)), sizeof(pTask[i].ProcessName))) {
\r
432 szAppName.LoadString(IDS_BECKY);
\r
433 } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_EXPLORER)), sizeof(pTask[i].ProcessName))) {
\r
434 szAppName.LoadString(IDS_PROGRAM_MANAGER);
\r
435 } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_MSIMN)), sizeof(pTask[i].ProcessName))) {
\r
436 szAppName.LoadString(IDS_OUTLOOK_EXPRESS);
\r
437 } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_PROJECT)), sizeof(pTask[i].ProcessName))
\r
438 || !_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_EXCEL)), sizeof(pTask[i].ProcessName))
\r
439 || !_tcsnicmp(pTask[i].ProcessName, _T("psp.exe"), sizeof(pTask[i].ProcessName))) {
\r
440 GetNthString(&szAppName, szWindowName, CString(MAKEINTRESOURCE(IDS_SEPARATE_WINDOWTITLE)), 1);
\r
441 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("sakura.exe"), sizeof(pTask[i].ProcessName))) {
\r
442 GetNthString(&szAppName, szWindowName, CString(MAKEINTRESOURCE(IDS_SEPARATE_WINDOWTITLE)), 2); // '.' is included, so...
\r
443 } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_MSDN)), sizeof(pTask[i].ProcessName))) {
\r
444 szAppName = szWindowName;
\r
445 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("devenv.exe"), sizeof(pTask[i].ProcessName))) {
\r
446 szAppName.Format(_T("Microsoft Visual Studio .NET"));
\r
447 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vb6.exe"), sizeof(pTask[i].ProcessName))) {
\r
448 szAppName.Format(_T("Microsoft Visual Basic"));
\r
449 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("ssexp.exe"), sizeof(pTask[i].ProcessName))) {
\r
450 szAppName.LoadString(IDS_VISUAL_SOURCESAFE_EXPLORER);
\r
451 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("sh.exe"), sizeof(pTask[i].ProcessName))) {
\r
452 szAppName.Format(_T("MKS Korn Shell"));
\r
453 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("csh.exe"), sizeof(pTask[i].ProcessName))) {
\r
454 szAppName.Format(_T("C Shell"));
\r
455 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vim.exe"), sizeof(pTask[i].ProcessName))) {
\r
456 szAppName.Format(_T("VIM"));
\r
458 CUtils::SetCorrectApplicationName(pTask[i].ProcessName, szWindowName);
\r
459 GetAppName(&szAppName, szWindowName);
\r
466 if ((IsWindowVisible(hWnd)) // Is visible?
\r
467 && (GetWindow(hWnd, GW_OWNER) == NULL) // Is top level window?
\r
468 && (lstrlen(szWindowName) > 0) // Have caption?
\r
469 && (pApplication->FindString(-1, szClassName) == CB_ERR)) {// Is not same string?
\r
470 CString szListItem;
\r
471 szListItem.Format(IDS_APPLICATION_LIST_ITEM, szAppName, pTask[i].ProcessName);
\r
472 if (IsNotSameString(pApplication, szListItem)) {
\r
473 pApplication->AddString(szListItem);
\r
482 } WindowTextTypes[] = {
\r
483 { IDS_WINDOW_TEXT_MATCH, CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH)) },
\r
484 { IDS_WINDOW_TEXT_MATCH_FORWARD, CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH_FORWARD)) },
\r
485 { IDS_WINDOW_TEXT_MATCH_BACKWARD, CString(MAKEINTRESOURCE(IDS_WINDOW_TEXT_MATCH_BACKWARD)) },
\r
488 inline int WindowTextType(const CString& cstr) {
\r
489 for (int i = 0; i < _countof(WindowTextTypes); ++i)
\r
490 if (WindowTextTypes[i].cstr == cstr)
\r
491 return WindowTextTypes[i].type;
\r
492 return IDS_WINDOW_TEXT_IGNORE;
\r
495 void CProfile::LoadRegistry()
\r
497 bool bDialog = false;
\r
498 const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));
\r
499 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
501 entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
502 CString appName = AfxGetApp()->GetProfileString(section, entry);
\r
503 if (appName.IsEmpty()) {
\r
507 appName.LoadString(IDS_DIALOG);
\r
510 appName.LoadString(IDS_DEFAULT);
\r
511 } else if (appName == CString(MAKEINTRESOURCE(IDS_DIALOG)))
\r
513 m_Data[nAppID].SetApplicationName(appName);
\r
515 entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);
\r
516 m_Data[nAppID].SetApplicationTitle(AfxGetApp()->GetProfileString(appName, entry));
\r
517 entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);
\r
518 m_Data[nAppID].SetWindowText(AfxGetApp()->GetProfileString(appName, entry, _T("*")));
\r
519 entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT_TYPE);
\r
520 m_Data[nAppID].SetWindowTextType(WindowTextType(AfxGetApp()->GetProfileString(appName, entry)));
\r
522 CString regApp(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));
\r
523 regApp += _T("\\") + appName;
\r
524 for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) {
\r
525 entry = CCommands::GetCommandName(nComID);
\r
527 const CString& regKey = regApp + _T("\\") + entry;
\r
528 if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
\r
529 TCHAR szKeyBind[128];
\r
530 DWORD dwKeyBind = _countof(szKeyBind);
\r
531 for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {
\r
533 ReadKeyBind(&nType, &nKey, szKeyBind);
\r
534 m_Data[nAppID].SetCommandID(nType, nKey, nComID);
\r
535 dwKeyBind = _countof(szKeyBind);
\r
539 // Set the default assignment
\r
540 for (int i = 0; const int nKey = CCommands::GetDefaultCommandKey(nComID, i); ++i) {
\r
541 if (CCommands::GetDefaultControlID(nComID, i) == IDC_CO2)
\r
543 const int nType = CCommands::GetDefaultCommandType(nComID, i);
\r
544 m_Data[nAppID].SetCommandID(nType, nKey, nComID);
\r
548 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {
\r
550 const CString regKey = regApp + _T("\\") + CDotXkeymacs::GetFunctionSymbol(nFuncID);
\r
551 if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
\r
552 CDotXkeymacs::ClearKey(nFuncID, nAppID);
\r
553 TCHAR szKeyBind[128];
\r
554 DWORD dwKeyBind = _countof(szKeyBind);
\r
555 for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {
\r
557 ReadKeyBind(&nType, &nKey, szKeyBind);
\r
558 CDotXkeymacs::SetKey(nFuncID, nAppID, nType, nKey);
\r
559 dwKeyBind = _countof(szKeyBind);
\r
565 entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);
\r
566 m_Data[nAppID].SetKillRingMax(AfxGetApp()->GetProfileInt(appName, entry, 1));
\r
567 entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);
\r
568 m_Data[nAppID].SetUseDialogSetting(AfxGetApp()->GetProfileInt(appName, entry, 1));
\r
569 entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);
\r
570 m_Data[nAppID].SetSettingStyle(AfxGetApp()->GetProfileInt(appName, entry, 0) ? SETTING_DISABLE : SETTING_SPECIFIC);
\r
571 entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);
\r
572 m_Data[nAppID].SetIgnoreUndefinedMetaCtrl(AfxGetApp()->GetProfileInt(appName, entry, 0));
\r
573 entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);
\r
574 m_Data[nAppID].SetIgnoreUndefinedC_x(AfxGetApp()->GetProfileInt(appName, entry, 0));
\r
575 entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);
\r
576 m_Data[nAppID].SetEnableCUA(AfxGetApp()->GetProfileInt(appName, entry, 0));
\r
577 entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);
\r
578 m_Data[nAppID].Set326Compatible(AfxGetApp()->GetProfileInt(appName, entry, 0));
\r
582 void CProfile::SaveRegistry()
\r
584 const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));
\r
585 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
586 const CString& appName = m_Data[nAppID].GetApplicationName();
\r
588 entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
589 if (appName.IsEmpty()) {
\r
590 if (!AfxGetApp()->GetProfileString(section, entry).IsEmpty())
\r
591 AfxGetApp()->WriteProfileString(section, entry, _T(""));
\r
594 AfxGetApp()->WriteProfileString(section, entry, appName);
\r
596 entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);
\r
597 CString appTitle = m_Data[nAppID].GetApplicationTitle();
\r
598 appTitle.TrimLeft(_T(' '));
\r
599 AfxGetApp()->WriteProfileString(appName, entry, appTitle);
\r
600 entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);
\r
601 AfxGetApp()->WriteProfileString(appName, entry, m_Data[nAppID].GetWindowText());
\r
602 entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT_TYPE);
\r
603 AfxGetApp()->WriteProfileString(appName, entry, CString(MAKEINTRESOURCE(m_Data[nAppID].GetWindowTextType())));
\r
605 CString regApp(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));
\r
606 regApp += _T("\\") + appName;
\r
607 // Create all commands
\r
608 for (int nComID = 1; nComID < MAX_COMMAND; ++nComID)
\r
609 SaveCommand(appName, nComID);
\r
610 for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType)
\r
611 for (int nKey = 0; nKey < MAX_KEY; ++nKey)
\r
612 SaveKeyBind(appName, m_Data[nAppID].GetCommandID(nType, nKey), nType, nKey);
\r
613 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)
\r
614 for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {
\r
616 CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);
\r
617 SaveKeyBind(appName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);
\r
620 entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);
\r
621 AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetKillRingMax());
\r
622 entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);
\r
623 AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetUseDialogSetting());
\r
624 entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);
\r
625 AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetSettingStyle() == SETTING_DISABLE);
\r
626 entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);
\r
627 AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetIgnoreUndefinedMetaCtrl());
\r
628 entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);
\r
629 AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetIgnoreUndefinedC_x());
\r
630 entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);
\r
631 AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].GetEnableCUA());
\r
632 entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);
\r
633 AfxGetApp()->WriteProfileInt(appName, entry, m_Data[nAppID].Get326Compatible());
\r
637 void CProfile::LoadData()
\r
639 CDotXkeymacs::Load();
\r
644 void CProfile::SaveData()
\r
646 DeleteAllRegistryData();
\r
651 void CProfile::SetDllData()
\r
653 CXkeymacsDll::ClearFunctionDefinition();
\r
654 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {
\r
655 CXkeymacsDll::SetFunctionDefinition(nFuncID, CDotXkeymacs::GetFunctionDefinition(nFuncID));
\r
658 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
660 CString szApplicationName = m_Data[nAppID].GetApplicationName();
\r
662 if (szApplicationName.IsEmpty()) {
\r
663 CXkeymacsDll::Clear(nAppID);
\r
667 CXkeymacsDll::SetApplicationName(nAppID, szApplicationName);
\r
668 CXkeymacsDll::SetWindowText(nAppID, m_Data[nAppID].GetWindowText());
\r
669 CXkeymacsDll::SetCommandID(nAppID, CONTROL, 'X', 0);
\r
671 for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType) {
\r
672 for (int nKey = 0; nKey < MAX_KEY; ++nKey) {
\r
673 const int nComID = m_Data[nAppID].GetCommandID(nType, nKey);
\r
674 CXkeymacsDll::SetCommandID(nAppID, nType, nKey, nComID);
\r
675 if ((nType & CONTROLX) && nComID) {
\r
676 CXkeymacsDll::SetCommandID(nAppID, CONTROL, 'X', 1); // Commands[1] is C-x
\r
681 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {
\r
682 for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {
\r
685 CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);
\r
686 CXkeymacsDll::SetFunctionKey(nFuncID, nAppID, nType, nKey);
\r
687 if (nType & CONTROLX) {
\r
688 CXkeymacsDll::SetCommandID(nAppID, CONTROL, 'X', 1); // Commands[1] is C-x
\r
693 CXkeymacsDll::SetKillRingMax(nAppID, m_Data[nAppID].GetKillRingMax());
\r
694 CXkeymacsDll::SetUseDialogSetting(nAppID, m_Data[nAppID].GetUseDialogSetting());
\r
695 CXkeymacsDll::SetSettingStyle(nAppID, m_Data[nAppID].GetSettingStyle());
\r
696 CXkeymacsDll::SetIgnoreUndefinedMetaCtrl(nAppID, m_Data[nAppID].GetIgnoreUndefinedMetaCtrl());
\r
697 CXkeymacsDll::SetIgnoreUndefinedC_x(nAppID, m_Data[nAppID].GetIgnoreUndefinedC_x());
\r
698 CXkeymacsDll::SetEnableCUA(nAppID, m_Data[nAppID].GetEnableCUA());
\r
699 CXkeymacsDll::Set326Compatible(nAppID, m_Data[nAppID].Get326Compatible());
\r
701 CXkeymacsApp *pApp = static_cast<CXkeymacsApp *>(AfxGetApp());
\r
702 if (!pApp->IsWow64())
\r
704 if (!CXkeymacsDll::SaveConfig())
\r
706 pApp->SendIPCMessage(XKEYMACS_RELOAD);
\r
709 void CProfile::ReadKeyBind(int *const pnCommandType, int *const pnKey, LPCTSTR szKeyBind)
\r
711 *pnCommandType = KeyBind2CommandType(szKeyBind);
\r
712 *pnKey = KeyBind2Key(szKeyBind + _tcslen(CommandType2String(*pnCommandType)));
\r
715 CString CProfile::WriteKeyBind(const int nType, const int nKey)
\r
718 szKeyBind.Format(_T("%s%s"), CommandType2String(nType), Key2String(nKey));
\r
722 int CProfile::KeyBind2CommandType(LPCTSTR szKeyBind)
\r
724 for (int nType = MAX_COMMAND_TYPE - 1; nType; --nType) {
\r
725 if (IsCommandType(nType, szKeyBind)) {
\r
732 int CProfile::KeyBind2Key(LPCTSTR szKey)
\r
734 for (int nKey = 1; nKey <= 0xff; ++nKey) {
\r
735 if (!_tcscmp(szKey, Key2String(nKey))) {
\r
742 LPCTSTR CProfile::CommandType2String(int nType)
\r
744 if (nType < 0 || sizeof(CommandTypes) / sizeof(CommandTypes[0]) <= nType) {
\r
748 return CommandTypes[nType].szName;
\r
751 LPCTSTR CProfile::Key2String(int nKey)
\r
753 if (CProfile::Is106Keyboard()) {
\r
768 if (nKey < 0 || sizeof(KeyNames) / sizeof(KeyNames[0]) <= nKey) {
\r
772 return KeyNames[nKey].name;
\r
775 BOOL CProfile::IsCommandType(const int nType, LPCTSTR szKeyBind)
\r
777 LPCTSTR szCommandType = CommandType2String(nType);
\r
779 if (!_tcsnicmp(szKeyBind, szCommandType, _tcslen(szCommandType))) {
\r
786 void CProfile::SaveKeyBind(const CString szApplicationName, const int nComID, const int nType, const int nKey)
\r
792 CString szCommandName = CCommands::GetCommandName(nComID);
\r
793 if (szCommandName.IsEmpty()) {
\r
797 SaveKeyBind(szApplicationName, szCommandName, nType, nKey);
\r
800 void CProfile::SaveKeyBind(const CString szApplicationName, const CString szCommandName, const int nType, const int nKey)
\r
802 CString szKeyBind = WriteKeyBind(nType, nKey);
\r
803 CString szSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));
\r
804 szSubKey += _T("\\") + szApplicationName + _T("\\") + szCommandName;
\r
805 if (!szKeyBind.IsEmpty()) {
\r
806 szSubKey += _T("\\") + szKeyBind;
\r
810 if (RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS) {
\r
815 void CProfile::SaveCommand(const CString szApplicationName, const int nComID)
\r
817 SaveKeyBind(szApplicationName, nComID, 0, 0);
\r
820 void CProfile::AddKeyBind2C_(const CString szApplicationName, const BYTE bVk)
\r
823 for (nComID = 0; nComID < MAX_COMMAND; ++nComID) {
\r
824 if (Commands[nComID].fCommand == CCommands::C_) {
\r
829 SaveKeyBind(szApplicationName, nComID, NONE, bVk);
\r
832 void CProfile::LevelUp()
\r
834 const int nDefalutLevel = 0;
\r
835 const int nLatestLevel = 4;
\r
839 szEntry.Format(_T("Level"));
\r
841 switch (AfxGetApp()->GetProfileInt(szSection, szEntry, nDefalutLevel)) {
\r
842 case nDefalutLevel:
\r
844 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
846 szEntry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
848 CString szApplicationName;
\r
849 szApplicationName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), szEntry);
\r
850 if (szApplicationName.IsEmpty()) {
\r
854 AddKeyBind2C_(szApplicationName, VK_LCONTROL);
\r
855 AddKeyBind2C_(szApplicationName, VK_RCONTROL);
\r
858 // Do NOT write break; here.
\r
861 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
863 szEntry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
865 CString szApplicationName;
\r
866 szApplicationName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), szEntry);
\r
867 if (szApplicationName.IsEmpty()) {
\r
871 // Set kill-ring-max 1 if it is 0.
\r
872 if (!AfxGetApp()->GetProfileInt(szApplicationName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 0)) {
\r
873 AfxGetApp()->WriteProfileInt(szApplicationName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 1);
\r
877 // Do NOT write break; here.
\r
880 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
882 szEntry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
884 CString szApplicationName;
\r
885 szApplicationName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), szEntry);
\r
886 if (szApplicationName.IsEmpty()) {
\r
890 // Chaged a label from Enter to newline.
\r
891 CString szSrcSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));
\r
892 szSrcSubKey += _T("\\") + szApplicationName + _T("\\") + _T("Enter");
\r
893 CString szDestSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));
\r
894 szDestSubKey += _T("\\") + szApplicationName + _T("\\") + _T("newline");
\r
895 HKEY hKeyDest = NULL;
\r
896 if (RegCreateKeyEx(HKEY_CURRENT_USER, szDestSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeyDest, NULL) == ERROR_SUCCESS) {
\r
897 SHCopyKey(HKEY_CURRENT_USER, szSrcSubKey, hKeyDest, NULL);
\r
898 SHDeleteKey(HKEY_CURRENT_USER, szSrcSubKey);
\r
899 RegCloseKey(hKeyDest);
\r
903 // Do NOT write break; here.
\r
906 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
908 szEntry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
910 CString szApplicationName;
\r
911 szApplicationName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), szEntry);
\r
912 if (szApplicationName.IsEmpty()) {
\r
916 // rename original function to remove IDS_REG_ORIGINAL_PREFIX
\r
917 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {
\r
919 CString szSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA));
\r
920 szSubKey += _T("\\") + szApplicationName + _T("\\") + CString(MAKEINTRESOURCE(IDS_REG_ORIGINAL_PREFIX)) + CDotXkeymacs::GetFunctionSymbol(nFuncID);
\r
921 if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
\r
922 // Use registry data
\r
923 TCHAR szKeyBind[128] = {'\0'};
\r
924 DWORD dwKeyBind = sizeof(szKeyBind);
\r
925 FILETIME ft = {'\0'}; // not use
\r
926 for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, &ft) == ERROR_SUCCESS; ++dwIndex) {
\r
929 ReadKeyBind(&nType, &nKey, szKeyBind);
\r
930 SaveKeyBind(szApplicationName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);
\r
932 memset(szKeyBind, 0, sizeof(szKeyBind));
\r
933 dwKeyBind = sizeof(szKeyBind);
\r
943 // case nLatestLevel-1:
\r
945 AfxGetApp()->WriteProfileInt(szSection, szEntry, nLatestLevel);
\r
952 void CProfile::InitDllData()
\r
958 void CProfile::ClearData(const CString szCurrentApplication)
\r
961 for (nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
962 if (m_Data[nAppID].GetApplicationName() == szCurrentApplication) {
\r
966 if (nAppID < MAX_APP) {
\r
967 m_Data[nAppID].ClearAll();
\r
971 // return count of saved settings
\r
972 int CProfile::GetSavedSettingCount()
\r
974 int nSavedSetting = 0;
\r
976 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
977 CString szApplicationName;
\r
978 szApplicationName = m_Data[nAppID].GetApplicationName();
\r
979 if (!szApplicationName.IsEmpty()) {
\r
984 return nSavedSetting;
\r
987 void CProfile::InitApplicationList(CComboBox *const cApplicationList)
\r
989 cApplicationList->ResetContent();
\r
993 EnumWindows(EnumWindowsProc, (LPARAM)cApplicationList);
\r
995 CString szListItem;
\r
996 for (int i = 0; i < MAX_APP; ++i) {
\r
997 CString szApplicationName = m_Data[i].GetApplicationName();
\r
998 CString szApplicationTitle = m_Data[i].GetApplicationTitle();
\r
999 if (szApplicationName == _T("IME")) // IDS_IME_FILE_NAME
\r
1001 szListItem.Format(IDS_APPLICATION_LIST_ITEM, szApplicationTitle, szApplicationName);
\r
1002 if (IsNotSameString(cApplicationList, szListItem)
\r
1003 && !IsDefault(szApplicationName)
\r
1004 && !IsDialog(szApplicationName)
\r
1005 && !szApplicationName.IsEmpty()) {
\r
1006 cApplicationList->AddString(szListItem);
\r
1010 AddIMEInfo(cApplicationList);
\r
1013 cApplicationList->InsertString(0, CString(MAKEINTRESOURCE(IDS_DIALOG_TITLE)));
\r
1016 cApplicationList->InsertString( 0, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));
\r
1017 cApplicationList->SelectString(-1, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));
\r
1020 void CProfile::AddIMEInfo(CComboBox *cApplicationList)
\r
1022 const UINT n = GetKeyboardLayoutList(0, NULL);
\r
1025 std::vector<HKL> hkls(n);
\r
1026 GetKeyboardLayoutList(n, &hkls[0]);
\r
1027 TCHAR szFileName[MAX_PATH];
\r
1028 TCHAR szDescription[WINDOW_TEXT_LENGTH];
\r
1029 for (std::vector<HKL>::const_iterator p = hkls.begin(); p != hkls.end(); ++p)
\r
1030 if (ImmGetDescription(*p, szDescription, WINDOW_TEXT_LENGTH) &&
\r
1031 ImmGetIMEFileName(*p, szFileName, MAX_PATH)) {
\r
1033 item.Format(IDS_APPLICATION_LIST_ITEM, szDescription, szFileName);
\r
1034 if (IsNotSameString(cApplicationList, item))
\r
1035 cApplicationList->AddString(item);
\r
1039 void CProfile::GetTaskList()
\r
1041 ZeroMemory(m_TaskList, sizeof(m_TaskList));
\r
1043 HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
\r
1044 if (hProcessSnap == (HANDLE)-1)
\r
1048 PROCESSENTRY32 processEntry32 = {sizeof(PROCESSENTRY32)};
\r
1049 if (Process32First(hProcessSnap, &processEntry32)) {
\r
1051 lstrcpy(m_TaskList[m_dwTasks].ProcessName, processEntry32.szExeFile);
\r
1052 m_TaskList[m_dwTasks++].dwProcessId = processEntry32.th32ProcessID;
\r
1053 } while (m_dwTasks < MAX_TASKS && Process32Next(hProcessSnap, &processEntry32));
\r
1056 CloseHandle(hProcessSnap);
\r
1059 // return application index
\r
1060 // and update setting style
\r
1061 // if there is NOT the application in the data, this function takes care of it.
\r
1062 int CProfile::GetApplicationIndex(const CString szApplicationName, const BOOL bSaveAndValidate, int *const nSettingStyle)
\r
1064 if (!bSaveAndValidate) { // SetDialogData
\r
1065 *nSettingStyle = SETTING_UNDEFINED;
\r
1068 int nAppID = GetApplicationIndex(szApplicationName);
\r
1070 if (nAppID == MAX_APP) {
\r
1071 if (bSaveAndValidate) { // GetDialogData
\r
1072 for (nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
1073 CString sz = m_Data[nAppID].GetApplicationName();
\r
1074 if (sz.IsEmpty()) {
\r
1075 m_Data[nAppID].SetApplicationName(szApplicationName);
\r
1079 if (nAppID == MAX_APP) {
\r
1082 } else { // SetDialogData
\r
1083 for (nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
1084 if (IsDefault(m_Data[nAppID].GetApplicationName())) {
\r
1085 *nSettingStyle = SETTING_DEFAULT;
\r
1089 if (nAppID == MAX_APP) {
\r
1095 if (bSaveAndValidate) { // GetDialogData
\r
1096 m_Data[nAppID].SetSettingStyle(*nSettingStyle);
\r
1097 } else { // SetDialogData
\r
1098 if (*nSettingStyle == SETTING_UNDEFINED) { // It means that *nSettingStyle != SETTING_DEFAULT.
\r
1099 *nSettingStyle = m_Data[nAppID].GetSettingStyle();
\r
1106 BOOL CProfile::Is106Keyboard()
\r
1108 static KEYBOARD_TYPE keyboard = UNKNOWN_KEYBOARD;
\r
1110 if (keyboard == UNKNOWN_KEYBOARD) {
\r
1111 OSVERSIONINFO verInfo = {0};
\r
1112 verInfo.dwOSVersionInfoSize = sizeof (verInfo);
\r
1113 GetVersionEx(&verInfo);
\r
1115 DWORD subtype = 0;
\r
1116 DWORD cbData = sizeof(subtype);
\r
1118 if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
\r
1120 CString szSubKey(_T("SYSTEM\\CurrentControlSet\\Services\\i8042prt\\Parameters"));
\r
1121 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
\r
1122 static const CString szValueName(_T("OverrideKeyboardSubtype"));
\r
1123 if (RegQueryValueEx(hKey, szValueName, NULL, NULL, (LPBYTE)&subtype, &cbData) != ERROR_SUCCESS) {
\r
1126 RegCloseKey(hKey);
\r
1128 } else if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
\r
1129 subtype = GetPrivateProfileInt(_T("keyboard"), _T("subtype"), 0, _T("system.ini"));
\r
1132 keyboard = (subtype & 0x02) ? JAPANESE_KEYBOARD : ENGLISH_KEYBOARD;
\r
1135 return keyboard == JAPANESE_KEYBOARD;
\r
1138 BOOL CProfile::IsTheString(const CString sz, const UINT nID)
\r
1140 return sz == CString(MAKEINTRESOURCE(nID));
\r
1143 // if sz is "Default", return TRUE
\r
1144 BOOL CProfile::IsDefault(const CString sz)
\r
1146 return IsTheString(sz, IDS_DEFAULT);
\r
1149 // if sz is "Dialog", return TRUE
\r
1150 BOOL CProfile::IsDialog(const CString sz)
\r
1152 return IsTheString(sz, IDS_DIALOG);
\r
1155 void CProfile::GetApplicationTitle(CComboBox *const cApplicationList, CString &rList, const int nIndex)
\r
1157 if (0 <= nIndex) {
\r
1158 cApplicationList->GetLBText(nIndex, rList);
\r
1160 cApplicationList->GetWindowText(rList);
\r
1163 if (IsTheString(rList, IDS_DEFAULT_TITLE)) {
\r
1164 rList.LoadString(IDS_DEFAULT);
\r
1167 if (IsTheString(rList, IDS_DIALOG_TITLE)) {
\r
1168 rList.LoadString(IDS_DIALOG);
\r
1174 void CProfile::UpdateApplicationTitle(CComboBox *const cApplicationList, const CString szCurrentApplication, const int nAppID, const BOOL bSaveAndValidate)
\r
1176 static CString szApplicationTitle;
\r
1177 if (bSaveAndValidate) { // GetDialogData
\r
1178 if (!CProfile::IsDefault(szCurrentApplication)) {
\r
1179 m_Data[nAppID].SetApplicationTitle(szApplicationTitle);
\r
1181 szApplicationTitle.Empty();
\r
1182 } else { // SetDialogData
\r
1183 CString szListItem;
\r
1184 CProfile::GetApplicationTitle(cApplicationList, szListItem);
\r
1185 int nEndTitle = szListItem.ReverseFind(_T('('));
\r
1186 if (nEndTitle > 0) {
\r
1187 szApplicationTitle = szListItem.Left(nEndTitle);
\r
1192 void CProfile::SetCommandID(const int nAppID, const int nType, const int nKey, int nComID)
\r
1194 if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_) {
\r
1195 // Change CommandID C_Eisu
\r
1196 for (nComID = 1; nComID < MAX_COMMAND; ++nComID) {
\r
1197 if (Commands[nComID].fCommand == CCommands::C_Eisu) {
\r
1202 m_Data[nAppID].SetCommandID(nType, nKey, nComID);
\r
1205 int CProfile::GetCommandID(const int nAppID, const int nType, const int nKey)
\r
1207 int nComID = m_Data[nAppID].GetCommandID(nType, nKey);
\r
1208 if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_Eisu) {
\r
1209 // Change CommandID C_
\r
1210 for (nComID = 1; nComID < MAX_COMMAND; ++nComID) {
\r
1211 if (Commands[nComID].fCommand == CCommands::C_) {
\r
1219 void CProfile::SetKillRingMax(const int nAppID, const int nKillRingMax)
\r
1221 m_Data[nAppID].SetKillRingMax(nKillRingMax);
\r
1224 int CProfile::GetKillRingMax(const int nAppID)
\r
1226 return m_Data[nAppID].GetKillRingMax();
\r
1229 void CProfile::SetUseDialogSetting(const int nAppID, const BOOL bUseDialogSetting)
\r
1231 m_Data[nAppID].SetUseDialogSetting(bUseDialogSetting);
\r
1234 BOOL CProfile::GetUseDialogSetting(const int nAppID)
\r
1236 return m_Data[nAppID].GetUseDialogSetting();
\r
1239 void CProfile::SetWindowText(const int nAppID, const CString szWindowText)
\r
1241 m_Data[nAppID].SetWindowText(szWindowText);
\r
1244 CString CProfile::GetWindowText(const int nAppID)
\r
1246 return m_Data[nAppID].GetWindowText();
\r
1249 void CProfile::DeleteAllRegistryData()
\r
1252 if (RegOpenKeyEx(HKEY_CURRENT_USER, CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)), 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS) {
\r
1253 // I am sure that I have to do only one time, but...
\r
1254 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
1255 DWORD dwIndex = 0;
\r
1256 TCHAR szName[SUB_KEY_NAME_LENGTH] = {'\0'};
\r
1257 DWORD dwName = sizeof(szName);
\r
1258 FILETIME filetime;
\r
1260 while (RegEnumKeyEx(hkey, dwIndex++, szName, &dwName, NULL, NULL, NULL, &filetime) == ERROR_SUCCESS) {
\r
1261 // RegDeleteKey(hkey, szName);
\r
1262 SHDeleteKey(hkey, szName);
\r
1263 ZeroMemory(szName, sizeof(szName));
\r
1264 dwName = sizeof(szName);
\r
1267 RegCloseKey(hkey);
\r
1271 int CProfile::GetCurrentApplicationID(CComboBox *const cApplicationList, const CString szCurrentApplication)
\r
1273 int nCounter = cApplicationList->GetCount();
\r
1274 CString szListItem;
\r
1275 int nCurSel = cApplicationList->GetCurSel();
\r
1277 for (int i = 0; i < nCounter; ++i) {
\r
1278 cApplicationList->SetCurSel(i);
\r
1279 CProfile::GetApplicationTitle(cApplicationList, szListItem);
\r
1280 if (szListItem.Find(szCurrentApplication) != -1) {
\r
1281 cApplicationList->SetCurSel(nCurSel);
\r
1288 void CProfile::CopyData(const CString szDestinationApplication, const CString szSourceApplication)
\r
1290 int nSettingStyle = SETTING_SPECIFIC;
\r
1291 int nDestinationApplication = GetApplicationIndex(szDestinationApplication, TRUE, &nSettingStyle);
\r
1292 int nSourceApplication = GetApplicationIndex(szSourceApplication);
\r
1294 CString szApplicationName = m_Data[nDestinationApplication].GetApplicationName();
\r
1295 CString szApplicationTitle = m_Data[nDestinationApplication].GetApplicationTitle();
\r
1296 CString szWindowText = m_Data[nDestinationApplication].GetWindowText();
\r
1297 int nWindowTextType = m_Data[nDestinationApplication].GetWindowTextType();
\r
1299 m_Data[nDestinationApplication] = m_Data[nSourceApplication];
\r
1301 m_Data[nDestinationApplication].SetApplicationName(szApplicationName);
\r
1302 m_Data[nDestinationApplication].SetApplicationTitle(szApplicationTitle);
\r
1303 m_Data[nDestinationApplication].SetWindowText(szWindowText);
\r
1304 m_Data[nDestinationApplication].SetWindowTextType(nWindowTextType);
\r
1307 // return application index
\r
1308 // if there is NOT the application in the data, return MAX_APP
\r
1309 int CProfile::GetApplicationIndex(const CString szApplicationName)
\r
1312 for (nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
1313 if (m_Data[nAppID].GetApplicationName() == szApplicationName) {
\r
1320 // Return True if Windows Vista or later.
\r
1321 BOOL CProfile::IsVistaOrLater()
\r
1323 OSVERSIONINFO info = {sizeof(OSVERSIONINFO)};
\r
1324 GetVersionEx(&info);
\r
1326 if (6 <= info.dwMajorVersion) {
\r
1332 void CProfile::RestartComputer()
\r
1334 if (!AdjustTokenPrivileges(SE_SHUTDOWN_NAME)) {
\r
1338 ExitWindowsEx(EWX_REBOOT, 0);
\r
1341 BOOL CProfile::AdjustTokenPrivileges(LPCTSTR lpName)
\r
1346 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
\r
1348 if (LookupPrivilegeValue(NULL, lpName, &luid)) {
\r
1349 TOKEN_PRIVILEGES tp;
\r
1350 tp.PrivilegeCount = 1;
\r
1351 tp.Privileges[0].Luid = luid;
\r
1352 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
\r
1354 if (!::AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
\r
1360 CloseHandle(hToken);
\r
1368 BOOL CProfile::DiableTokenPrivileges()
\r
1373 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
\r
1374 if (!::AdjustTokenPrivileges(hToken, TRUE, NULL, NULL, NULL, NULL)) {
\r
1377 CloseHandle(hToken);
\r
1385 void CProfile::ExportProperties()
\r
1387 if (!AdjustTokenPrivileges(SE_BACKUP_NAME)) {
\r
1391 CFileDialog oFileOpenDialog(FALSE, _T("reg"), _T("xkeymacs"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_REGISTRATION_FILTER)));
\r
1392 if (oFileOpenDialog.DoModal() == IDOK) {
\r
1393 CString szCommandLine;
\r
1394 szCommandLine.Format(_T("regedit /e \"%s\" HKEY_CURRENT_USER\\%s"), oFileOpenDialog.GetPathName(), CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)));
\r
1395 CUtils::Run(szCommandLine, TRUE); // regedit /e "x:\xkeymacs.reg" HKEY_CURRENT_USER\Software\Oishi\XKeymacs2
\r
1398 DiableTokenPrivileges();
\r
1402 void CProfile::ImportProperties()
\r
1404 if (!AdjustTokenPrivileges(SE_RESTORE_NAME)) {
\r
1408 CFileDialog oFileOpenDialog(TRUE, _T("reg"), _T("xkeymacs"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_REGISTRATION_FILTER)));
\r
1409 if (oFileOpenDialog.DoModal() == IDOK) {
\r
1410 CString szCommandLine;
\r
1411 szCommandLine.Format(_T("regedit \"%s\""), oFileOpenDialog.GetPathName());
\r
1412 CUtils::Run(szCommandLine, TRUE); // regedit "x:\xkeymacs.reg"
\r
1415 DiableTokenPrivileges();
\r
1419 BOOL CProfile::GetEnableCUA(const int nAppID)
\r
1421 return m_Data[nAppID].GetEnableCUA();
\r
1424 void CProfile::SetEnableCUA(const int nAppID, const BOOL bEnableCUA)
\r
1426 m_Data[nAppID].SetEnableCUA(bEnableCUA);
\r
1429 int CProfile::GetKeyboardSpeed()
\r
1431 int nKeyboardSpeed = 31; // default value of Windows
\r
1432 CString szSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_KEYBOARD));
\r
1433 CString szValueName(MAKEINTRESOURCE(IDS_KEYBOARD_SPEED));
\r
1436 if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
\r
1438 DWORD dwType = REG_SZ;
\r
1439 BYTE data[4] = {0};
\r
1440 DWORD dwcbData = sizeof(data)/sizeof(data[0]);
\r
1441 RegQueryValueEx(hKey, szValueName, NULL, &dwType, (LPBYTE)&data, &dwcbData);
\r
1442 RegCloseKey(hKey);
\r
1444 for (DWORD i = 0; i < dwcbData; ++i) {
\r
1447 nKeyboardSpeed = nKeyboardSpeed * 10 + data[i] - _T('0');
\r
1449 nKeyboardSpeed = data[i] - _T('0');
\r
1457 return nKeyboardSpeed;
\r