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 CONFIG CProfile::m_Config;
\r
309 TCHAR CProfile::m_szAppTitle[MAX_APP][WINDOW_TEXT_LENGTH];
\r
310 TASK_LIST CProfile::m_TaskList[MAX_TASKS];
\r
311 DWORD CProfile::m_dwTasks;
\r
313 enum { INITIAL_SIZE = 51200 };
\r
314 enum { EXTEND_SIZE = 25600 };
\r
316 void CProfile::Item2AppName(CString *const sz)
\r
318 if (IsTheString(*sz, IDS_DEFAULT_TITLE)) {
\r
319 sz->LoadString(IDS_DEFAULT);
\r
322 if (IsTheString(*sz, IDS_DIALOG_TITLE)) {
\r
323 sz->LoadString(IDS_DIALOG);
\r
326 int nStart, nEnd, nCount;
\r
328 nStart = sz->ReverseFind(_T('(')) + 1;
\r
329 nEnd = sz->Find(_T(')'), nStart) - 1;
\r
330 nCount = (nEnd + 1) - nStart;
\r
331 *sz = sz->Mid(nStart, nCount);
\r
334 int CProfile::IsNotSameString(CComboBox *const pApplication, const CString szListItem)
\r
336 CString szItem, szList;
\r
337 szList = szListItem;
\r
338 Item2AppName(&szList);
\r
340 for (int i = 0; i < pApplication->GetCount(); ++i) {
\r
341 pApplication->GetLBText(i, szItem);
\r
342 Item2AppName(&szItem);
\r
343 if (!_tcsicmp(szItem, szList)) {
\r
351 // This function returns the nth string in a window name separated by " - ".
\r
352 // If there aren't a sufficient number of strings, it returns the last string
\r
353 // appropriate for the title.
\r
354 bool CProfile::GetAppTitle(CString& appTitle, const CString& windowName, int nth)
\r
356 const CString sep(MAKEINTRESOURCE(IDS_SEPARATE_WINDOWTITLE));
\r
357 const int nSep = windowName.Find(sep);
\r
359 appTitle = windowName;
\r
362 if (GetAppTitle(appTitle, windowName.Right(windowName.GetLength() - nSep - sep.GetLength()), --nth) ||
\r
363 !nth || nth > 0 && appTitle.GetAt(0) != _T('[') && appTitle.FindOneOf(_T(".]")) == -1)
\r
365 appTitle = windowName.Left(nSep);
\r
369 BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
\r
371 CComboBox *pApplication = (CComboBox*)lParam;
\r
372 PTASK_LIST pTask = CProfile::m_TaskList;
\r
374 TCHAR szWindowName[WINDOW_TEXT_LENGTH];
\r
375 TCHAR szClassName[CLASS_NAME_LENGTH];
\r
376 WINDOWPLACEMENT wpl;
\r
378 wpl.length = sizeof(WINDOWPLACEMENT);
\r
379 ::GetWindowText(hWnd, szWindowName, sizeof(szWindowName));
\r
380 GetClassName(hWnd, szClassName, sizeof(szClassName));
\r
383 // Get Process Name
\r
384 DWORD dwProcessId = 0;
\r
385 GetWindowThreadProcessId(hWnd, &dwProcessId);
\r
387 for (i = 0; i < CProfile::m_dwTasks; ++i) {
\r
388 if (pTask[i].dwProcessId == dwProcessId) {
\r
390 // Get Application Name
\r
391 if (szWindowName[0] == '\0') {
\r
394 if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_B2)), sizeof(pTask[i].ProcessName))) {
\r
395 appTitle.LoadString(IDS_BECKY);
\r
396 } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_EXPLORER)), sizeof(pTask[i].ProcessName))) {
\r
397 appTitle.LoadString(IDS_PROGRAM_MANAGER);
\r
398 } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_MSIMN)), sizeof(pTask[i].ProcessName))) {
\r
399 appTitle.LoadString(IDS_OUTLOOK_EXPRESS);
\r
400 } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_PROJECT)), sizeof(pTask[i].ProcessName))
\r
401 || !_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_EXCEL)), sizeof(pTask[i].ProcessName))
\r
402 || !_tcsnicmp(pTask[i].ProcessName, _T("psp.exe"), sizeof(pTask[i].ProcessName))) {
\r
403 GetAppTitle(appTitle, szWindowName, 1);
\r
404 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("sakura.exe"), sizeof(pTask[i].ProcessName))) {
\r
405 GetAppTitle(appTitle, szWindowName, 2); // '.' is included, so...
\r
406 } else if (!_tcsnicmp(pTask[i].ProcessName, CString(MAKEINTRESOURCE(IDS_MSDN)), sizeof(pTask[i].ProcessName))) {
\r
407 appTitle = szWindowName;
\r
408 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("devenv.exe"), sizeof(pTask[i].ProcessName))) {
\r
409 appTitle.Format(_T("Microsoft Visual Studio .NET"));
\r
410 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vb6.exe"), sizeof(pTask[i].ProcessName))) {
\r
411 appTitle.Format(_T("Microsoft Visual Basic"));
\r
412 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("ssexp.exe"), sizeof(pTask[i].ProcessName))) {
\r
413 appTitle.LoadString(IDS_VISUAL_SOURCESAFE_EXPLORER);
\r
414 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("sh.exe"), sizeof(pTask[i].ProcessName))) {
\r
415 appTitle.Format(_T("MKS Korn Shell"));
\r
416 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("csh.exe"), sizeof(pTask[i].ProcessName))) {
\r
417 appTitle.Format(_T("C Shell"));
\r
418 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vim.exe"), sizeof(pTask[i].ProcessName))) {
\r
419 appTitle.Format(_T("VIM"));
\r
421 CUtils::SetCorrectApplicationName(pTask[i].ProcessName, szWindowName);
\r
422 GetAppTitle(appTitle, szWindowName);
\r
429 if ((IsWindowVisible(hWnd)) // Is visible?
\r
430 && (GetWindow(hWnd, GW_OWNER) == NULL) // Is top level window?
\r
431 && (lstrlen(szWindowName) > 0) // Have caption?
\r
432 && (pApplication->FindString(-1, szClassName) == CB_ERR)) {// Is not same string?
\r
433 CString szListItem;
\r
434 szListItem.Format(IDS_APPLICATION_LIST_ITEM, appTitle, pTask[i].ProcessName);
\r
435 if (IsNotSameString(pApplication, szListItem)) {
\r
436 pApplication->AddString(szListItem);
\r
442 void CProfile::LoadRegistry()
\r
444 bool bDialog = false;
\r
445 const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));
\r
446 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
448 entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
449 CString appName = AfxGetApp()->GetProfileString(section, entry);
\r
450 if (appName.IsEmpty()) {
\r
454 appName.LoadString(IDS_DIALOG);
\r
457 appName.LoadString(IDS_DEFAULT);
\r
458 } else if (appName == CString(MAKEINTRESOURCE(IDS_DIALOG)))
\r
460 _tcsncpy_s(m_Config.szSpecialApp[nAppID], appName, _TRUNCATE);
\r
461 entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);
\r
462 _tcsncpy_s(m_szAppTitle[nAppID], AfxGetApp()->GetProfileString(appName, entry), _TRUNCATE);
\r
463 entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);
\r
464 _tcsncpy_s(m_Config.szWindowText[nAppID], AfxGetApp()->GetProfileString(appName, entry, _T("*")), _TRUNCATE);
\r
466 const CString regApp = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName;
\r
467 for (int nComID = 1; nComID < MAX_COMMAND; ++nComID) {
\r
468 entry = CCommands::GetCommandName(nComID);
\r
470 const CString regKey = regApp + _T("\\") + entry;
\r
471 if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
\r
472 TCHAR szKeyBind[128];
\r
473 DWORD dwKeyBind = _countof(szKeyBind);
\r
474 for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {
\r
476 ReadKeyBind(nType, nKey, szKeyBind);
\r
477 m_Config.nCommandID[nAppID][nType][nKey] = nComID;
\r
478 dwKeyBind = _countof(szKeyBind);
\r
482 // Set the default assignment
\r
483 for (int i = 0; const int nKey = CCommands::GetDefaultCommandKey(nComID, i); ++i) {
\r
484 if (CCommands::GetDefaultControlID(nComID, i) == IDC_CO2)
\r
486 const int nType = CCommands::GetDefaultCommandType(nComID, i);
\r
487 m_Config.nCommandID[nAppID][nType][nKey] = nComID;
\r
491 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {
\r
493 const CString regKey = regApp + _T("\\") + CDotXkeymacs::GetFunctionSymbol(nFuncID);
\r
494 if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
\r
495 CDotXkeymacs::ClearKey(nFuncID, nAppID);
\r
496 TCHAR szKeyBind[128];
\r
497 DWORD dwKeyBind = _countof(szKeyBind);
\r
498 for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {
\r
500 ReadKeyBind(nType, nKey, szKeyBind);
\r
501 CDotXkeymacs::SetKey(nFuncID, nAppID, nType, nKey);
\r
502 dwKeyBind = _countof(szKeyBind);
\r
508 entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);
\r
509 m_Config.nKillRingMax[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 1);
\r
510 entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);
\r
511 m_Config.bUseDialogSetting[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 1);
\r
512 entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);
\r
513 m_Config.nSettingStyle[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0) ? SETTING_DISABLE : SETTING_SPECIFIC;
\r
514 entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);
\r
515 m_Config.bIgnoreUndefinedMetaCtrl[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0);
\r
516 entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);
\r
517 m_Config.bIgnoreUndefinedC_x[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0);
\r
518 entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);
\r
519 m_Config.bEnableCUA[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0);
\r
520 entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);
\r
521 m_Config.b326Compatible[nAppID] = AfxGetApp()->GetProfileInt(appName, entry, 0);
\r
525 void CProfile::SaveRegistry()
\r
527 const CString section(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION));
\r
528 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
529 const LPCTSTR szAppName = m_Config.szSpecialApp[nAppID];
\r
531 entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
532 if (!szAppName[0]) {
\r
533 if (!AfxGetApp()->GetProfileString(section, entry).IsEmpty())
\r
534 AfxGetApp()->WriteProfileString(section, entry, _T(""));
\r
537 AfxGetApp()->WriteProfileString(section, entry, szAppName);
\r
539 entry.LoadString(IDS_REG_ENTRY_APPLICATOIN_TITLE);
\r
540 CString appTitle = m_szAppTitle[nAppID];
\r
541 appTitle.TrimLeft(_T(' '));
\r
542 AfxGetApp()->WriteProfileString(szAppName, entry, appTitle);
\r
543 entry.LoadString(IDS_REG_ENTRY_WINDOW_TEXT);
\r
544 AfxGetApp()->WriteProfileString(szAppName, entry, m_Config.szWindowText[nAppID]);
\r
546 const CString regApp = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + szAppName;
\r
547 // Create all commands
\r
548 for (int nComID = 1; nComID < MAX_COMMAND; ++nComID)
\r
549 SaveCommand(szAppName, nComID);
\r
550 for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType)
\r
551 for (int nKey = 0; nKey < MAX_KEY; ++nKey)
\r
552 SaveKeyBind(szAppName, m_Config.nCommandID[nAppID][nType][nKey], nType, nKey);
\r
553 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)
\r
554 for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {
\r
556 CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);
\r
557 SaveKeyBind(szAppName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);
\r
560 entry.LoadString(IDS_REG_ENTRY_KILL_RING_MAX);
\r
561 AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.nKillRingMax[nAppID]);
\r
562 entry.LoadString(IDS_REG_ENTRY_USE_DIALOG_SETTING);
\r
563 AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bUseDialogSetting[nAppID]);
\r
564 entry.LoadString(IDS_REG_ENTRY_DISABLE_XKEYMACS);
\r
565 AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.nSettingStyle[nAppID] == SETTING_DISABLE);
\r
566 entry.LoadString(IDC_REG_ENTRY_IGNORE_META_CTRL);
\r
567 AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bIgnoreUndefinedMetaCtrl[nAppID]);
\r
568 entry.LoadString(IDC_REG_ENTRY_IGNORE_C_X);
\r
569 AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bIgnoreUndefinedC_x[nAppID]);
\r
570 entry.LoadString(IDC_REG_ENTRY_ENABLE_CUA);
\r
571 AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.bEnableCUA[nAppID]);
\r
572 entry.LoadString(IDS_REG_ENTRY_326_COMPATIBLE);
\r
573 AfxGetApp()->WriteProfileInt(szAppName, entry, m_Config.b326Compatible[nAppID]);
\r
577 void CProfile::LoadData()
\r
579 CDotXkeymacs::Load();
\r
584 void CProfile::SaveData()
\r
586 DeleteAllRegistryData();
\r
591 void CProfile::SetDllData()
\r
593 memset(m_Config.nFunctionID, -1, sizeof(m_Config.nFunctionID));
\r
594 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)
\r
595 _tcscpy_s(m_Config.szFunctionDefinition[nFuncID], CDotXkeymacs::GetFunctionDefinition(nFuncID));
\r
597 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
598 m_Config.nCommandID[nAppID][CONTROL]['X'] = 0; // C-x is unassigned.
\r
599 for (int nType = 0; nType < MAX_COMMAND_TYPE; ++nType)
\r
600 for (int nKey = 0; nKey < MAX_KEY; ++nKey)
\r
601 if ((nType & CONTROLX) && m_Config.nCommandID[nAppID][nType][nKey])
\r
602 m_Config.nCommandID[nAppID][CONTROL]['X'] = 1; // C-x is available.
\r
603 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID)
\r
604 for (int nKeyID = 0; nKeyID < CDotXkeymacs::GetKeyNumber(nFuncID, nAppID); ++nKeyID) {
\r
606 CDotXkeymacs::GetKey(nFuncID, nAppID, nKeyID, &nType, &nKey);
\r
607 m_Config.nFunctionID[nAppID][nType][nKey] = nFuncID;
\r
608 if (nType & CONTROLX)
\r
609 m_Config.nCommandID[nAppID][CONTROL]['X'] = 1; // C-x is available.
\r
612 m_Config.b106Keyboard = Is106Keyboard();
\r
613 CXkeymacsDll::SetConfig(m_Config);
\r
614 CXkeymacsApp *pApp = static_cast<CXkeymacsApp *>(AfxGetApp());
\r
615 if (!pApp->IsWow64())
\r
617 if (!CXkeymacsDll::SaveConfig())
\r
619 pApp->SendIPCMessage(XKEYMACS_RELOAD);
\r
622 void CProfile::ReadKeyBind(int& nCommandType, int& nKey, const LPCTSTR szKeyBind)
\r
624 nCommandType = KeyBind2CommandType(szKeyBind);
\r
625 nKey = KeyBind2Key(szKeyBind + _tcslen(CommandType2String(nCommandType)));
\r
628 CString CProfile::WriteKeyBind(const int nType, const int nKey)
\r
631 szKeyBind.Format(_T("%s%s"), CommandType2String(nType), Key2String(nKey));
\r
635 int CProfile::KeyBind2CommandType(LPCTSTR szKeyBind)
\r
637 for (int nType = MAX_COMMAND_TYPE - 1; nType; --nType) {
\r
638 if (IsCommandType(nType, szKeyBind)) {
\r
645 int CProfile::KeyBind2Key(LPCTSTR szKey)
\r
647 for (int nKey = 1; nKey <= 0xff; ++nKey) {
\r
648 if (!_tcscmp(szKey, Key2String(nKey))) {
\r
655 LPCTSTR CProfile::CommandType2String(int nType)
\r
657 if (nType < 0 || sizeof(CommandTypes) / sizeof(CommandTypes[0]) <= nType) {
\r
661 return CommandTypes[nType].szName;
\r
664 LPCTSTR CProfile::Key2String(int nKey)
\r
666 if (CProfile::Is106Keyboard()) {
\r
681 if (nKey < 0 || sizeof(KeyNames) / sizeof(KeyNames[0]) <= nKey) {
\r
685 return KeyNames[nKey].name;
\r
688 BOOL CProfile::IsCommandType(const int nType, LPCTSTR szKeyBind)
\r
690 LPCTSTR szCommandType = CommandType2String(nType);
\r
692 if (!_tcsnicmp(szKeyBind, szCommandType, _tcslen(szCommandType))) {
\r
699 void CProfile::SaveKeyBind(const LPCSTR szAppName, const int nComID, const int nType, const int nKey)
\r
703 const LPCSTR szComName = CCommands::GetCommandName(nComID);
\r
706 SaveKeyBind(szAppName, szComName, nType, nKey);
\r
709 void CProfile::SaveKeyBind(const LPCSTR szAppName, const LPCSTR szComName, const int nType, const int nKey)
\r
711 const CString szKeyBind = WriteKeyBind(nType, nKey);
\r
712 CString szSubKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + szAppName + _T("\\") + szComName;
\r
713 if (!szKeyBind.IsEmpty())
\r
714 szSubKey += _T("\\") + szKeyBind;
\r
716 if (RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS)
\r
720 void CProfile::SaveCommand(const LPCSTR szAppName, const int nComID)
\r
722 SaveKeyBind(szAppName, nComID, 0, 0);
\r
725 void CProfile::AddKeyBind2C_(const LPCSTR szAppName, const BYTE bVk)
\r
728 for (nComID = 0; nComID < MAX_COMMAND; ++nComID)
\r
729 if (Commands[nComID].fCommand == CCommands::C_)
\r
731 SaveKeyBind(szAppName, nComID, NONE, bVk);
\r
734 void CProfile::LevelUp()
\r
736 const int nCurrentLevel = AfxGetApp()->GetProfileInt(_T(""), _T("Level"), 0);
\r
737 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
739 entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
\r
740 const CString appName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), entry);
\r
741 if (appName.IsEmpty())
\r
743 switch (nCurrentLevel) {
\r
745 AddKeyBind2C_(appName, VK_LCONTROL);
\r
746 AddKeyBind2C_(appName, VK_RCONTROL);
\r
749 // Set kill-ring-max 1 if it is 0.
\r
750 if (!AfxGetApp()->GetProfileInt(appName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 0))
\r
751 AfxGetApp()->WriteProfileInt(appName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 1);
\r
755 // Chaged a label from Enter to newline.
\r
756 const CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName;
\r
757 const CString srcKey = subKey + _T("\\") + _T("Enter");
\r
758 const CString dstKey = subKey + _T("\\") + _T("newline");
\r
759 HKEY hDstKey = NULL;
\r
760 if (RegCreateKeyEx(HKEY_CURRENT_USER, dstKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hDstKey, NULL) == ERROR_SUCCESS) {
\r
761 SHCopyKey(HKEY_CURRENT_USER, srcKey, hDstKey, NULL);
\r
762 SHDeleteKey(HKEY_CURRENT_USER, srcKey);
\r
763 RegCloseKey(hDstKey);
\r
768 // rename original function to remove IDS_REG_ORIGINAL_PREFIX
\r
769 for (int nFuncID = 0; nFuncID < CDotXkeymacs::GetFunctionNumber(); ++nFuncID) {
\r
771 const CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName + _T("\\") + CString(MAKEINTRESOURCE(IDS_REG_ORIGINAL_PREFIX)) + CDotXkeymacs::GetFunctionSymbol(nFuncID);
\r
772 if (RegOpenKeyEx(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
\r
773 // Use registry data
\r
774 TCHAR szKeyBind[128];
\r
775 DWORD dwKeyBind = sizeof(szKeyBind);
\r
776 for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {
\r
778 ReadKeyBind(nType, nKey, szKeyBind);
\r
779 SaveKeyBind(appName, CDotXkeymacs::GetFunctionSymbol(nFuncID), nType, nKey);
\r
780 dwKeyBind = sizeof(szKeyBind);
\r
787 AfxGetApp()->WriteProfileInt(_T(""), _T("Level"), 4);
\r
790 void CProfile::InitDllData()
\r
796 void CProfile::ClearData(const CString szCurrentApplication)
\r
798 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID)
\r
799 if (szCurrentApplication == m_Config.szSpecialApp[nAppID]) {
\r
800 ZeroMemory(m_Config.nCommandID[nAppID], sizeof(m_Config.nCommandID[nAppID]));
\r
801 ZeroMemory(m_Config.szSpecialApp[nAppID], CLASS_NAME_LENGTH);
\r
806 // return count of saved settings
\r
807 int CProfile::GetSavedSettingCount()
\r
809 int nSavedSetting = 0;
\r
810 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID)
\r
811 if (m_Config.szSpecialApp[nAppID][0])
\r
813 return nSavedSetting;
\r
816 void CProfile::InitApplicationList(CComboBox *const cApplicationList)
\r
818 cApplicationList->ResetContent();
\r
822 EnumWindows(EnumWindowsProc, (LPARAM)cApplicationList);
\r
824 CString szListItem;
\r
825 for (int i = 0; i < MAX_APP; ++i) {
\r
826 const LPCTSTR szAppName = m_Config.szSpecialApp[i];
\r
827 const LPCTSTR szAppTitle = m_szAppTitle[i];
\r
828 if (!szAppName[0] || !_tcscmp(szAppName, _T("IME")))
\r
830 szListItem.Format(IDS_APPLICATION_LIST_ITEM, szAppTitle, szAppName);
\r
831 if (IsNotSameString(cApplicationList, szListItem) &&
\r
832 !IsDefault(szAppName) && !IsDialog(szAppName))
\r
833 cApplicationList->AddString(szListItem);
\r
836 AddIMEInfo(cApplicationList);
\r
839 cApplicationList->InsertString(0, CString(MAKEINTRESOURCE(IDS_DIALOG_TITLE)));
\r
842 cApplicationList->InsertString( 0, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));
\r
843 cApplicationList->SelectString(-1, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));
\r
846 void CProfile::AddIMEInfo(CComboBox *cApplicationList)
\r
848 const UINT n = GetKeyboardLayoutList(0, NULL);
\r
851 std::vector<HKL> hkls(n);
\r
852 GetKeyboardLayoutList(n, &hkls[0]);
\r
853 TCHAR szFileName[MAX_PATH];
\r
854 TCHAR szDescription[WINDOW_TEXT_LENGTH];
\r
855 for (std::vector<HKL>::const_iterator p = hkls.begin(); p != hkls.end(); ++p)
\r
856 if (ImmGetDescription(*p, szDescription, WINDOW_TEXT_LENGTH) &&
\r
857 ImmGetIMEFileName(*p, szFileName, MAX_PATH)) {
\r
859 item.Format(IDS_APPLICATION_LIST_ITEM, szDescription, szFileName);
\r
860 if (IsNotSameString(cApplicationList, item))
\r
861 cApplicationList->AddString(item);
\r
865 void CProfile::GetTaskList()
\r
867 ZeroMemory(m_TaskList, sizeof(m_TaskList));
\r
869 HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
\r
870 if (hProcessSnap == (HANDLE)-1)
\r
874 PROCESSENTRY32 processEntry32 = {sizeof(PROCESSENTRY32)};
\r
875 if (Process32First(hProcessSnap, &processEntry32)) {
\r
877 lstrcpy(m_TaskList[m_dwTasks].ProcessName, processEntry32.szExeFile);
\r
878 m_TaskList[m_dwTasks++].dwProcessId = processEntry32.th32ProcessID;
\r
879 } while (m_dwTasks < MAX_TASKS && Process32Next(hProcessSnap, &processEntry32));
\r
882 CloseHandle(hProcessSnap);
\r
885 int CProfile::DefaultAppID()
\r
887 const CString name(MAKEINTRESOURCE(IDS_DEFAULT));
\r
888 for(int nAppID = 0; nAppID < MAX_APP; ++nAppID)
\r
889 if (name == m_Config.szSpecialApp[nAppID])
\r
894 int CProfile::AssignAppID(const LPCSTR szAppName)
\r
896 int nAppID = GetAppID(szAppName);
\r
897 if (nAppID != MAX_APP)
\r
899 for (nAppID = 0; nAppID < MAX_APP; ++nAppID)
\r
900 if (!m_Config.szSpecialApp[nAppID][0]) {
\r
901 _tcsncpy_s(m_Config.szSpecialApp[nAppID], szAppName, _TRUNCATE);
\r
907 int CProfile::GetSettingStyle(const int nAppID)
\r
909 if (nAppID == MAX_APP)
\r
910 return SETTING_DEFAULT;
\r
911 return m_Config.nSettingStyle[nAppID];
\r
914 void CProfile::SetSettingStyle(int nAppID, int nSettingStyle)
\r
916 if (nAppID == MAX_APP)
\r
918 m_Config.nSettingStyle[nAppID] = nSettingStyle;
\r
921 BOOL CProfile::Is106Keyboard()
\r
923 static KEYBOARD_TYPE keyboard = UNKNOWN_KEYBOARD;
\r
925 if (keyboard == UNKNOWN_KEYBOARD) {
\r
926 OSVERSIONINFO verInfo = {0};
\r
927 verInfo.dwOSVersionInfoSize = sizeof (verInfo);
\r
928 GetVersionEx(&verInfo);
\r
931 DWORD cbData = sizeof(subtype);
\r
933 if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
\r
935 CString szSubKey(_T("SYSTEM\\CurrentControlSet\\Services\\i8042prt\\Parameters"));
\r
936 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
\r
937 static const CString szValueName(_T("OverrideKeyboardSubtype"));
\r
938 if (RegQueryValueEx(hKey, szValueName, NULL, NULL, (LPBYTE)&subtype, &cbData) != ERROR_SUCCESS) {
\r
943 } else if (verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
\r
944 subtype = GetPrivateProfileInt(_T("keyboard"), _T("subtype"), 0, _T("system.ini"));
\r
947 keyboard = (subtype & 0x02) ? JAPANESE_KEYBOARD : ENGLISH_KEYBOARD;
\r
950 return keyboard == JAPANESE_KEYBOARD;
\r
953 BOOL CProfile::IsTheString(const CString sz, const UINT nID)
\r
955 return sz == CString(MAKEINTRESOURCE(nID));
\r
958 // if sz is "Default", return TRUE
\r
959 BOOL CProfile::IsDefault(const CString sz)
\r
961 return IsTheString(sz, IDS_DEFAULT);
\r
964 // if sz is "Dialog", return TRUE
\r
965 BOOL CProfile::IsDialog(const CString sz)
\r
967 return IsTheString(sz, IDS_DIALOG);
\r
970 void CProfile::GetApplicationTitle(CComboBox *const cApplicationList, CString &rList, const int nIndex)
\r
973 cApplicationList->GetLBText(nIndex, rList);
\r
975 cApplicationList->GetWindowText(rList);
\r
978 if (IsTheString(rList, IDS_DEFAULT_TITLE)) {
\r
979 rList.LoadString(IDS_DEFAULT);
\r
982 if (IsTheString(rList, IDS_DIALOG_TITLE)) {
\r
983 rList.LoadString(IDS_DIALOG);
\r
989 void CProfile::UpdateApplicationTitle(CComboBox *const cApplicationList, const CString szCurrentApplication, const int nAppID, const BOOL bSaveAndValidate)
\r
991 static CString szApplicationTitle;
\r
992 if (bSaveAndValidate) { // GetDialogData
\r
993 if (!CProfile::IsDefault(szCurrentApplication))
\r
994 _tcsncpy_s(m_szAppTitle[nAppID], szApplicationTitle, _TRUNCATE);
\r
995 szApplicationTitle.Empty();
\r
996 } else { // SetDialogData
\r
997 CString szListItem;
\r
998 CProfile::GetApplicationTitle(cApplicationList, szListItem);
\r
999 const int nEndTitle = szListItem.ReverseFind(_T('('));
\r
1000 if (nEndTitle > 0)
\r
1001 szApplicationTitle = szListItem.Left(nEndTitle);
\r
1005 void CProfile::SetCommandID(const int nAppID, const int nType, const int nKey, int nComID)
\r
1007 if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_)
\r
1008 // Change CommandID C_Eisu
\r
1009 for (nComID = 1; nComID < MAX_COMMAND; ++nComID)
\r
1010 if (Commands[nComID].fCommand == CCommands::C_Eisu)
\r
1012 m_Config.nCommandID[nAppID][nType][nKey] = nComID;
\r
1015 int CProfile::GetCommandID(const int nAppID, const int nType, const int nKey)
\r
1017 int nComID = m_Config.nCommandID[nAppID][nType][nKey];
\r
1018 if (nKey == 0xf0 && Commands[nComID].fCommand == CCommands::C_Eisu)
\r
1019 // Change CommandID C_
\r
1020 for (nComID = 1; nComID < MAX_COMMAND; nComID++)
\r
1021 if (Commands[nComID].fCommand == CCommands::C_)
\r
1026 void CProfile::SetKillRingMax(const int nAppID, const int nKillRingMax)
\r
1028 m_Config.nKillRingMax[nAppID] = nKillRingMax;
\r
1031 int CProfile::GetKillRingMax(const int nAppID)
\r
1033 return m_Config.nKillRingMax[nAppID];
\r
1036 void CProfile::SetUseDialogSetting(const int nAppID, const BOOL bUseDialogSetting)
\r
1038 m_Config.bUseDialogSetting[nAppID] = bUseDialogSetting;
\r
1041 BOOL CProfile::GetUseDialogSetting(const int nAppID)
\r
1043 return m_Config.bUseDialogSetting[nAppID];
\r
1046 void CProfile::SetWindowText(const int nAppID, const CString szWindowText)
\r
1048 if (CUtils::GetWindowTextType(szWindowText) == IDS_WINDOW_TEXT_IGNORE)
\r
1049 _tcscpy_s(m_Config.szWindowText[nAppID], _T("*"));
\r
1051 _tcsncpy_s(m_Config.szWindowText[nAppID], szWindowText, _TRUNCATE);
\r
1054 CString CProfile::GetWindowText(const int nAppID)
\r
1056 return m_Config.szWindowText[nAppID];
\r
1059 void CProfile::DeleteAllRegistryData()
\r
1062 if (RegOpenKeyEx(HKEY_CURRENT_USER, CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)), 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS) {
\r
1063 // I am sure that I have to do only one time, but...
\r
1064 for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
\r
1065 DWORD dwIndex = 0;
\r
1066 TCHAR szName[SUB_KEY_NAME_LENGTH] = {'\0'};
\r
1067 DWORD dwName = sizeof(szName);
\r
1068 FILETIME filetime;
\r
1070 while (RegEnumKeyEx(hkey, dwIndex++, szName, &dwName, NULL, NULL, NULL, &filetime) == ERROR_SUCCESS) {
\r
1071 // RegDeleteKey(hkey, szName);
\r
1072 SHDeleteKey(hkey, szName);
\r
1073 ZeroMemory(szName, sizeof(szName));
\r
1074 dwName = sizeof(szName);
\r
1077 RegCloseKey(hkey);
\r
1081 int CProfile::GetCurrentApplicationID(CComboBox *const cApplicationList, const CString szCurrentApplication)
\r
1083 int nCounter = cApplicationList->GetCount();
\r
1084 CString szListItem;
\r
1085 int nCurSel = cApplicationList->GetCurSel();
\r
1087 for (int i = 0; i < nCounter; ++i) {
\r
1088 cApplicationList->SetCurSel(i);
\r
1089 CProfile::GetApplicationTitle(cApplicationList, szListItem);
\r
1090 if (szListItem.Find(szCurrentApplication) != -1) {
\r
1091 cApplicationList->SetCurSel(nCurSel);
\r
1098 void CProfile::CopyData(const CString szDstApp, const CString szSrcApp)
\r
1100 const int nDstApp = AssignAppID(szDstApp);
\r
1101 const int nSrcApp = GetAppID(szSrcApp);
\r
1102 if (nDstApp == MAX_APP || nSrcApp == MAX_APP)
\r
1104 SetSettingStyle(nDstApp, SETTING_SPECIFIC);
\r
1106 #define CopyMember(member) CopyMemory(&m_Config. ## member ## [nDstApp], &m_Config. ## member ## [nSrcApp], sizeof(m_Config. ## member ## [nSrcApp]))
\r
1107 CopyMember(b326Compatible);
\r
1108 CopyMember(nFunctionID);
\r
1109 CopyMember(bEnableCUA);
\r
1110 CopyMember(bUseDialogSetting);
\r
1111 CopyMember(bIgnoreUndefinedC_x);
\r
1112 CopyMember(bIgnoreUndefinedMetaCtrl);
\r
1113 CopyMember(nKillRingMax);
\r
1114 CopyMember(nCommandID);
\r
1118 // return application index
\r
1119 // if there is NOT the application in the data, return MAX_APP
\r
1120 int CProfile::GetAppID(const LPCSTR szAppName)
\r
1123 for (nAppID = 0; nAppID < MAX_APP; ++nAppID)
\r
1124 if (!_tcscmp(szAppName, m_Config.szSpecialApp[nAppID]))
\r
1129 // Return True if Windows Vista or later.
\r
1130 BOOL CProfile::IsVistaOrLater()
\r
1132 OSVERSIONINFO info = {sizeof(OSVERSIONINFO)};
\r
1133 GetVersionEx(&info);
\r
1135 if (6 <= info.dwMajorVersion) {
\r
1141 void CProfile::RestartComputer()
\r
1143 if (!AdjustTokenPrivileges(SE_SHUTDOWN_NAME)) {
\r
1147 ExitWindowsEx(EWX_REBOOT, 0);
\r
1150 BOOL CProfile::AdjustTokenPrivileges(LPCTSTR lpName)
\r
1155 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
\r
1157 if (LookupPrivilegeValue(NULL, lpName, &luid)) {
\r
1158 TOKEN_PRIVILEGES tp;
\r
1159 tp.PrivilegeCount = 1;
\r
1160 tp.Privileges[0].Luid = luid;
\r
1161 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
\r
1163 if (!::AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
\r
1169 CloseHandle(hToken);
\r
1177 BOOL CProfile::DiableTokenPrivileges()
\r
1182 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
\r
1183 if (!::AdjustTokenPrivileges(hToken, TRUE, NULL, NULL, NULL, NULL)) {
\r
1186 CloseHandle(hToken);
\r
1194 void CProfile::ExportProperties()
\r
1196 if (!AdjustTokenPrivileges(SE_BACKUP_NAME)) {
\r
1200 CFileDialog oFileOpenDialog(FALSE, _T("reg"), _T("xkeymacs"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_REGISTRATION_FILTER)));
\r
1201 if (oFileOpenDialog.DoModal() == IDOK) {
\r
1202 CString szCommandLine;
\r
1203 szCommandLine.Format(_T("regedit /e \"%s\" HKEY_CURRENT_USER\\%s"), oFileOpenDialog.GetPathName(), CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)));
\r
1204 CUtils::Run(szCommandLine, TRUE); // regedit /e "x:\xkeymacs.reg" HKEY_CURRENT_USER\Software\Oishi\XKeymacs2
\r
1207 DiableTokenPrivileges();
\r
1211 void CProfile::ImportProperties()
\r
1213 if (!AdjustTokenPrivileges(SE_RESTORE_NAME)) {
\r
1217 CFileDialog oFileOpenDialog(TRUE, _T("reg"), _T("xkeymacs"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_REGISTRATION_FILTER)));
\r
1218 if (oFileOpenDialog.DoModal() == IDOK) {
\r
1219 CString szCommandLine;
\r
1220 szCommandLine.Format(_T("regedit \"%s\""), oFileOpenDialog.GetPathName());
\r
1221 CUtils::Run(szCommandLine, TRUE); // regedit "x:\xkeymacs.reg"
\r
1224 DiableTokenPrivileges();
\r
1228 BOOL CProfile::GetEnableCUA(const int nAppID)
\r
1230 return m_Config.bEnableCUA[nAppID];
\r
1233 void CProfile::SetEnableCUA(const int nAppID, const BOOL bEnableCUA)
\r
1235 m_Config.bEnableCUA[nAppID] = bEnableCUA;
\r
1238 int CProfile::GetKeyboardSpeed()
\r
1240 int nKeyboardSpeed = 31; // default value of Windows
\r
1241 CString szSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_KEYBOARD));
\r
1242 CString szValueName(MAKEINTRESOURCE(IDS_KEYBOARD_SPEED));
\r
1245 if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
\r
1247 DWORD dwType = REG_SZ;
\r
1248 BYTE data[4] = {0};
\r
1249 DWORD dwcbData = sizeof(data)/sizeof(data[0]);
\r
1250 RegQueryValueEx(hKey, szValueName, NULL, &dwType, (LPBYTE)&data, &dwcbData);
\r
1251 RegCloseKey(hKey);
\r
1253 for (DWORD i = 0; i < dwcbData; ++i) {
\r
1256 nKeyboardSpeed = nKeyboardSpeed * 10 + data[i] - _T('0');
\r
1258 nKeyboardSpeed = data[i] - _T('0');
\r
1266 return nKeyboardSpeed;
\r