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
12 OSVERSIONINFO CUtils::m_OsVersionInfo = {sizeof(OSVERSIONINFO)};
\r
15 //////////////////////////////////////////////////////////////////////
\r
16 // Construction/Destruction
\r
17 //////////////////////////////////////////////////////////////////////
\r
29 BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)
\r
32 TCHAR buf[WINDOW_TEXT_LENGTH] = {'\0'};
\r
33 GetWindowText(GetForegroundWindow(), buf, sizeof(buf));
\r
34 // CUtils::Log(_T("Window Text --%s--"), buf);
\r
35 szDialogTitle->Format(_T("%s"), buf);
\r
38 if (!szDialogTitle->Compare(_T("
\8c\9f\8dõ")) // notepad, wordpad, IE, regedit,
\r
39 // Excel, Front Page, PowerPoint, Acrobat Reader, IBM HPB
\r
40 || !szDialogTitle->Compare(_T("Find")) // notepad, Outlook, Outlook Express, Opera
\r
41 || !szDialogTitle->Compare(_T("Find in this Page")) // Mozilla
\r
42 || !szDialogTitle->Compare(_T("Find/Replace")) // Eclipse
\r
43 || !szDialogTitle->Compare(_T("
\96{
\95¶
\93à
\8c\9f\8dõ")) // Becky!
\r
44 || !szDialogTitle->Compare(_T("
\83\81\81[
\83\8b\8c\9f\8dõ")) // Becky!
\r
45 || !szDialogTitle->Compare(_T("
\95¶
\8e\9a\97ñ
\82Ì
\8c\9f\8dõ")) // M$ VC++
\r
46 || !szDialogTitle->Compare(_T("
\8c\9f\8dõ
\82Æ
\92u
\8a·")) // M$ Word, 123
\r
47 || !szDialogTitle->Compare(_T("
\95¶
\8f\91\82Ì
\83e
\83L
\83X
\83g
\82Ì
\8c\9f\8dõ")) // Lotus Notes
\r
48 || !szDialogTitle->Compare(_T("
\82±
\82Ì
\83y
\81[
\83W
\82ð
\8c\9f\8dõ")) // Netscape 6
\r
49 || !szDialogTitle->Compare(_T("
\95¶
\8e\9a\97ñ
\8c\9f\8dõ")) // Dana
\r
50 || !szDialogTitle->Compare(_T("
\8c\9f\8dõ/
\92u
\8a·")) // PHP Editor
\r
51 || !szDialogTitle->Compare(_T("
\92u
\8a·"))
\r
52 || !szDialogTitle->Compare(_T("Replace"))) {
\r
56 szDialogTitle->Empty();
\r
60 BOOL CUtils::IsFindDialog()
\r
62 CString szDialogTitle;
\r
63 return GetFindDialogTitle(&szDialogTitle);
\r
66 BOOL CUtils::IsAstecX()
\r
68 return !_tcsicmp(m_szApplicationName, _T("astecx.exe"));
\r
71 BOOL CUtils::IsBecky()
\r
73 return !_tcsicmp(m_szApplicationName, _T("b2.exe"));
\r
76 BOOL CUtils::IsEmacs()
\r
78 return !_tcsicmp(m_szApplicationName, _T("Emacs.exe"));
\r
81 BOOL CUtils::IsExplorer()
\r
83 return !_tcsicmp(m_szApplicationName, _T("explorer.exe"));
\r
86 BOOL CUtils::IsHidemaru()
\r
88 return !_tcsicmp(m_szApplicationName, _T("hidemaru.exe"));
\r
91 BOOL CUtils::IsInternetExplorer()
\r
93 return !_tcsicmp(m_szApplicationName, _T("iexplore.exe"));
\r
96 BOOL CUtils::IsLotus123()
\r
98 return !_tcsicmp(m_szApplicationName, _T("123w.exe"));
\r
101 BOOL CUtils::IsLotusNotes()
\r
103 return !_tcsicmp(m_szApplicationName, _T("nlnotes.exe"));
\r
106 BOOL CUtils::IsLotusWordPro()
\r
108 return !_tcsicmp(m_szApplicationName, _T("wordpro.exe"));
\r
111 BOOL CUtils::IsMeadow()
\r
113 return !_tcsicmp(m_szApplicationName, _T("Meadow.exe"))
\r
114 || !_tcsicmp(m_szApplicationName, _T("Meadow95.exe"))
\r
115 || !_tcsicmp(m_szApplicationName, _T("MeadowNT.exe"));
\r
118 BOOL CUtils::IsMicrosoftFrontPage()
\r
120 return !_tcsicmp(m_szApplicationName, _T("frontpg.exe"));
\r
123 BOOL CUtils::IsMicrosoftWord()
\r
125 return !_tcsicmp(m_szApplicationName, _T("winword.exe"));
\r
128 BOOL CUtils::IsMozilla()
\r
130 return !_tcsicmp(m_szApplicationName, _T("mozilla.exe"));
\r
133 BOOL CUtils::IsMuleForWin32()
\r
135 return !_tcsicmp(m_szApplicationName, _T("mule.exe"))
\r
136 || !_tcsicmp(m_szApplicationName, _T("mulent.exe"))
\r
137 || !_tcsicmp(m_szApplicationName, _T("mulecd.exe"));
\r
140 BOOL CUtils::IsNetscape()
\r
142 return !_tcsicmp(m_szApplicationName, _T("netscp6.exe"))
\r
143 || !_tcsicmp(m_szApplicationName, _T("netscp.exe"));
\r
146 BOOL CUtils::IsNotepad()
\r
148 return !_tcsicmp(m_szApplicationName, _T("notepad.exe"));
\r
151 BOOL CUtils::IsOpera()
\r
153 return !_tcsicmp(m_szApplicationName, _T("opera.exe"));
\r
156 BOOL CUtils::IsOutlook()
\r
158 return !_tcsicmp(m_szApplicationName, _T("outlook.exe"));
\r
161 BOOL CUtils::IsOutlookExpress()
\r
163 return !_tcsicmp(m_szApplicationName, _T("msimn.exe"));
\r
166 BOOL CUtils::IsSakuraEditor()
\r
168 return !_tcsicmp(m_szApplicationName, _T("sakura.exe"));
\r
171 BOOL CUtils::IsTeraTermPro()
\r
173 return !_tcsicmp(m_szApplicationName, _T("ttermpro.exe"));
\r
176 BOOL CUtils::IsVisualCpp()
\r
178 return !_tcsicmp(m_szApplicationName, _T("msdev.exe"));
\r
181 BOOL CUtils::IsWordpad()
\r
183 return !_tcsicmp(m_szApplicationName, _T("wordpad.exe"));
\r
186 BOOL CUtils::IsXWin()
\r
188 return !_tcsicmp(m_szApplicationName, _T("XWin.exe"));
\r
191 BOOL CUtils::IsXyzzy()
\r
193 return !_tcsicmp(m_szApplicationName, _T("xyzzy.exe"));
\r
196 LPCTSTR const CUtils::GetApplicationName()
\r
198 return m_szApplicationName;
\r
201 void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)
\r
203 if (IsFindDialog()) {
\r
207 if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) { // "foo bar" -> foo bar
\r
208 int nApplicationName = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"
\r
209 _tcsncpy(szWindowText, szWindowText + 1, nApplicationName);
\r
210 memset(szWindowText + nApplicationName, 0, WINDOW_TEXT_LENGTH - nApplicationName);
\r
211 } else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo
\r
212 LPTSTR pFirstSpace = _tcschr(szWindowText, _T(' '));
\r
213 memset(pFirstSpace, 0, WINDOW_TEXT_LENGTH - (pFirstSpace - szWindowText));
\r
216 memset(szApplicationName, 0, MAX_PATH);
\r
217 _stprintf(szApplicationName, _T("%s"), szWindowText);
\r
219 static LPCTSTR const szExe = _T(".exe");
\r
220 if (_tcsnicmp(szApplicationName + _tcslen(szApplicationName) - _tcslen(szExe), szExe, _tcslen(szExe))) {
\r
221 _tcscat(szApplicationName, szExe);
\r
225 // Set real application name in the szApplicationName.
\r
226 void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)
\r
228 if (IsConsole(szApplicationName)) {
\r
230 static LPCTSTR const szPromptName[] = {_T("Command Prompt"), _T("Mark Command Prompt"), _T("Select Command Prompt"), _T("MS-DOS Prompt"),
\r
231 _T("Visual Studio .NET Command Prompt"), _T("Visual Studio .NET 2003 Command Prompt"),
\r
232 _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
233 _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
234 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
235 static LPCTSTR const szSeparator = _T(" - ");
\r
237 for (i = 0; i < sizeof(szPromptName) / sizeof(szPromptName[0]); ++i) {
\r
238 if (!_tcsicmp(szWindowText, szPromptName[i])) { // "Command Prompt"
\r
242 TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};
\r
243 _stprintf(sz, _T("%s%s"), szPromptName[i], szSeparator);
\r
245 if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) { // "Command Promp - foo"
\r
246 _tcscpy(szWindowText, szWindowText + _tcslen(sz));
\r
247 FairConsoleApplicationName(szApplicationName, szWindowText);
\r
252 for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {
\r
253 TCHAR szWindowTextLower[WINDOW_TEXT_LENGTH] = {'\0'};
\r
254 _tcscpy(szWindowTextLower, szWindowText);
\r
255 _tcslwr(szWindowTextLower);
\r
257 if (_tcsstr(szWindowTextLower, szPromptPath[i])) {
\r
258 TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};
\r
259 _stprintf(sz, _T("%s%s"), szPromptPath[i], szSeparator);
\r
261 if (_tcsstr(szWindowTextLower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"
\r
262 _tcscpy(szWindowText, _tcsstr(szWindowTextLower, sz) + _tcslen(sz));
\r
263 FairConsoleApplicationName(szApplicationName, szWindowText);
\r
265 } else { // "X:\WINNT\system32\cmd.exe"
\r
271 LPTSTR newName = NULL, newText = NULL;
\r
272 if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))
\r
273 || (*szWindowText == _T('~'))
\r
274 || (*szWindowText == _T('/'))) { // Bash
\r
275 newName = _T("bash.exe");
\r
276 newText = _T("bash");
\r
277 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) {
\r
278 newName = _T("pdksh.exe");
\r
279 newText = _T("pdksh");
\r
280 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) {
\r
281 newName = _T("tcsh.exe");
\r
282 newText = _T("tcsh");
\r
283 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) {
\r
284 newName = _T("zsh.exe");
\r
285 newText = _T("zsh");
\r
286 } else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14)
\r
287 || !_tcsnicmp(szWindowText, _T("cat"), 3)) {
\r
288 newName = _T("sh.exe");
\r
289 newText = _T("MKS Korn Shell");
\r
290 } else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2)
\r
291 || !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) {
\r
292 newName = _T("csh.exe");
\r
293 newText = _T("C Shell");
\r
294 } else if (_tcsstr(szWindowText, _T(" - VIM"))) {
\r
295 newName = _T("vim.exe");
\r
296 newText = _T("VIM");
\r
297 } else if (_tcsstr(szWindowText, _T(" - Poderosa"))) {
\r
298 newName = _T("Poderosa.exe");
\r
299 newText = _T("Poderosa");
\r
300 } else { // unknown console application
\r
301 FairConsoleApplicationName(szApplicationName, szWindowText);
\r
304 memset(szApplicationName, 0, MAX_PATH);
\r
305 _stprintf(szApplicationName, newName);
\r
306 memset(szWindowText, 0, WINDOW_TEXT_LENGTH);
\r
307 _stprintf(szWindowText, newText);
\r
309 } else if (IsJavaW(szApplicationName)) {
\r
310 LPTSTR newName = NULL;
\r
311 if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) {
\r
312 newName = _T("eclipse.exe");
\r
313 } else if (!_tcsicmp(szWindowText, _T("BlueJ"))
\r
314 || !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) {
\r
315 newName = _T("bluej.exe");
\r
316 } else if (!_tcsicmp(szWindowText, _T("JUDE"))
\r
317 || !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) {
\r
318 newName = _T("jude.exe");
\r
321 memset(szApplicationName, 0, MAX_PATH);
\r
322 _stprintf(szApplicationName, newName);
\r
328 void CUtils::SetApplicationName(BOOL bImeComposition)
\r
330 // CUtils::Log(_T("SetApplicationName: start"));
\r
332 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
334 if (_tcscmp(m_szIMEName, _T("IME")) == 0) { // IDS_IME_FILE_NAME
\r
335 HKL hKL = GetKeyboardLayout(0);
\r
336 if (ImmIsIME(hKL)) {
\r
337 if (!ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName))) {
\r
338 _tcsncpy(m_szIMEName, _T("IME"), sizeof(m_szIMEName)); // IDS_IME_FILE_NAME
\r
340 // CUtils::Log(_T("SetApplicationName: m_szIMEName == %s"), m_szIMEName);
\r
344 if (bImeComposition) {
\r
345 // CUtils::Log(_T("SetApplicationName: bImeComposition"));
\r
347 HKL hKL = GetKeyboardLayout(0);
\r
348 if (ImmIsIME(hKL)) {
\r
349 if (!ImmGetIMEFileName(hKL, m_szApplicationName, sizeof(m_szApplicationName))) {
\r
350 _tcsncpy(m_szApplicationName, m_szIMEName, sizeof(m_szApplicationName));
\r
352 _tcsncpy(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));
\r
354 // ImmIsIME return 0 on Word2002, Excel2002, etc. with IME2002, so...
\r
355 // _tcsncpy(m_szApplicationName, _T("imjp81.ime"), sizeof(m_szApplicationName));
\r
356 _tcsncpy(m_szApplicationName, m_szIMEName, sizeof(m_szApplicationName));
\r
359 // CUtils::Log(_T("SetApplicationName: appication (%s)"), m_szApplicationName);
\r
361 GetModuleFileName(NULL, m_szApplicationName, sizeof(m_szApplicationName));
\r
362 CString szFn(m_szApplicationName);
\r
363 szFn.Delete(0, szFn.ReverseFind(_T('\\')) + 1);
\r
364 ZeroMemory(m_szApplicationName, sizeof(m_szApplicationName));
\r
365 _tcsncpy(m_szApplicationName, szFn, szFn.GetLength());
\r
367 // CUtils::Log(_T("SetApplicationName: appication [%s]"), m_szApplicationName);
\r
370 // CUtils::Log(_T("SetApplicationName: console"));
\r
372 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
373 _tcscpy(m_szApplicationName, _T("CMD.exe"));
\r
374 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
375 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
376 SetCorrectApplicationName(m_szApplicationName, szWindowText);
\r
377 } else if (IsJavaW()) {
\r
378 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
379 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
380 SetCorrectApplicationName(m_szApplicationName, szWindowText);
\r
382 if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {
\r
383 // CUtils::Log(_T("SetApplicationName: cygwin"));
\r
385 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
386 _tcscpy(m_szApplicationName, _T("bash.exe"));
\r
388 // CUtils::Log(_T("name: %s"), m_szApplicationName);
\r
392 void CUtils::SetIMEName()
\r
394 HKL hKL = GetKeyboardLayout(0);
\r
395 if (ImmIsIME(hKL)) {
\r
396 ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName));
\r
400 void CUtils::InitCUtils()
\r
402 GetVersionEx(&m_OsVersionInfo);
\r
406 BOOL CUtils::IsXPorLater()
\r
408 return 5 < m_OsVersionInfo.dwMajorVersion
\r
409 || 5 == m_OsVersionInfo.dwMajorVersion && 1 <= m_OsVersionInfo.dwMinorVersion;
\r
412 BOOL CUtils::OpenClipboard()
\r
414 const int RETRY_COUNT = 0x10;
\r
416 BOOL bOpened = FALSE;
\r
417 for (int i = 0; i <= RETRY_COUNT; ++i) {
\r
418 if (::OpenClipboard(NULL)) {
\r
419 // Log(_T("ok (%d)"), i);
\r
423 Sleep(1); // for OpenOffice
\r
424 // Log(_T("CUtils::OpenClipboard: %d (%d)"), GetLastError(), i);
\r
431 BOOL CUtils::GetClipboardText(CString *szClipboardText)
\r
433 if (!szClipboardText) {
\r
437 szClipboardText->Empty();
\r
439 if (!OpenClipboard()) {
\r
440 // CUtils::Log(_T("Cannot open the Clipboard"));
\r
446 Log(_T("GetClipboardText"));
\r
449 uFormat = EnumClipboardFormats(uFormat);
\r
451 Log(_T("uFormat = %d"), uFormat);
\r
457 //#define CF_TEXT 1
\r
458 //#define CF_METAFILEPICT 3
\r
459 //#define CF_OEMTEXT 7
\r
460 //#define CF_UNICODETEXT 13
\r
461 //#define CF_ENHMETAFILE 14
\r
462 //#define CF_LOCALE 16
\r
463 //#define CF_DSPTEXT 0x0081
\r
466 // DataObject 49161
\r
467 // Embed Source 49163
\r
468 // Object Descriptor 49166
\r
469 // Ole Private Data 49171
\r
470 // Rich Text Format 49311
\r
471 // Rich Text Format 49312
\r
472 // HTML Format 49360
\r
473 // HTML Format 49361
\r
475 // RTF As Text 49595
\r
476 // Rich Text Format Without Objects 49618
\r
477 // Star Object Descriptor (XML) 49681
\r
478 // Star Embed Source (XML) 49708
\r
479 // HPB HTML Format 49742
\r
483 UINT uFormat = CF_OEMTEXT;
\r
484 if (IsSakuraEditor()) {
\r
488 HANDLE hClipboardText;
\r
489 if ((hClipboardText = ::GetClipboardData(uFormat)) == NULL) {
\r
490 // DWORD dw = GetLastError();
\r
491 // CUtils::Log(_T("Unable to get Clipboard data: %d"), dw);
\r
496 szClipboardText->Format(_T("%s"), hClipboardText);
\r
502 BOOL CUtils::SetClipboardText(CString *szClipboardText)
\r
504 if (!OpenClipboard()) {
\r
505 // CUtils::Log(_T("Cannot open the Clipboard in SetClipboardText"));
\r
509 int nLength = szClipboardText->GetLength() + 1;
\r
510 HGLOBAL hClipboardText = GlobalAlloc(GHND, nLength);
\r
511 if (hClipboardText == NULL) {
\r
512 // CUtils::Log(_T("Failed: GlobalAlloc in SetClipboardText"));
\r
516 LPTSTR lpStr = (LPTSTR)GlobalLock(hClipboardText);
\r
517 lstrcpyn(lpStr, *szClipboardText, nLength);
\r
518 GlobalUnlock(hClipboardText);
\r
521 UINT uFormat = CF_OEMTEXT;
\r
522 if (IsSakuraEditor()) {
\r
526 if ((hClipboardText = ::SetClipboardData(uFormat, hClipboardText)) == NULL) {
\r
527 // DWORD dw = GetLastError();
\r
528 // CUtils::Log(_T("Unable to set Clipboard data: %d"), dw);
\r
537 BOOL CUtils::IsDefaultIgnoreApplication()
\r
543 || IsLispWorksPersonalEdition()
\r
545 || IsMuleForWin32()
\r
549 || IsTeraTermPro() && !IsDialog()
\r
550 || IsVisualSlickEdit() && !IsDialog()
\r
552 || IsXyzzy() && !IsDialog()
\r
559 BOOL CUtils::IsDWFM()
\r
561 return !_tcsicmp(m_szApplicationName, _T("dwfm.exe"));
\r
564 BOOL CUtils::IsK2Editor()
\r
566 return !_tcsicmp(m_szApplicationName, _T("K2Editor.exe"));
\r
569 BOOL CUtils::IsEggExplorer()
\r
571 return !_tcsicmp(m_szApplicationName, _T("EggExp.exe"));
\r
574 BOOL CUtils::IsDirector()
\r
576 return !_tcsicmp(m_szApplicationName, _T("Director.exe"));
\r
579 BOOL CUtils::IsExcel()
\r
581 return !_tcsicmp(m_szApplicationName, _T("Excel.exe"));
\r
584 BOOL CUtils::IsFireworks()
\r
586 return !_tcsicmp(m_szApplicationName, _T("Fireworks 4.exe"))
\r
587 || !_tcsicmp(m_szApplicationName, _T("Fireworks.exe"));
\r
590 BOOL CUtils::IsDreamweaver()
\r
592 return !_tcsicmp(m_szApplicationName, _T("Dreamweaver.exe"));
\r
595 BOOL CUtils::IsFlash()
\r
597 return !_tcsicmp(m_szApplicationName, _T("Flash.exe"));
\r
600 BOOL CUtils::IsPhotoshop()
\r
602 return !_tcsicmp(m_szApplicationName, _T("Photoshp.exe"));
\r
605 BOOL CUtils::IsIllustrator()
\r
607 return !_tcsicmp(m_szApplicationName, _T("Illustrator.exe"));
\r
610 BOOL CUtils::IsMicrosoftPowerPoint()
\r
612 return !_tcsicmp(m_szApplicationName, _T("PowerPnt.exe"));
\r
615 BOOL CUtils::IsReget()
\r
617 return !_tcsicmp(m_szApplicationName, _T("Regetdx.exe"))
\r
618 || !_tcsicmp(m_szApplicationName, _T("Regetjr.exe"));
\r
621 BOOL CUtils::IsPaint()
\r
623 return !_tcsicmp(m_szApplicationName, _T("mspaint.exe"));
\r
626 BOOL CUtils::IsConsole()
\r
628 // Log(_T("_%s_"), m_szApplicationName);
\r
629 return !m_szApplicationName[0]
\r
630 || !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe"))
\r
631 || !_tcsicmp(m_szApplicationName, _T("conhost.exe"))
\r
632 || !_tcsicmp(m_szApplicationName, _T("conime.exe"))
\r
633 || !_tcsicmp(m_szApplicationName, _T("csh.exe"))
\r
634 || !_tcsicmp(m_szApplicationName, _T("WINOA386.MOD"))
\r
635 || !_tcsicmp(m_szApplicationName, _T("CMD.exe"))
\r
636 || !_tcsicmp(m_szApplicationName, _T("bash.exe"))
\r
637 || !_tcsicmp(m_szApplicationName, _T("ftp.exe"))
\r
638 || !_tcsicmp(m_szApplicationName, _T("sh.exe"))
\r
639 || !_tcsicmp(m_szApplicationName, _T("telnet.exe"));
\r
642 BOOL CUtils::IsConsole(LPCTSTR szApplicationName)
\r
644 return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), MAX_PATH)
\r
645 || !_tcsnicmp(szApplicationName, _T("CMD.exe"), MAX_PATH);
\r
648 BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)
\r
650 return !_tcsnicmp(szApplicationName, _T("javaw.exe"), MAX_PATH);
\r
653 BOOL CUtils::IsSleipnir()
\r
655 return !_tcsicmp(m_szApplicationName, _T("Sleipnir.exe"));
\r
658 BOOL CUtils::IsBash()
\r
660 return !_tcsicmp(m_szApplicationName, _T("bash.exe"));
\r
664 void CUtils::Log(LPTSTR fmt, ...)
\r
669 static const int LOG_MAX = 0x10000;
\r
670 TCHAR szLog[LOG_MAX] = {'\0'};
\r
672 for (unsigned int nIndex = 0; nIndex < _tcslen(fmt); ) {
\r
673 LPTSTR pNextString = fmt + nIndex;
\r
674 LPTSTR pLogEnd = szLog + _tcslen(szLog);
\r
676 if (*pNextString == _T('%')) {
\r
677 TCHAR szFormatTag[LOG_MAX] = {'0'};
\r
678 _tcscpy(szFormatTag, pNextString);
\r
680 switch (GetFormatTag(szFormatTag)) {
\r
688 _stprintf(pLogEnd, szFormatTag, va_arg(ap, int));
\r
691 _stprintf(pLogEnd, szFormatTag, va_arg(ap, LPTSTR));
\r
698 _stprintf(pLogEnd, szFormatTag, va_arg(ap, double));
\r
701 _stprintf(pLogEnd, szFormatTag, va_arg(ap, void *));
\r
704 _stprintf(pLogEnd, szFormatTag, va_arg(ap, int *));
\r
708 _stprintf(pLogEnd, _T("%s"), szFormatTag);
\r
712 nIndex += _tcslen(szFormatTag);
\r
714 TCHAR szString[LOG_MAX] = {'0'};
\r
715 _tcscpy(szString, pNextString);
\r
716 LPTSTR pString = _tcstok(szString, _T("%"));
\r
717 _stprintf(pLogEnd, _T("%s"), pString);
\r
719 nIndex += _tcslen(pString);
\r
726 TCHAR szPath[MAX_PATH] = {'\0'};
\r
727 if (GetTempPath(MAX_PATH, szPath)) {
\r
729 _tmakepath(szPath, NULL, szPath, _T("xkeylog"), _T("txt"));
\r
731 _tmakepath(szPath, NULL, szPath, _T("xkeylog64"), _T("txt"));
\r
734 _tcscpy(szPath, _T("c:\\xkeylog.txt"));
\r
736 FILE *fp = _tfopen(szPath, _T("a"));
\r
737 _ftprintf(fp, _T("%8d: %s %s\n"), n++, m_szApplicationName, szLog);
\r
742 BOOL CUtils::IsSh()
\r
744 return !_tcsicmp(m_szApplicationName, _T("sh.exe"));
\r
747 BOOL CUtils::IsCsh()
\r
749 return !_tcsicmp(m_szApplicationName, _T("csh.exe"));
\r
752 BOOL CUtils::IsVisualStudioDotNet()
\r
754 return !_tcsicmp(m_szApplicationName, _T("devenv.exe"));
\r
757 BOOL CUtils::IsAccess()
\r
759 return !_tcsicmp(m_szApplicationName, _T("MSACCESS.EXE"));
\r
762 BOOL CUtils::IsProject()
\r
764 return !_tcsicmp(m_szApplicationName, _T("WINPROJ.EXE"));
\r
767 BOOL CUtils::IsVisualBasic()
\r
769 return !_tcsicmp(m_szApplicationName, _T("VB6.EXE"));
\r
772 BOOL CUtils::IsVisualBasicEditor()
\r
774 if (IsVisualBasic()) {
\r
780 || IsMicrosoftFrontPage()
\r
781 || IsMicrosoftPowerPoint()
\r
782 || IsMicrosoftWord()
\r
785 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
786 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
787 static LPCTSTR const szVBE = _T("Microsoft Visual Basic - ");
\r
788 if (!_tcsnicmp(szWindowText, szVBE, _tcslen(szVBE))) {
\r
795 BOOL CUtils::IsEclipse()
\r
797 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
798 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
800 LPCTSTR szEclipse = _T(" - Eclipse Platform");
\r
801 LPCTSTR szFind = _T("Find/Replace");
\r
804 && (_tcslen(szEclipse) < _tcslen(szWindowText) && !_tcsicmp(szWindowText + _tcslen(szWindowText) - _tcslen(szEclipse), szEclipse)
\r
805 || _tcslen(szFind) == _tcslen(szWindowText) && !_tcsicmp(szWindowText, szFind));
\r
808 int CUtils::GetClipboardTextLength()
\r
810 CString szClipboardText;
\r
811 CUtils::GetClipboardText(&szClipboardText);
\r
812 CUtils::SetClipboardText(&szClipboardText);
\r
814 // return sz.GetLength();
\r
817 for (int i = 0; i < szClipboardText.GetLength(); ++i) {
\r
818 if (szClipboardText.GetAt(i) & 0x80) {
\r
826 BOOL CUtils::IsDialog()
\r
828 HWND hwnd = GetForegroundWindow();
\r
829 TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
830 if (!GetWindowText(hwnd, szWindowText, sizeof(szWindowText)))
\r
831 return FALSE; // inside sound box
\r
832 return GetParent(GetForegroundWindow()) != NULL;
\r
835 int CUtils::GetFormatTag(LPTSTR szFormatTag)
\r
837 if (*(szFormatTag) != _T('%')) {
\r
841 unsigned int nIndex = 1;
\r
844 while (nIndex < _tcslen(szFormatTag)) {
\r
845 switch (*(szFormatTag + nIndex)) {
\r
861 while (_istdigit(*(szFormatTag + nIndex))) {
\r
866 if (*(szFormatTag + nIndex) == _T('.')) {
\r
868 while (_istdigit(*(szFormatTag + nIndex))) {
\r
874 switch (*(szFormatTag + nIndex)) {
\r
883 switch (*(szFormatTag + nIndex)) {
\r
900 *(szFormatTag + nIndex + 1) = NULL;
\r
901 return *(szFormatTag + nIndex);
\r
903 *(szFormatTag + nIndex) = NULL;
\r
908 BOOL CUtils::IsEudora()
\r
910 return !_tcsicmp(m_szApplicationName, _T("Eudora.exe"));
\r
913 BOOL CUtils::IsCodeWarrior()
\r
915 return !_tcsicmp(m_szApplicationName, _T("IDE.exe"));
\r
918 BOOL CUtils::IseMemoPad()
\r
920 return !_tcsicmp(m_szApplicationName, _T("eMemoPad.exe"));
\r
923 BOOL CUtils::IsStoryEditor()
\r
925 return !_tcsicmp(m_szApplicationName, _T("STRYEDIT.EXE"));
\r
928 BOOL CUtils::IsNami2000()
\r
930 return !_tcsicmp(m_szApplicationName, _T("Nami2000.exe"));
\r
933 BOOL CUtils::IsCorelDRAW()
\r
935 return !_tcsicmp(m_szApplicationName, _T("CorelDrw.exe"));
\r
938 // If Clipboard data is empty, return ture.
\r
939 // You must CopyNextCharacter in previous step.
\r
940 // Clipboard data is destroyed.
\r
941 BOOL CUtils::IsEOF()
\r
943 return IsTOForEOF();
\r
946 // If Clipboard data is empty, return ture.
\r
947 // You must CopyBackCharacter in previous step.
\r
948 // Clipboard data is destroyed.
\r
949 BOOL CUtils::IsTOF()
\r
951 return IsTOForEOF();
\r
954 BOOL CUtils::IsTOForEOF()
\r
956 CString szClipboardText;
\r
957 GetClipboardText(&szClipboardText);
\r
958 return szClipboardText.IsEmpty() // for normal application
\r
959 || szClipboardText.GetLength() >= 3; // for VC++
\r
962 BOOL CUtils::IsHusen()
\r
964 return !_tcsicmp(m_szApplicationName, _T("husen.exe"));
\r
967 BOOL CUtils::IsAdobeReader()
\r
969 return !_tcsicmp(m_szApplicationName, _T("AcroRd32.exe"));
\r
972 BOOL CUtils::IsOpenOffice()
\r
974 return !_tcsicmp(m_szApplicationName, _T("soffice.exe"))
\r
975 || !_tcsicmp(m_szApplicationName, _T("soffice.bin"));
\r
978 BOOL CUtils::IsTuruKameMail()
\r
980 return !_tcsicmp(m_szApplicationName, _T("TuruKame.exe"));
\r
983 BOOL CUtils::IsOedit()
\r
985 return !_tcsicmp(m_szApplicationName, _T("oedit.exe"));
\r
988 BOOL CUtils::IsAutla()
\r
990 return !_tcsicmp(m_szApplicationName, _T("Autla.exe"));
\r
993 BOOL CUtils::IsShuriken()
\r
995 return !_tcsicmp(m_szApplicationName, _T("JsvMail.exe"));
\r
998 BOOL CUtils::IsEdLeaf()
\r
1000 return !_tcsicmp(m_szApplicationName, _T("edleaf.exe"));
\r
1003 BOOL CUtils::IsJmEditor()
\r
1005 return !_tcsicmp(m_szApplicationName, _T("JmEdit.exe"))
\r
1006 || !_tcsicmp(m_szApplicationName, _T("JmEdit2.exe"));
\r
1009 BOOL CUtils::IsDana()
\r
1011 return !_tcsicmp(m_szApplicationName, _T("Dana.exe"));
\r
1014 BOOL CUtils::IsIPMessenger()
\r
1016 return !_tcsicmp(m_szApplicationName, _T("ipmsg.exe"));
\r
1019 BOOL CUtils::IsezHTML()
\r
1021 return !_tcsicmp(m_szApplicationName, _T("ezhtml.exe"));
\r
1024 BOOL CUtils::IsTcsh()
\r
1026 return !_tcsicmp(m_szApplicationName, _T("tcsh.exe"));
\r
1029 BOOL CUtils::IsZsh()
\r
1031 return !_tcsicmp(m_szApplicationName, _T("zsh.exe"));
\r
1034 BOOL CUtils::IsPdksh()
\r
1036 return !_tcsicmp(m_szApplicationName, _T("pdksh.exe"));
\r
1039 BOOL CUtils::IsFirefox()
\r
1041 return !_tcsicmp(m_szApplicationName, _T("firefox.exe"));
\r
1044 BOOL CUtils::IsPHPEditor()
\r
1046 return !_tcsicmp(m_szApplicationName, _T("php_editor.exe"));
\r
1049 BOOL CUtils::IsTeraPad()
\r
1051 return !_tcsicmp(m_szApplicationName, _T("TeraPad.exe"));
\r
1054 BOOL CUtils::IsLispWorksPersonalEdition()
\r
1056 CString szLispWorks(_T("lispworks-personal-"));
\r
1057 return !_tcsnicmp(m_szApplicationName, szLispWorks, szLispWorks.GetLength());
\r
1059 // return !_tcsicmp(m_szApplicationName, _T("lispworks-personal-4300.exe"));
\r
1062 BOOL CUtils::IsBorlandCppBuilder()
\r
1064 return !_tcsicmp(m_szApplicationName, _T("bcb.exe"));
\r
1067 BOOL CUtils::Run(CString szCommandLine, BOOL isWait)
\r
1070 ZeroMemory(&si, sizeof(si));
\r
1071 si.cb = sizeof(si);
\r
1073 PROCESS_INFORMATION pi;
\r
1074 ZeroMemory(&pi, sizeof(pi));
\r
1076 BOOL rc = CreateProcess(NULL, szCommandLine.GetBuffer(szCommandLine.GetLength() + 1), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
\r
1079 WaitForSingleObject( pi.hProcess, INFINITE );
\r
1082 CloseHandle(pi.hThread);
\r
1083 CloseHandle(pi.hProcess);
\r
1089 BOOL CUtils::IsJavaW()
\r
1091 return !_tcsicmp(m_szApplicationName, _T("javaw.exe"));
\r
1094 BOOL CUtils::IsMSDN()
\r
1096 return !_tcsicmp(m_szApplicationName, _T("hh.exe"));
\r
1099 BOOL CUtils::IsVisualSlickEdit()
\r
1101 return !_tcsicmp(m_szApplicationName, _T("vs.exe"));
\r
1104 void CUtils::PrintWindowInfo(WINDOWINFO *pwi)
\r
1106 Log(_T("windowinfo.cbSize: %d"), pwi->cbSize);
\r
1107 Log(_T("windowinfo.rcWindow.top: %d"), pwi->rcWindow.top);
\r
1108 Log(_T("windowinfo.rcWindow.bottom: %d"), pwi->rcWindow.bottom);
\r
1109 Log(_T("windowinfo.rcWindow.left: %d"), pwi->rcWindow.left);
\r
1110 Log(_T("windowinfo.rcWindow.right: %d"), pwi->rcWindow.right);
\r
1111 Log(_T("windowinfo.rcClient.top: %d"), pwi->rcClient.top);
\r
1112 Log(_T("windowinfo.rcClient.bottom: %d"), pwi->rcClient.bottom);
\r
1113 Log(_T("windowinfo.rcClient.left: %d"), pwi->rcClient.left);
\r
1114 Log(_T("windowinfo.rcClient.right: %d"), pwi->rcClient.right);
\r
1115 Log(_T("windowinfo.dwStyle: %d"), pwi->dwStyle);
\r
1116 Log(_T("windowinfo.dwExStyle: %d"), pwi->dwExStyle);
\r
1117 Log(_T("windowinfo.dwWindowStatus: %d"), pwi->dwWindowStatus);
\r
1118 Log(_T("windowinfo.cxWindowBorders: %d"), pwi->cxWindowBorders);
\r
1119 Log(_T("windowinfo.cyWindowBorders: %d"), pwi->cyWindowBorders);
\r
1120 Log(_T("windowinfo.atomWindowType: %d"), pwi->atomWindowType);
\r
1121 Log(_T("windowinfo.wCreatorVersion: %d"), pwi->wCreatorVersion);
\r
1124 BOOL CUtils::IsOpenJane()
\r
1126 return !_tcsicmp(m_szApplicationName, _T("Jane2ch.exe"));
\r
1129 BOOL CUtils::UpdateKeyboardState(BYTE bVk, BYTE bState)
\r
1131 BYTE ks[256] = {'\0'};
\r
1134 if ((rc = GetKeyboardState(ks)) != FALSE) {
\r
1136 rc = SetKeyboardState(ks);
\r
1141 BOOL CUtils::IsThunderbird()
\r
1143 return !_tcsicmp(m_szApplicationName, _T("thunderbird.exe"));
\r
1146 int CUtils::GetWindowTextType(CString strWindowText)
\r
1148 int nWindowTextType = IDS_WINDOW_TEXT_IGNORE;
\r
1150 if (3 <= strWindowText.GetLength()
\r
1151 && strWindowText.Find(_T('*')) == 0
\r
1152 && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {
\r
1153 nWindowTextType = IDS_WINDOW_TEXT_MATCH;
\r
1154 } else if (2 <= strWindowText.GetLength()
\r
1155 && strWindowText.Find(_T('*')) != 0
\r
1156 && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {
\r
1157 nWindowTextType = IDS_WINDOW_TEXT_MATCH_FORWARD;
\r
1158 } else if (2 <= strWindowText.GetLength()
\r
1159 && strWindowText.Find(_T('*')) == 0
\r
1160 && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {
\r
1161 nWindowTextType = IDS_WINDOW_TEXT_MATCH_BACKWARD;
\r
1162 } else if (!strWindowText.IsEmpty()
\r
1163 && strWindowText.Find(_T('*')) != 0
\r
1164 && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {
\r
1165 nWindowTextType = IDS_WINDOW_TEXT_MATCH_FULL;
\r
1168 return nWindowTextType;
\r
1171 BOOL CUtils::IsLunascape()
\r
1173 return !_tcsicmp(m_szApplicationName, _T("Luna.exe"));
\r
1176 BOOL CUtils::IsAtok()
\r
1178 return !_tcsnicmp(m_szApplicationName, _T("ATOK"), 4) && !_tcsnicmp(m_szApplicationName + _tcslen(m_szApplicationName) - 4, _T(".IME"), 4);
\r