1 // Utils.cpp: implementation of the CUtils class
\r
3 //////////////////////////////////////////////////////////////////////
\r
7 #include "../xkeymacs/resource.h"
\r
9 #pragma data_seg(".xkmcs")
\r
10 TCHAR CUtils::m_szApplicationName[MAX_PATH] = {'\0'};
\r
11 TCHAR CUtils::m_szIMEName[MAX_PATH] = _T("IME"); // IDS_IME_FILE_NAME
\r
14 BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)
\r
17 TCHAR buf[WINDOW_TEXT_LENGTH] = {'\0'};
\r
18 GetWindowText(GetForegroundWindow(), buf, sizeof(buf));
\r
19 // CUtils::Log(_T("Window Text --%s--"), buf);
\r
20 szDialogTitle->Format(_T("%s"), buf);
\r
23 if (!szDialogTitle->Compare(_T("
\8c\9f\8dõ")) // notepad, wordpad, IE, regedit,
\r
24 // Excel, Front Page, PowerPoint, Acrobat Reader, IBM HPB
\r
25 || !szDialogTitle->Compare(_T("Find")) // notepad, Outlook, Outlook Express, Opera
\r
26 || !szDialogTitle->Compare(_T("Find in this Page")) // Mozilla
\r
27 || !szDialogTitle->Compare(_T("Find/Replace")) // Eclipse
\r
28 || !szDialogTitle->Compare(_T("
\96{
\95¶
\93à
\8c\9f\8dõ")) // Becky!
\r
29 || !szDialogTitle->Compare(_T("
\83\81\81[
\83\8b\8c\9f\8dõ")) // Becky!
\r
30 || !szDialogTitle->Compare(_T("
\95¶
\8e\9a\97ñ
\82Ì
\8c\9f\8dõ")) // M$ VC++
\r
31 || !szDialogTitle->Compare(_T("
\8c\9f\8dõ
\82Æ
\92u
\8a·")) // M$ Word, 123
\r
32 || !szDialogTitle->Compare(_T("
\95¶
\8f\91\82Ì
\83e
\83L
\83X
\83g
\82Ì
\8c\9f\8dõ")) // Lotus Notes
\r
33 || !szDialogTitle->Compare(_T("
\82±
\82Ì
\83y
\81[
\83W
\82ð
\8c\9f\8dõ")) // Netscape 6
\r
34 || !szDialogTitle->Compare(_T("
\95¶
\8e\9a\97ñ
\8c\9f\8dõ")) // Dana
\r
35 || !szDialogTitle->Compare(_T("
\8c\9f\8dõ/
\92u
\8a·")) // PHP Editor
\r
36 || !szDialogTitle->Compare(_T("
\92u
\8a·"))
\r
37 || !szDialogTitle->Compare(_T("Replace"))) {
\r
41 szDialogTitle->Empty();
\r
45 BOOL CUtils::IsFindDialog()
\r
47 CString szDialogTitle;
\r
48 return GetFindDialogTitle(&szDialogTitle);
\r
51 BOOL CUtils::IsXkeymacs()
\r
53 return !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe")) || !_tcsicmp(m_szApplicationName, _T("xkeymacs64.exe"));
\r
56 BOOL CUtils::IsChrome()
\r
58 return !_tcsicmp(m_szApplicationName, _T("chrome.exe"));
\r
61 BOOL CUtils::IsAstecX()
\r
63 return !_tcsicmp(m_szApplicationName, _T("astecx.exe"));
\r
66 BOOL CUtils::IsBecky()
\r
68 return !_tcsicmp(m_szApplicationName, _T("b2.exe"));
\r
71 BOOL CUtils::IsEmacs()
\r
73 return !_tcsicmp(m_szApplicationName, _T("Emacs.exe"));
\r
76 BOOL CUtils::IsExplorer()
\r
78 return !_tcsicmp(m_szApplicationName, _T("explorer.exe"));
\r
81 BOOL CUtils::IsHidemaru()
\r
83 return !_tcsicmp(m_szApplicationName, _T("hidemaru.exe"));
\r
86 BOOL CUtils::IsInternetExplorer()
\r
88 return !_tcsicmp(m_szApplicationName, _T("iexplore.exe"));
\r
91 BOOL CUtils::IsLotus123()
\r
93 return !_tcsicmp(m_szApplicationName, _T("123w.exe"));
\r
96 BOOL CUtils::IsLotusNotes()
\r
98 return !_tcsicmp(m_szApplicationName, _T("nlnotes.exe"));
\r
101 BOOL CUtils::IsLotusWordPro()
\r
103 return !_tcsicmp(m_szApplicationName, _T("wordpro.exe"));
\r
106 BOOL CUtils::IsMeadow()
\r
108 return !_tcsicmp(m_szApplicationName, _T("Meadow.exe"))
\r
109 || !_tcsicmp(m_szApplicationName, _T("Meadow95.exe"))
\r
110 || !_tcsicmp(m_szApplicationName, _T("MeadowNT.exe"));
\r
113 BOOL CUtils::IsMicrosoftFrontPage()
\r
115 return !_tcsicmp(m_szApplicationName, _T("frontpg.exe"));
\r
118 BOOL CUtils::IsMicrosoftWord()
\r
120 return !_tcsicmp(m_szApplicationName, _T("winword.exe"));
\r
123 BOOL CUtils::IsMozilla()
\r
125 return !_tcsicmp(m_szApplicationName, _T("mozilla.exe"))
\r
126 || !_tcsicmp(m_szApplicationName, _T("firefox.exe"));
\r
129 BOOL CUtils::IsMuleForWin32()
\r
131 return !_tcsicmp(m_szApplicationName, _T("mule.exe"))
\r
132 || !_tcsicmp(m_szApplicationName, _T("mulent.exe"))
\r
133 || !_tcsicmp(m_szApplicationName, _T("mulecd.exe"));
\r
136 BOOL CUtils::IsNetscape()
\r
138 return !_tcsicmp(m_szApplicationName, _T("netscp6.exe"))
\r
139 || !_tcsicmp(m_szApplicationName, _T("netscp.exe"));
\r
142 BOOL CUtils::IsNotepad()
\r
144 return !_tcsicmp(m_szApplicationName, _T("notepad.exe"));
\r
147 BOOL CUtils::IsNotepadPP()
\r
149 return !_tcsicmp(m_szApplicationName, _T("notepad++.exe"));
\r
152 BOOL CUtils::IsOpera()
\r
154 return !_tcsicmp(m_szApplicationName, _T("opera.exe"));
\r
157 BOOL CUtils::IsOutlook()
\r
159 return !_tcsicmp(m_szApplicationName, _T("outlook.exe"));
\r
162 BOOL CUtils::IsOutlookExpress()
\r
164 return !_tcsicmp(m_szApplicationName, _T("msimn.exe"));
\r
167 BOOL CUtils::IsSakuraEditor()
\r
169 return !_tcsicmp(m_szApplicationName, _T("sakura.exe"));
\r
172 BOOL CUtils::IsTeraTermPro()
\r
174 return !_tcsicmp(m_szApplicationName, _T("ttermpro.exe"));
\r
177 BOOL CUtils::IsVisualCpp()
\r
179 return !_tcsicmp(m_szApplicationName, _T("msdev.exe"));
\r
182 BOOL CUtils::IsWordpad()
\r
184 return !_tcsicmp(m_szApplicationName, _T("wordpad.exe"));
\r
187 BOOL CUtils::IsXWin()
\r
189 return !_tcsicmp(m_szApplicationName, _T("XWin.exe"));
\r
192 BOOL CUtils::IsXyzzy()
\r
194 return !_tcsicmp(m_szApplicationName, _T("xyzzy.exe"));
\r
197 LPCTSTR const CUtils::GetApplicationName()
\r
199 return m_szApplicationName;
\r
202 void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)
\r
204 if (IsFindDialog()) {
\r
208 if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) { // "foo bar" -> foo bar
\r
209 int len = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"
\r
210 memmove(szWindowText, szWindowText + 1, len);
\r
211 memset(szWindowText + len, 0, WINDOW_TEXT_LENGTH - len);
\r
212 } else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo
\r
213 LPTSTR p = _tcschr(szWindowText, _T(' '));
\r
214 memset(p, 0, WINDOW_TEXT_LENGTH - (p - szWindowText));
\r
217 memset(szApplicationName, 0, MAX_PATH);
\r
218 _stprintf_s(szApplicationName, MAX_PATH, _T("%s"), szWindowText);
\r
220 static LPCTSTR const szExe = _T(".exe");
\r
221 if (_tcsnicmp(szApplicationName + _tcslen(szApplicationName) - _tcslen(szExe), szExe, _tcslen(szExe))) {
\r
222 _tcscat_s(szApplicationName, MAX_PATH, szExe);
\r
226 // Set real application name in the szApplicationName.
\r
227 void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)
\r
229 if (IsConsole(szApplicationName)) {
\r
231 static LPCTSTR const szPromptName[] = {_T("Command Prompt"), _T("Mark Command Prompt"), _T("Select Command Prompt"), _T("MS-DOS Prompt"),
\r
232 _T("Visual Studio .NET Command Prompt"), _T("Visual Studio .NET 2003 Command Prompt"),
\r
233 _T("
\83R
\83}
\83\93\83h
\83v
\83\8d\83\93\83v
\83g"), _T("
\94Í
\88Í
\8ew
\92è
\83R
\83}
\83\93\83h
\83v
\83\8d\83\93\83v
\83g"), _T("
\91I
\91ð
\83R
\83}
\83\93\83h
\83v
\83\8d\83\93\83v
\83g"), _T("MS-DOS
\83v
\83\8d\83\93\83v
\83g"),
\r
234 _T("Visual Studio .NET
\83R
\83}
\83\93\83h
\83v
\83\8d\83\93\83v
\83g"), _T("Visual Studio .NET 2003
\83R
\83}
\83\93\83h
\83v
\83\8d\83\93\83v
\83g")};
\r
235 static LPCTSTR const szPromptPath[] = {_T("system32\\cmd.exe")}; // WindowText of Command Prompt is sometimes this style. But MS-DOS Prompt's is always MS-DOS Prompt.
\r
236 static LPCTSTR const szSeparator = _T(" - ");
\r
238 for (i = 0; i < sizeof(szPromptName) / sizeof(szPromptName[0]); ++i) {
\r
239 if (!_tcsicmp(szWindowText, szPromptName[i])) { // "Command Prompt"
\r
243 TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};
\r
244 _stprintf_s(sz, _T("%s%s"), szPromptName[i], szSeparator);
\r
246 if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) { // "Command Promp - foo"
\r
247 _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, szWindowText + _tcslen(sz));
\r
248 FairConsoleApplicationName(szApplicationName, szWindowText);
\r
253 for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {
\r
254 TCHAR lower[WINDOW_TEXT_LENGTH] = {'\0'};
\r
255 _tcscpy_s(lower, szWindowText);
\r
258 if (_tcsstr(lower, szPromptPath[i])) {
\r
259 TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};
\r
260 _stprintf_s(sz, _T("%s%s"), szPromptPath[i], szSeparator);
\r
262 if (_tcsstr(lower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"
\r
263 _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, _tcsstr(lower, sz) + _tcslen(sz));
\r
264 FairConsoleApplicationName(szApplicationName, szWindowText);
\r
266 } else { // "X:\WINNT\system32\cmd.exe"
\r
272 LPTSTR newName = NULL, newText = NULL;
\r
273 if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))
\r
274 || (*szWindowText == _T('~'))
\r
275 || (*szWindowText == _T('/'))) { // Bash
\r
276 newName = _T("bash.exe");
\r
277 newText = _T("bash");
\r
278 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) {
\r
279 newName = _T("pdksh.exe");
\r
280 newText = _T("pdksh");
\r
281 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) {
\r
282 newName = _T("tcsh.exe");
\r
283 newText = _T("tcsh");
\r
284 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) {
\r
285 newName = _T("zsh.exe");
\r
286 newText = _T("zsh");
\r
287 } else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14)
\r
288 || !_tcsnicmp(szWindowText, _T("cat"), 3)) {
\r
289 newName = _T("sh.exe");
\r
290 newText = _T("MKS Korn Shell");
\r
291 } else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2)
\r
292 || !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) {
\r
293 newName = _T("csh.exe");
\r
294 newText = _T("C Shell");
\r
295 } else if (_tcsstr(szWindowText, _T(" - VIM"))) {
\r
296 newName = _T("vim.exe");
\r
297 newText = _T("VIM");
\r
298 } else if (_tcsstr(szWindowText, _T(" - Poderosa"))) {
\r
299 newName = _T("Poderosa.exe");
\r
300 newText = _T("Poderosa");
\r
301 } else { // unknown console application
\r
302 FairConsoleApplicationName(szApplicationName, szWindowText);
\r
305 memset(szApplicationName, 0, MAX_PATH);
\r
306 _tcscpy_s(szApplicationName, MAX_PATH, newName);
\r
307 memset(szWindowText, 0, WINDOW_TEXT_LENGTH);
\r
308 _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, newText);
\r
310 } else if (IsJavaW(szApplicationName)) {
\r
311 LPTSTR newName = NULL;
\r
312 if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) {
\r
313 newName = _T("eclipse.exe");
\r
314 } else if (!_tcsicmp(szWindowText, _T("BlueJ"))
\r
315 || !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) {
\r
316 newName = _T("bluej.exe");
\r
317 } else if (!_tcsicmp(szWindowText, _T("JUDE"))
\r
318 || !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) {
\r
319 newName = _T("jude.exe");
\r
322 memset(szApplicationName, 0, MAX_PATH);
\r
323 _tcscpy_s(szApplicationName, MAX_PATH, newName);
\r
329 void CUtils::SetApplicationName(BOOL bImeComposition)
\r
331 // CUtils::Log(_T("SetApplicationName: start"));
\r
333 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
335 if (_tcscmp(m_szIMEName, _T("IME")) == 0) { // IDS_IME_FILE_NAME
\r
336 HKL hKL = GetKeyboardLayout(0);
\r
337 if (ImmIsIME(hKL)) {
\r
338 if (!ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName))) {
\r
339 _tcsncpy_s(m_szIMEName, _T("IME"), _TRUNCATE); // IDS_IME_FILE_NAME
\r
341 // CUtils::Log(_T("SetApplicationName: m_szIMEName == %s"), m_szIMEName);
\r
345 if (bImeComposition) {
\r
346 // CUtils::Log(_T("SetApplicationName: bImeComposition"));
\r
348 HKL hKL = GetKeyboardLayout(0);
\r
349 if (ImmIsIME(hKL)) {
\r
350 if (!ImmGetIMEFileName(hKL, m_szApplicationName, sizeof(m_szApplicationName))) {
\r
351 _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);
\r
353 _tcsncpy_s(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));
\r
355 // ImmIsIME return 0 on Word2002, Excel2002, etc. with IME2002, so...
\r
356 // _tcsncpy(m_szApplicationName, _T("imjp81.ime"), sizeof(m_szApplicationName));
\r
357 _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);
\r
360 // CUtils::Log(_T("SetApplicationName: appication (%s)"), m_szApplicationName);
\r
362 GetModuleFileName(NULL, m_szApplicationName, sizeof(m_szApplicationName));
\r
363 CString szFn(m_szApplicationName);
\r
364 szFn.Delete(0, szFn.ReverseFind(_T('\\')) + 1);
\r
365 ZeroMemory(m_szApplicationName, sizeof(m_szApplicationName));
\r
366 _tcscpy_s(m_szApplicationName, szFn);
\r
368 // CUtils::Log(_T("SetApplicationName: appication [%s]"), m_szApplicationName);
\r
371 // CUtils::Log(_T("SetApplicationName: console"));
\r
373 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
374 _tcscpy_s(m_szApplicationName, _T("CMD.exe"));
\r
375 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
376 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
377 SetCorrectApplicationName(m_szApplicationName, szWindowText);
\r
378 } else if (IsJavaW()) {
\r
379 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
380 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
381 SetCorrectApplicationName(m_szApplicationName, szWindowText);
\r
383 if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {
\r
384 // CUtils::Log(_T("SetApplicationName: cygwin"));
\r
386 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
387 _tcscpy_s(m_szApplicationName, _T("bash.exe"));
\r
389 // CUtils::Log(_T("name: %s"), m_szApplicationName);
\r
393 BOOL CUtils::OpenClipboard()
\r
395 // OpenClipboard will fail on OpenOffice.org/LibreOffice at the first time
\r
396 // and we must retry multiple times.
\r
397 for (int i = 0; i < 10; ++i, Sleep(1))
\r
398 if (::OpenClipboard(NULL))
\r
401 // Log(_T("failed to open clipboard: %d (%d)"), GetLastError(), i);
\r
405 BOOL CUtils::GetClipboardText(CString& text)
\r
408 if (!OpenClipboard())
\r
411 Log(_T("GetClipboardText"));
\r
413 while (uFormat = EnumClipboardFormats(uFormat))
\r
414 Log(_T("uFormat = %d"), uFormat);
\r
416 const HANDLE hClipboard = GetClipboardData(CF_TEXT);
\r
421 const LPVOID pMem = GlobalLock(hClipboard);
\r
424 text = reinterpret_cast<LPCSTR>(pMem);
\r
425 GlobalUnlock(hClipboard);
\r
431 BOOL CUtils::SetClipboardText(const CString& text)
\r
433 if (!OpenClipboard())
\r
435 const int nLength = text.GetLength() + 1;
\r
436 const HGLOBAL hClipboard = GlobalAlloc(GHND, nLength);
\r
439 const LPVOID pMem = GlobalLock(hClipboard);
\r
440 memcpy(pMem, LPCTSTR(text), nLength);
\r
441 GlobalUnlock(hClipboard);
\r
443 if (SetClipboardData(CF_TEXT, hClipboard) == NULL) {
\r
451 BOOL CUtils::IsDefaultIgnoreApplication()
\r
457 || IsLispWorksPersonalEdition()
\r
459 || IsMuleForWin32()
\r
463 || IsTeraTermPro() && !IsDialog()
\r
464 || IsVisualSlickEdit() && !IsDialog()
\r
466 || IsXyzzy() && !IsDialog()
\r
473 BOOL CUtils::IsDWFM()
\r
475 return !_tcsicmp(m_szApplicationName, _T("dwfm.exe"));
\r
478 BOOL CUtils::IsK2Editor()
\r
480 return !_tcsicmp(m_szApplicationName, _T("K2Editor.exe"));
\r
483 BOOL CUtils::IsEggExplorer()
\r
485 return !_tcsicmp(m_szApplicationName, _T("EggExp.exe"));
\r
488 BOOL CUtils::IsDirector()
\r
490 return !_tcsicmp(m_szApplicationName, _T("Director.exe"));
\r
493 BOOL CUtils::IsExcel()
\r
495 return !_tcsicmp(m_szApplicationName, _T("Excel.exe"));
\r
498 BOOL CUtils::IsFireworks()
\r
500 return !_tcsicmp(m_szApplicationName, _T("Fireworks 4.exe"))
\r
501 || !_tcsicmp(m_szApplicationName, _T("Fireworks.exe"));
\r
504 BOOL CUtils::IsDreamweaver()
\r
506 return !_tcsicmp(m_szApplicationName, _T("Dreamweaver.exe"));
\r
509 BOOL CUtils::IsFlash()
\r
511 return !_tcsicmp(m_szApplicationName, _T("Flash.exe"));
\r
514 BOOL CUtils::IsPhotoshop()
\r
516 return !_tcsicmp(m_szApplicationName, _T("Photoshp.exe"));
\r
519 BOOL CUtils::IsIllustrator()
\r
521 return !_tcsicmp(m_szApplicationName, _T("Illustrator.exe"));
\r
524 BOOL CUtils::IsMicrosoftPowerPoint()
\r
526 return !_tcsicmp(m_szApplicationName, _T("PowerPnt.exe"));
\r
529 BOOL CUtils::IsReget()
\r
531 return !_tcsicmp(m_szApplicationName, _T("Regetdx.exe"))
\r
532 || !_tcsicmp(m_szApplicationName, _T("Regetjr.exe"));
\r
535 BOOL CUtils::IsPaint()
\r
537 return !_tcsicmp(m_szApplicationName, _T("mspaint.exe"));
\r
540 BOOL CUtils::IsConsole()
\r
542 // Log(_T("_%s_"), m_szApplicationName);
\r
543 return !m_szApplicationName[0]
\r
544 || !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe"))
\r
545 || !_tcsicmp(m_szApplicationName, _T("conhost.exe"))
\r
546 || !_tcsicmp(m_szApplicationName, _T("conime.exe"))
\r
547 || !_tcsicmp(m_szApplicationName, _T("csh.exe"))
\r
548 || !_tcsicmp(m_szApplicationName, _T("WINOA386.MOD"))
\r
549 || !_tcsicmp(m_szApplicationName, _T("CMD.exe"))
\r
550 || !_tcsicmp(m_szApplicationName, _T("bash.exe"))
\r
551 || !_tcsicmp(m_szApplicationName, _T("ftp.exe"))
\r
552 || !_tcsicmp(m_szApplicationName, _T("sh.exe"))
\r
553 || !_tcsicmp(m_szApplicationName, _T("telnet.exe"));
\r
556 BOOL CUtils::IsConsole(LPCTSTR szApplicationName)
\r
558 return !_tcsicmp(szApplicationName, _T("WINOA386.MOD"))
\r
559 || !_tcsicmp(szApplicationName, _T("CMD.exe"));
\r
562 BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)
\r
564 return !_tcsicmp(szApplicationName, _T("javaw.exe"));
\r
567 BOOL CUtils::IsSleipnir()
\r
569 return !_tcsicmp(m_szApplicationName, _T("Sleipnir.exe"));
\r
572 BOOL CUtils::IsBash()
\r
574 return !_tcsicmp(m_szApplicationName, _T("bash.exe"));
\r
577 static void invalid_parameter_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t)
\r
583 void CUtils::Log(LPCTSTR fmt, ...)
\r
588 _set_invalid_parameter_handler(invalid_parameter_handler);
\r
589 if (_vstprintf_s(log, fmt, ap) < 0)
\r
590 _tcscpy_s(log, _T("invalid format"));
\r
593 TCHAR path[MAX_PATH];
\r
594 if (GetTempPath(MAX_PATH, path)) {
\r
596 _tmakepath_s(path, NULL, path, _T("xkeylog"), _T("txt"));
\r
598 _tmakepath_s(path, NULL, path, _T("xkeylog64"), _T("txt"));
\r
601 _tcscpy_s(path, _T("c:\\xkeylog.txt"));
\r
603 _tfopen_s(&fp, path, _T("a"));
\r
604 _ftprintf(fp, _T("%8d: %s\t%s\n"), n++, m_szApplicationName, log);
\r
608 BOOL CUtils::IsSh()
\r
610 return !_tcsicmp(m_szApplicationName, _T("sh.exe"));
\r
613 BOOL CUtils::IsCsh()
\r
615 return !_tcsicmp(m_szApplicationName, _T("csh.exe"));
\r
618 BOOL CUtils::IsVisualStudio()
\r
620 if (IsVisualCpp() || CUtils::IsVisualBasic())
\r
622 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = _T("");
\r
623 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
624 return _tcsstr(szWindowText, _T(" - Microsoft Visual ")) != NULL;
\r
627 BOOL CUtils::IsAccess()
\r
629 return !_tcsicmp(m_szApplicationName, _T("MSACCESS.EXE"));
\r
632 BOOL CUtils::IsProject()
\r
634 return !_tcsicmp(m_szApplicationName, _T("WINPROJ.EXE"));
\r
637 BOOL CUtils::IsVisualBasic()
\r
639 return !_tcsicmp(m_szApplicationName, _T("VB6.EXE"));
\r
642 BOOL CUtils::IsVisualBasicEditor()
\r
644 if (IsVisualBasic()) {
\r
650 || IsMicrosoftFrontPage()
\r
651 || IsMicrosoftPowerPoint()
\r
652 || IsMicrosoftWord()
\r
655 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
656 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
657 static LPCTSTR const szVBE = _T("Microsoft Visual Basic - ");
\r
658 if (!_tcsnicmp(szWindowText, szVBE, _tcslen(szVBE))) {
\r
665 BOOL CUtils::IsEclipse()
\r
667 if (!_tcsicmp(m_szApplicationName, _T("eclipse.exe")))
\r
670 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
671 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
673 LPCTSTR szEclipse = _T(" - Eclipse Platform");
\r
674 LPCTSTR szFind = _T("Find/Replace");
\r
677 && (_tcslen(szEclipse) < _tcslen(szWindowText) && !_tcsicmp(szWindowText + _tcslen(szWindowText) - _tcslen(szEclipse), szEclipse)
\r
678 || _tcslen(szFind) == _tcslen(szWindowText) && !_tcsicmp(szWindowText, szFind));
\r
681 BOOL CUtils::IsDialog()
\r
683 HWND hwnd = GetForegroundWindow();
\r
684 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
685 if (!GetWindowText(hwnd, szWindowText, sizeof(szWindowText)))
\r
686 return FALSE; // inside sound box
\r
687 return GetParent(GetForegroundWindow()) != NULL;
\r
690 BOOL CUtils::IsEudora()
\r
692 return !_tcsicmp(m_szApplicationName, _T("Eudora.exe"));
\r
695 BOOL CUtils::IsCodeWarrior()
\r
697 return !_tcsicmp(m_szApplicationName, _T("IDE.exe"));
\r
700 BOOL CUtils::IseMemoPad()
\r
702 return !_tcsicmp(m_szApplicationName, _T("eMemoPad.exe"));
\r
705 BOOL CUtils::IsStoryEditor()
\r
707 return !_tcsicmp(m_szApplicationName, _T("STRYEDIT.EXE"));
\r
710 BOOL CUtils::IsNami2000()
\r
712 return !_tcsicmp(m_szApplicationName, _T("Nami2000.exe"));
\r
715 BOOL CUtils::IsCorelDRAW()
\r
717 return !_tcsicmp(m_szApplicationName, _T("CorelDrw.exe"));
\r
720 // If Clipboard data is empty, return true.
\r
721 // You must CopyNextCharacter in previous step.
\r
722 // Clipboard data is destroyed.
\r
723 BOOL CUtils::IsEOF()
\r
725 return IsTOForEOF();
\r
728 // If Clipboard data is empty, return ture.
\r
729 // You must CopyBackCharacter in previous step.
\r
730 // Clipboard data is destroyed.
\r
731 BOOL CUtils::IsTOF()
\r
733 return IsTOForEOF();
\r
736 BOOL CUtils::IsTOForEOF()
\r
739 GetClipboardText(text);
\r
740 return text.IsEmpty() || // for normal application
\r
741 text.GetLength() >= 3; // for VC++
\r
744 BOOL CUtils::IsHusen()
\r
746 return !_tcsicmp(m_szApplicationName, _T("husen.exe"));
\r
749 BOOL CUtils::IsAdobeReader()
\r
751 return !_tcsicmp(m_szApplicationName, _T("AcroRd32.exe"));
\r
754 BOOL CUtils::IsOpenOffice()
\r
756 return !_tcsicmp(m_szApplicationName, _T("soffice.exe"))
\r
757 || !_tcsicmp(m_szApplicationName, _T("soffice.bin"));
\r
760 BOOL CUtils::IsTuruKameMail()
\r
762 return !_tcsicmp(m_szApplicationName, _T("TuruKame.exe"));
\r
765 BOOL CUtils::IsOedit()
\r
767 return !_tcsicmp(m_szApplicationName, _T("oedit.exe"));
\r
770 BOOL CUtils::IsAutla()
\r
772 return !_tcsicmp(m_szApplicationName, _T("Autla.exe"));
\r
775 BOOL CUtils::IsShuriken()
\r
777 return !_tcsicmp(m_szApplicationName, _T("JsvMail.exe"));
\r
780 BOOL CUtils::IsEdLeaf()
\r
782 return !_tcsicmp(m_szApplicationName, _T("edleaf.exe"));
\r
785 BOOL CUtils::IsJmEditor()
\r
787 return !_tcsicmp(m_szApplicationName, _T("JmEdit.exe"))
\r
788 || !_tcsicmp(m_szApplicationName, _T("JmEdit2.exe"));
\r
791 BOOL CUtils::IsDana()
\r
793 return !_tcsicmp(m_szApplicationName, _T("Dana.exe"));
\r
796 BOOL CUtils::IsIPMessenger()
\r
798 return !_tcsicmp(m_szApplicationName, _T("ipmsg.exe"));
\r
801 BOOL CUtils::IsezHTML()
\r
803 return !_tcsicmp(m_szApplicationName, _T("ezhtml.exe"));
\r
806 BOOL CUtils::IsTcsh()
\r
808 return !_tcsicmp(m_szApplicationName, _T("tcsh.exe"));
\r
811 BOOL CUtils::IsZsh()
\r
813 return !_tcsicmp(m_szApplicationName, _T("zsh.exe"));
\r
816 BOOL CUtils::IsPdksh()
\r
818 return !_tcsicmp(m_szApplicationName, _T("pdksh.exe"));
\r
821 BOOL CUtils::IsFirefox()
\r
823 return !_tcsicmp(m_szApplicationName, _T("firefox.exe"));
\r
826 BOOL CUtils::IsPHPEditor()
\r
828 return !_tcsicmp(m_szApplicationName, _T("php_editor.exe"));
\r
831 BOOL CUtils::IsTeraPad()
\r
833 return !_tcsicmp(m_szApplicationName, _T("TeraPad.exe"));
\r
836 BOOL CUtils::IsLispWorksPersonalEdition()
\r
838 CString szLispWorks(_T("lispworks-personal-"));
\r
839 return !_tcsnicmp(m_szApplicationName, szLispWorks, szLispWorks.GetLength());
\r
841 // return !_tcsicmp(m_szApplicationName, _T("lispworks-personal-4300.exe"));
\r
844 BOOL CUtils::IsBorlandCppBuilder()
\r
846 return !_tcsicmp(m_szApplicationName, _T("bcb.exe"));
\r
849 BOOL CUtils::Run(CString szCommandLine, BOOL isWait)
\r
852 ZeroMemory(&si, sizeof(si));
\r
853 si.cb = sizeof(si);
\r
855 PROCESS_INFORMATION pi;
\r
856 ZeroMemory(&pi, sizeof(pi));
\r
858 BOOL rc = CreateProcess(NULL, szCommandLine.GetBuffer(szCommandLine.GetLength() + 1), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
\r
861 WaitForSingleObject( pi.hProcess, INFINITE );
\r
864 CloseHandle(pi.hThread);
\r
865 CloseHandle(pi.hProcess);
\r
871 BOOL CUtils::IsJavaW()
\r
873 return !_tcsicmp(m_szApplicationName, _T("javaw.exe"));
\r
876 BOOL CUtils::IsMSDN()
\r
878 return !_tcsicmp(m_szApplicationName, _T("hh.exe"));
\r
881 BOOL CUtils::IsVisualSlickEdit()
\r
883 return !_tcsicmp(m_szApplicationName, _T("vs.exe"));
\r
886 BOOL CUtils::IsOpenJane()
\r
888 return !_tcsicmp(m_szApplicationName, _T("Jane2ch.exe"));
\r
891 BOOL CUtils::IsThunderbird()
\r
893 return !_tcsicmp(m_szApplicationName, _T("thunderbird.exe"));
\r
896 int CUtils::GetWindowTextType(CString strWindowText)
\r
898 int nWindowTextType = IDS_WINDOW_TEXT_IGNORE;
\r
900 if (3 <= strWindowText.GetLength()
\r
901 && strWindowText.Find(_T('*')) == 0
\r
902 && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {
\r
903 nWindowTextType = IDS_WINDOW_TEXT_MATCH;
\r
904 } else if (2 <= strWindowText.GetLength()
\r
905 && strWindowText.Find(_T('*')) != 0
\r
906 && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {
\r
907 nWindowTextType = IDS_WINDOW_TEXT_MATCH_FORWARD;
\r
908 } else if (2 <= strWindowText.GetLength()
\r
909 && strWindowText.Find(_T('*')) == 0
\r
910 && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {
\r
911 nWindowTextType = IDS_WINDOW_TEXT_MATCH_BACKWARD;
\r
912 } else if (!strWindowText.IsEmpty()
\r
913 && strWindowText.Find(_T('*')) != 0
\r
914 && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {
\r
915 nWindowTextType = IDS_WINDOW_TEXT_MATCH_FULL;
\r
918 return nWindowTextType;
\r
921 BOOL CUtils::IsLunascape()
\r
923 return !_tcsicmp(m_szApplicationName, _T("Luna.exe"));
\r
926 BOOL CUtils::IsAtok()
\r
928 return !_tcsnicmp(m_szApplicationName, _T("ATOK"), 4) && !_tcsnicmp(m_szApplicationName + _tcslen(m_szApplicationName) - 4, _T(".IME"), 4);
\r