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[0x100] = {'\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, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength)
\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, nWindowTextLength - nApplicationName);
\r
211 } else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo
\r
212 LPTSTR pFirstSpace = _tcschr(szWindowText, _T(' '));
\r
213 memset(pFirstSpace, 0, nWindowTextLength - (pFirstSpace - szWindowText));
\r
216 memset(szApplicationName, 0, nApplicationNameLength);
\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, const int nApplicationNameLength, LPTSTR szWindowText, const int nWindowTextLength)
\r
228 if (IsConsole(szApplicationName, nApplicationNameLength)) {
\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[0x100] = {'\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, nApplicationNameLength, szWindowText, nWindowTextLength);
\r
252 for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {
\r
253 TCHAR szWindowTextLower[0x100] = {'\0'};
\r
254 _tcscpy(szWindowTextLower, szWindowText);
\r
255 _tcslwr(szWindowTextLower);
\r
257 if (_tcsstr(szWindowTextLower, szPromptPath[i])) {
\r
258 TCHAR sz[0x100] = {'\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, nApplicationNameLength, szWindowText, nWindowTextLength);
\r
265 } else { // "X:\WINNT\system32\cmd.exe"
\r
271 if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))
\r
272 || (*szWindowText == _T('~'))
\r
273 || (*szWindowText == _T('/'))) { // Bash
\r
274 memset(szApplicationName, 0, nApplicationNameLength);
\r
275 _stprintf(szApplicationName, _T("bash.exe"));
\r
276 memset(szWindowText, 0, nWindowTextLength);
\r
277 _stprintf(szWindowText, _T("bash"));
\r
278 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) {
\r
279 memset(szApplicationName, 0, nApplicationNameLength);
\r
280 _stprintf(szApplicationName, _T("pdksh.exe"));
\r
281 memset(szWindowText, 0, nWindowTextLength);
\r
282 _stprintf(szWindowText, _T("pdksh"));
\r
283 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) {
\r
284 memset(szApplicationName, 0, nApplicationNameLength);
\r
285 _stprintf(szApplicationName, _T("tcsh.exe"));
\r
286 memset(szWindowText, 0, nWindowTextLength);
\r
287 _stprintf(szWindowText, _T("tcsh"));
\r
288 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) {
\r
289 memset(szApplicationName, 0, nApplicationNameLength);
\r
290 _stprintf(szApplicationName, _T("zsh.exe"));
\r
291 memset(szWindowText, 0, nWindowTextLength);
\r
292 _stprintf(szWindowText, _T("zsh"));
\r
293 } else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14)
\r
294 || !_tcsnicmp(szWindowText, _T("cat"), 3)) {
\r
295 memset(szApplicationName, 0, nApplicationNameLength);
\r
296 _stprintf(szApplicationName, _T("sh.exe"));
\r
297 memset(szWindowText, 0, nWindowTextLength);
\r
298 _stprintf(szWindowText, _T("MKS Korn Shell"));
\r
299 } else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2)
\r
300 || !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) {
\r
301 memset(szApplicationName, 0, nApplicationNameLength);
\r
302 _stprintf(szApplicationName, _T("csh.exe"));
\r
303 memset(szWindowText, 0, nWindowTextLength);
\r
304 _stprintf(szWindowText, _T("C Shell"));
\r
305 } else if (_tcsstr(szWindowText, _T(" - VIM"))) {
\r
306 memset(szApplicationName, 0, nApplicationNameLength);
\r
307 _stprintf(szApplicationName, _T("vim.exe"));
\r
308 memset(szWindowText, 0, nWindowTextLength);
\r
309 _stprintf(szWindowText, _T("VIM"));
\r
310 } else if (_tcsstr(szWindowText, _T(" - Poderosa"))) {
\r
311 memset(szApplicationName, 0, nApplicationNameLength);
\r
312 _stprintf(szApplicationName, _T("Poderosa.exe"));
\r
313 memset(szWindowText, 0, nWindowTextLength);
\r
314 _stprintf(szWindowText, _T("Poderosa"));
\r
315 } else { // unknown console application
\r
316 FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);
\r
318 } else if (IsJavaW(szApplicationName, nApplicationNameLength)) {
\r
319 if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) {
\r
320 memset(szApplicationName, 0, nApplicationNameLength);
\r
321 _stprintf(szApplicationName, _T("eclipse.exe"));
\r
322 } else if (!_tcsicmp(szWindowText, _T("BlueJ"))
\r
323 || !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) {
\r
324 memset(szApplicationName, 0, nApplicationNameLength);
\r
325 _stprintf(szApplicationName, _T("bluej.exe"));
\r
326 } else if (!_tcsicmp(szWindowText, _T("JUDE"))
\r
327 || !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) {
\r
328 memset(szApplicationName, 0, nApplicationNameLength);
\r
329 _stprintf(szApplicationName, _T("jude.exe"));
\r
335 void CUtils::SetApplicationName(BOOL bImeComposition)
\r
337 // CUtils::Log(_T("SetApplicationName: start"));
\r
339 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
341 if (_tcscmp(m_szIMEName, _T("IME")) == 0) { // IDS_IME_FILE_NAME
\r
342 HKL hKL = GetKeyboardLayout(0);
\r
343 if (ImmIsIME(hKL)) {
\r
344 if (!ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName))) {
\r
345 _tcsncpy(m_szIMEName, _T("IME"), sizeof(m_szIMEName)); // IDS_IME_FILE_NAME
\r
347 // CUtils::Log(_T("SetApplicationName: m_szIMEName == %s"), m_szIMEName);
\r
351 if (bImeComposition) {
\r
352 // CUtils::Log(_T("SetApplicationName: bImeComposition"));
\r
354 HKL hKL = GetKeyboardLayout(0);
\r
355 if (ImmIsIME(hKL)) {
\r
356 if (!ImmGetIMEFileName(hKL, m_szApplicationName, sizeof(m_szApplicationName))) {
\r
357 _tcsncpy(m_szApplicationName, m_szIMEName, sizeof(m_szApplicationName));
\r
359 _tcsncpy(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));
\r
361 // ImmIsIME return 0 on Word2002, Excel2002, etc. with IME2002, so...
\r
362 // _tcsncpy(m_szApplicationName, _T("imjp81.ime"), sizeof(m_szApplicationName));
\r
363 _tcsncpy(m_szApplicationName, m_szIMEName, sizeof(m_szApplicationName));
\r
366 // CUtils::Log(_T("SetApplicationName: appication (%s)"), m_szApplicationName);
\r
368 GetModuleFileName(NULL, m_szApplicationName, sizeof(m_szApplicationName));
\r
369 CString szFn(m_szApplicationName);
\r
370 szFn.Delete(0, szFn.ReverseFind(_T('\\')) + 1);
\r
371 ZeroMemory(m_szApplicationName, sizeof(m_szApplicationName));
\r
372 _tcsncpy(m_szApplicationName, szFn, szFn.GetLength());
\r
374 // CUtils::Log(_T("SetApplicationName: appication [%s]"), m_szApplicationName);
\r
377 // CUtils::Log(_T("SetApplicationName: console"));
\r
379 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
381 _tcscpy(m_szApplicationName, _T("CMD.exe"));
\r
383 _tcscpy(m_szApplicationName, _T("WINOA386.MOD"));
\r
385 TCHAR szWindowText[0x100] = {'\0'};
\r
386 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
387 SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText));
\r
388 } else if (IsJavaW()) {
\r
389 TCHAR szWindowText[0x100] = {'\0'};
\r
390 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
391 SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText));
\r
393 if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {
\r
394 // CUtils::Log(_T("SetApplicationName: cygwin"));
\r
396 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
\r
397 _tcscpy(m_szApplicationName, _T("bash.exe"));
\r
399 // CUtils::Log(_T("name: %s"), m_szApplicationName);
\r
403 void CUtils::SetIMEName()
\r
405 HKL hKL = GetKeyboardLayout(0);
\r
406 if (ImmIsIME(hKL)) {
\r
407 ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName));
\r
411 void CUtils::InitCUtils()
\r
413 GetVersionEx(&m_OsVersionInfo);
\r
417 BOOL CUtils::IsNTor9x()
\r
419 return ((m_OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && (m_OsVersionInfo.dwMajorVersion <= 4))
\r
420 || (m_OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
\r
423 BOOL CUtils::IsXPorLater()
\r
425 return 5 < m_OsVersionInfo.dwMajorVersion
\r
426 || 5 == m_OsVersionInfo.dwMajorVersion && 1 <= m_OsVersionInfo.dwMinorVersion;
\r
429 BOOL CUtils::IsNT()
\r
431 return m_OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
\r
434 BOOL CUtils::OpenClipboard()
\r
436 const int RETRY_COUNT = 0x10;
\r
438 BOOL bOpened = FALSE;
\r
439 for (int i = 0; i <= RETRY_COUNT; ++i) {
\r
440 if (::OpenClipboard(NULL)) {
\r
441 // Log(_T("ok (%d)"), i);
\r
445 Sleep(1); // for OpenOffice
\r
446 // Log(_T("CUtils::OpenClipboard: %d (%d)"), GetLastError(), i);
\r
453 BOOL CUtils::GetClipboardText(CString *szClipboardText)
\r
455 if (!szClipboardText) {
\r
459 szClipboardText->Empty();
\r
461 if (!OpenClipboard()) {
\r
462 // CUtils::Log(_T("Cannot open the Clipboard"));
\r
468 Log(_T("GetClipboardText"));
\r
471 uFormat = EnumClipboardFormats(uFormat);
\r
473 Log(_T("uFormat = %d"), uFormat);
\r
479 //#define CF_TEXT 1
\r
480 //#define CF_METAFILEPICT 3
\r
481 //#define CF_OEMTEXT 7
\r
482 //#define CF_UNICODETEXT 13
\r
483 //#define CF_ENHMETAFILE 14
\r
484 //#define CF_LOCALE 16
\r
485 //#define CF_DSPTEXT 0x0081
\r
488 // DataObject 49161
\r
489 // Embed Source 49163
\r
490 // Object Descriptor 49166
\r
491 // Ole Private Data 49171
\r
492 // Rich Text Format 49311
\r
493 // Rich Text Format 49312
\r
494 // HTML Format 49360
\r
495 // HTML Format 49361
\r
497 // RTF As Text 49595
\r
498 // Rich Text Format Without Objects 49618
\r
499 // Star Object Descriptor (XML) 49681
\r
500 // Star Embed Source (XML) 49708
\r
501 // HPB HTML Format 49742
\r
505 UINT uFormat = CF_OEMTEXT;
\r
506 if (IsSakuraEditor()) {
\r
510 HANDLE hClipboardText;
\r
511 if ((hClipboardText = ::GetClipboardData(uFormat)) == NULL) {
\r
512 // DWORD dw = GetLastError();
\r
513 // CUtils::Log(_T("Unable to get Clipboard data: %d"), dw);
\r
518 szClipboardText->Format(_T("%s"), hClipboardText);
\r
524 BOOL CUtils::SetClipboardText(CString *szClipboardText)
\r
526 if (!OpenClipboard()) {
\r
527 // CUtils::Log(_T("Cannot open the Clipboard in SetClipboardText"));
\r
531 int nLength = szClipboardText->GetLength() + 1;
\r
532 HGLOBAL hClipboardText = GlobalAlloc(GHND, nLength);
\r
533 if (hClipboardText == NULL) {
\r
534 // CUtils::Log(_T("Failed: GlobalAlloc in SetClipboardText"));
\r
538 LPTSTR lpStr = (LPTSTR)GlobalLock(hClipboardText);
\r
539 lstrcpyn(lpStr, *szClipboardText, nLength);
\r
540 GlobalUnlock(hClipboardText);
\r
543 UINT uFormat = CF_OEMTEXT;
\r
544 if (IsSakuraEditor()) {
\r
548 if ((hClipboardText = ::SetClipboardData(uFormat, hClipboardText)) == NULL) {
\r
549 // DWORD dw = GetLastError();
\r
550 // CUtils::Log(_T("Unable to set Clipboard data: %d"), dw);
\r
559 BOOL CUtils::IsDefaultIgnoreApplication()
\r
565 || IsLispWorksPersonalEdition()
\r
567 || IsMuleForWin32()
\r
571 || IsTeraTermPro() && !IsDialog()
\r
572 || IsVisualSlickEdit() && !IsDialog()
\r
574 || IsXyzzy() && !IsDialog()
\r
581 BOOL CUtils::IsDWFM()
\r
583 return !_tcsicmp(m_szApplicationName, _T("dwfm.exe"));
\r
586 BOOL CUtils::IsK2Editor()
\r
588 return !_tcsicmp(m_szApplicationName, _T("K2Editor.exe"));
\r
591 BOOL CUtils::IsEggExplorer()
\r
593 return !_tcsicmp(m_szApplicationName, _T("EggExp.exe"));
\r
596 BOOL CUtils::IsDirector()
\r
598 return !_tcsicmp(m_szApplicationName, _T("Director.exe"));
\r
601 BOOL CUtils::IsExcel()
\r
603 return !_tcsicmp(m_szApplicationName, _T("Excel.exe"));
\r
606 BOOL CUtils::IsFireworks()
\r
608 return !_tcsicmp(m_szApplicationName, _T("Fireworks 4.exe"))
\r
609 || !_tcsicmp(m_szApplicationName, _T("Fireworks.exe"));
\r
612 BOOL CUtils::IsDreamweaver()
\r
614 return !_tcsicmp(m_szApplicationName, _T("Dreamweaver.exe"));
\r
617 BOOL CUtils::IsFlash()
\r
619 return !_tcsicmp(m_szApplicationName, _T("Flash.exe"));
\r
622 BOOL CUtils::IsPhotoshop()
\r
624 return !_tcsicmp(m_szApplicationName, _T("Photoshp.exe"));
\r
627 BOOL CUtils::IsIllustrator()
\r
629 return !_tcsicmp(m_szApplicationName, _T("Illustrator.exe"));
\r
632 BOOL CUtils::IsMicrosoftPowerPoint()
\r
634 return !_tcsicmp(m_szApplicationName, _T("PowerPnt.exe"));
\r
637 BOOL CUtils::IsReget()
\r
639 return !_tcsicmp(m_szApplicationName, _T("Regetdx.exe"))
\r
640 || !_tcsicmp(m_szApplicationName, _T("Regetjr.exe"));
\r
643 BOOL CUtils::IsPaint()
\r
645 return !_tcsicmp(m_szApplicationName, _T("mspaint.exe"));
\r
648 BOOL CUtils::IsConsole()
\r
650 // Log(_T("_%s_"), m_szApplicationName);
\r
651 return !m_szApplicationName[0]
\r
652 || !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe"))
\r
653 || !_tcsicmp(m_szApplicationName, _T("conhost.exe"))
\r
654 || !_tcsicmp(m_szApplicationName, _T("conime.exe"))
\r
655 || !_tcsicmp(m_szApplicationName, _T("csh.exe"))
\r
656 || !_tcsicmp(m_szApplicationName, _T("WINOA386.MOD"))
\r
657 || !_tcsicmp(m_szApplicationName, _T("CMD.exe"))
\r
658 || !_tcsicmp(m_szApplicationName, _T("bash.exe"))
\r
659 || !_tcsicmp(m_szApplicationName, _T("ftp.exe"))
\r
660 || !_tcsicmp(m_szApplicationName, _T("sh.exe"))
\r
661 || !_tcsicmp(m_szApplicationName, _T("telnet.exe"));
\r
664 BOOL CUtils::IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength)
\r
666 return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), nApplicationNameLength)
\r
667 || !_tcsnicmp(szApplicationName, _T("CMD.exe"), nApplicationNameLength);
\r
670 BOOL CUtils::IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength)
\r
672 return !_tcsnicmp(szApplicationName, _T("javaw.exe"), nApplicationNameLength);
\r
675 BOOL CUtils::IsSleipnir()
\r
677 return !_tcsicmp(m_szApplicationName, _T("Sleipnir.exe"));
\r
680 BOOL CUtils::IsBash()
\r
682 return !_tcsicmp(m_szApplicationName, _T("bash.exe"));
\r
686 void CUtils::Log(LPTSTR fmt, ...)
\r
691 static const int LOG_MAX = 0x10000;
\r
692 TCHAR szLog[LOG_MAX] = {'\0'};
\r
694 for (unsigned int nIndex = 0; nIndex < _tcslen(fmt); ) {
\r
695 LPTSTR pNextString = fmt + nIndex;
\r
696 LPTSTR pLogEnd = szLog + _tcslen(szLog);
\r
698 if (*pNextString == _T('%')) {
\r
699 TCHAR szFormatTag[LOG_MAX] = {'0'};
\r
700 _tcscpy(szFormatTag, pNextString);
\r
702 switch (GetFormatTag(szFormatTag)) {
\r
710 _stprintf(pLogEnd, szFormatTag, va_arg(ap, int));
\r
713 _stprintf(pLogEnd, szFormatTag, va_arg(ap, LPTSTR));
\r
720 _stprintf(pLogEnd, szFormatTag, va_arg(ap, double));
\r
723 _stprintf(pLogEnd, szFormatTag, va_arg(ap, void *));
\r
726 _stprintf(pLogEnd, szFormatTag, va_arg(ap, int *));
\r
730 _stprintf(pLogEnd, _T("%s"), szFormatTag);
\r
734 nIndex += _tcslen(szFormatTag);
\r
736 TCHAR szString[LOG_MAX] = {'0'};
\r
737 _tcscpy(szString, pNextString);
\r
738 LPTSTR pString = _tcstok(szString, _T("%"));
\r
739 _stprintf(pLogEnd, _T("%s"), pString);
\r
741 nIndex += _tcslen(pString);
\r
748 TCHAR szPath[MAX_PATH] = {'\0'};
\r
749 if (SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, TRUE)) {
\r
750 _tmakepath(szPath, NULL, szPath, _T("xkeylog"), _T("txt"));
\r
752 _tcscpy(szPath, _T("c:\\xkeylog.txt"));
\r
754 FILE *fp = _tfopen(szPath, _T("a"));
\r
755 _ftprintf(fp, _T("%8d: %s %s\n"), n++, m_szApplicationName, szLog);
\r
760 BOOL CUtils::IsSh()
\r
762 return !_tcsicmp(m_szApplicationName, _T("sh.exe"));
\r
765 BOOL CUtils::IsCsh()
\r
767 return !_tcsicmp(m_szApplicationName, _T("csh.exe"));
\r
770 BOOL CUtils::IsVisualStudioDotNet()
\r
772 return !_tcsicmp(m_szApplicationName, _T("devenv.exe"));
\r
775 BOOL CUtils::IsAccess()
\r
777 return !_tcsicmp(m_szApplicationName, _T("MSACCESS.EXE"));
\r
780 BOOL CUtils::IsProject()
\r
782 return !_tcsicmp(m_szApplicationName, _T("WINPROJ.EXE"));
\r
785 BOOL CUtils::IsVisualBasic()
\r
787 return !_tcsicmp(m_szApplicationName, _T("VB6.EXE"));
\r
790 BOOL CUtils::IsVisualBasicEditor()
\r
792 if (IsVisualBasic()) {
\r
798 || IsMicrosoftFrontPage()
\r
799 || IsMicrosoftPowerPoint()
\r
800 || IsMicrosoftWord()
\r
803 TCHAR szWindowText[0x100] = {'\0'};
\r
804 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
805 static LPCTSTR const szVBE = _T("Microsoft Visual Basic - ");
\r
806 if (!_tcsnicmp(szWindowText, szVBE, _tcslen(szVBE))) {
\r
813 BOOL CUtils::IsEclipse()
\r
815 TCHAR szWindowText[0x100] = {'\0'};
\r
816 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
\r
818 LPCTSTR szEclipse = _T(" - Eclipse Platform");
\r
819 LPCTSTR szFind = _T("Find/Replace");
\r
822 && (_tcslen(szEclipse) < _tcslen(szWindowText) && !_tcsicmp(szWindowText + _tcslen(szWindowText) - _tcslen(szEclipse), szEclipse)
\r
823 || _tcslen(szFind) == _tcslen(szWindowText) && !_tcsicmp(szWindowText, szFind));
\r
826 int CUtils::GetClipboardTextLength()
\r
828 CString szClipboardText;
\r
829 CUtils::GetClipboardText(&szClipboardText);
\r
830 CUtils::SetClipboardText(&szClipboardText);
\r
832 // return sz.GetLength();
\r
835 for (int i = 0; i < szClipboardText.GetLength(); ++i) {
\r
836 if (szClipboardText.GetAt(i) & 0x80) {
\r
844 BOOL CUtils::IsDialog()
\r
846 HWND hwnd = GetForegroundWindow();
\r
847 TCHAR szWindowText[0x100] = {'\0'};
\r
848 if (!GetWindowText(hwnd, szWindowText, sizeof(szWindowText)))
\r
849 return FALSE; // inside sound box
\r
850 return GetParent(GetForegroundWindow()) != NULL;
\r
853 int CUtils::GetFormatTag(LPTSTR szFormatTag)
\r
855 if (*(szFormatTag) != _T('%')) {
\r
859 unsigned int nIndex = 1;
\r
862 while (nIndex < _tcslen(szFormatTag)) {
\r
863 switch (*(szFormatTag + nIndex)) {
\r
879 while (_istdigit(*(szFormatTag + nIndex))) {
\r
884 if (*(szFormatTag + nIndex) == _T('.')) {
\r
886 while (_istdigit(*(szFormatTag + nIndex))) {
\r
892 switch (*(szFormatTag + nIndex)) {
\r
901 switch (*(szFormatTag + nIndex)) {
\r
918 *(szFormatTag + nIndex + 1) = NULL;
\r
919 return *(szFormatTag + nIndex);
\r
921 *(szFormatTag + nIndex) = NULL;
\r
926 BOOL CUtils::IsEudora()
\r
928 return !_tcsicmp(m_szApplicationName, _T("Eudora.exe"));
\r
931 BOOL CUtils::IsCodeWarrior()
\r
933 return !_tcsicmp(m_szApplicationName, _T("IDE.exe"));
\r
936 BOOL CUtils::IseMemoPad()
\r
938 return !_tcsicmp(m_szApplicationName, _T("eMemoPad.exe"));
\r
941 BOOL CUtils::IsStoryEditor()
\r
943 return !_tcsicmp(m_szApplicationName, _T("STRYEDIT.EXE"));
\r
946 BOOL CUtils::IsNami2000()
\r
948 return !_tcsicmp(m_szApplicationName, _T("Nami2000.exe"));
\r
951 BOOL CUtils::IsCorelDRAW()
\r
953 return !_tcsicmp(m_szApplicationName, _T("CorelDrw.exe"));
\r
956 // If Clipboard data is empty, return ture.
\r
957 // You must CopyNextCharacter in previous step.
\r
958 // Clipboard data is destroyed.
\r
959 BOOL CUtils::IsEOF()
\r
961 return IsTOForEOF();
\r
964 // If Clipboard data is empty, return ture.
\r
965 // You must CopyBackCharacter in previous step.
\r
966 // Clipboard data is destroyed.
\r
967 BOOL CUtils::IsTOF()
\r
969 return IsTOForEOF();
\r
972 BOOL CUtils::IsTOForEOF()
\r
974 CString szClipboardText;
\r
975 GetClipboardText(&szClipboardText);
\r
976 return szClipboardText.IsEmpty() // for normal application
\r
977 || szClipboardText.GetLength() >= 3; // for VC++
\r
980 BOOL CUtils::IsHusen()
\r
982 return !_tcsicmp(m_szApplicationName, _T("husen.exe"));
\r
985 BOOL CUtils::IsAdobeReader()
\r
987 return !_tcsicmp(m_szApplicationName, _T("AcroRd32.exe"));
\r
990 BOOL CUtils::IsOpenOffice()
\r
992 return !_tcsicmp(m_szApplicationName, _T("soffice.exe"))
\r
993 || !_tcsicmp(m_szApplicationName, _T("soffice.bin"));
\r
996 BOOL CUtils::IsTuruKameMail()
\r
998 return !_tcsicmp(m_szApplicationName, _T("TuruKame.exe"));
\r
1001 BOOL CUtils::IsOedit()
\r
1003 return !_tcsicmp(m_szApplicationName, _T("oedit.exe"));
\r
1006 BOOL CUtils::IsAutla()
\r
1008 return !_tcsicmp(m_szApplicationName, _T("Autla.exe"));
\r
1011 BOOL CUtils::IsShuriken()
\r
1013 return !_tcsicmp(m_szApplicationName, _T("JsvMail.exe"));
\r
1016 BOOL CUtils::IsEdLeaf()
\r
1018 return !_tcsicmp(m_szApplicationName, _T("edleaf.exe"));
\r
1021 BOOL CUtils::IsJmEditor()
\r
1023 return !_tcsicmp(m_szApplicationName, _T("JmEdit.exe"))
\r
1024 || !_tcsicmp(m_szApplicationName, _T("JmEdit2.exe"));
\r
1027 BOOL CUtils::IsDana()
\r
1029 return !_tcsicmp(m_szApplicationName, _T("Dana.exe"));
\r
1032 BOOL CUtils::IsIPMessenger()
\r
1034 return !_tcsicmp(m_szApplicationName, _T("ipmsg.exe"));
\r
1037 BOOL CUtils::IsezHTML()
\r
1039 return !_tcsicmp(m_szApplicationName, _T("ezhtml.exe"));
\r
1042 BOOL CUtils::IsTcsh()
\r
1044 return !_tcsicmp(m_szApplicationName, _T("tcsh.exe"));
\r
1047 BOOL CUtils::IsZsh()
\r
1049 return !_tcsicmp(m_szApplicationName, _T("zsh.exe"));
\r
1052 BOOL CUtils::IsPdksh()
\r
1054 return !_tcsicmp(m_szApplicationName, _T("pdksh.exe"));
\r
1057 BOOL CUtils::IsFirefox()
\r
1059 return !_tcsicmp(m_szApplicationName, _T("firefox.exe"));
\r
1062 BOOL CUtils::IsPHPEditor()
\r
1064 return !_tcsicmp(m_szApplicationName, _T("php_editor.exe"));
\r
1067 BOOL CUtils::IsTeraPad()
\r
1069 return !_tcsicmp(m_szApplicationName, _T("TeraPad.exe"));
\r
1072 BOOL CUtils::IsLispWorksPersonalEdition()
\r
1074 CString szLispWorks(_T("lispworks-personal-"));
\r
1075 return !_tcsnicmp(m_szApplicationName, szLispWorks, szLispWorks.GetLength());
\r
1077 // return !_tcsicmp(m_szApplicationName, _T("lispworks-personal-4300.exe"));
\r
1080 BOOL CUtils::IsBorlandCppBuilder()
\r
1082 return !_tcsicmp(m_szApplicationName, _T("bcb.exe"));
\r
1085 BOOL CUtils::Run(CString szCommandLine, BOOL isWait)
\r
1088 ZeroMemory(&si, sizeof(si));
\r
1089 si.cb = sizeof(si);
\r
1091 PROCESS_INFORMATION pi;
\r
1092 ZeroMemory(&pi, sizeof(pi));
\r
1094 BOOL rc = CreateProcess(NULL, szCommandLine.GetBuffer(szCommandLine.GetLength() + 1), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
\r
1097 WaitForSingleObject( pi.hProcess, INFINITE );
\r
1100 CloseHandle(pi.hThread);
\r
1101 CloseHandle(pi.hProcess);
\r
1107 BOOL CUtils::IsJavaW()
\r
1109 return !_tcsicmp(m_szApplicationName, _T("javaw.exe"));
\r
1112 BOOL CUtils::IsMSDN()
\r
1114 return !_tcsicmp(m_szApplicationName, _T("hh.exe"));
\r
1117 BOOL CUtils::IsVisualSlickEdit()
\r
1119 return !_tcsicmp(m_szApplicationName, _T("vs.exe"));
\r
1122 void CUtils::PrintWindowInfo(WINDOWINFO *pwi)
\r
1124 Log(_T("windowinfo.cbSize: %d"), pwi->cbSize);
\r
1125 Log(_T("windowinfo.rcWindow.top: %d"), pwi->rcWindow.top);
\r
1126 Log(_T("windowinfo.rcWindow.bottom: %d"), pwi->rcWindow.bottom);
\r
1127 Log(_T("windowinfo.rcWindow.left: %d"), pwi->rcWindow.left);
\r
1128 Log(_T("windowinfo.rcWindow.right: %d"), pwi->rcWindow.right);
\r
1129 Log(_T("windowinfo.rcClient.top: %d"), pwi->rcClient.top);
\r
1130 Log(_T("windowinfo.rcClient.bottom: %d"), pwi->rcClient.bottom);
\r
1131 Log(_T("windowinfo.rcClient.left: %d"), pwi->rcClient.left);
\r
1132 Log(_T("windowinfo.rcClient.right: %d"), pwi->rcClient.right);
\r
1133 Log(_T("windowinfo.dwStyle: %d"), pwi->dwStyle);
\r
1134 Log(_T("windowinfo.dwExStyle: %d"), pwi->dwExStyle);
\r
1135 Log(_T("windowinfo.dwWindowStatus: %d"), pwi->dwWindowStatus);
\r
1136 Log(_T("windowinfo.cxWindowBorders: %d"), pwi->cxWindowBorders);
\r
1137 Log(_T("windowinfo.cyWindowBorders: %d"), pwi->cyWindowBorders);
\r
1138 Log(_T("windowinfo.atomWindowType: %d"), pwi->atomWindowType);
\r
1139 Log(_T("windowinfo.wCreatorVersion: %d"), pwi->wCreatorVersion);
\r
1142 BOOL CUtils::IsOpenJane()
\r
1144 return !_tcsicmp(m_szApplicationName, _T("Jane2ch.exe"));
\r
1147 BOOL CUtils::UpdateKeyboardState(BYTE bVk, BYTE bState)
\r
1149 BYTE ks[256] = {'\0'};
\r
1152 if ((rc = GetKeyboardState(ks)) != FALSE) {
\r
1154 rc = SetKeyboardState(ks);
\r
1159 BOOL CUtils::IsThunderbird()
\r
1161 return !_tcsicmp(m_szApplicationName, _T("thunderbird.exe"));
\r
1164 int CUtils::GetWindowTextType(CString strWindowText)
\r
1166 int nWindowTextType = IDS_WINDOW_TEXT_IGNORE;
\r
1168 if (3 <= strWindowText.GetLength()
\r
1169 && strWindowText.Find(_T('*')) == 0
\r
1170 && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {
\r
1171 nWindowTextType = IDS_WINDOW_TEXT_MATCH;
\r
1172 } else if (2 <= strWindowText.GetLength()
\r
1173 && strWindowText.Find(_T('*')) != 0
\r
1174 && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {
\r
1175 nWindowTextType = IDS_WINDOW_TEXT_MATCH_FORWARD;
\r
1176 } else if (2 <= strWindowText.GetLength()
\r
1177 && strWindowText.Find(_T('*')) == 0
\r
1178 && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {
\r
1179 nWindowTextType = IDS_WINDOW_TEXT_MATCH_BACKWARD;
\r
1180 } else if (!strWindowText.IsEmpty()
\r
1181 && strWindowText.Find(_T('*')) != 0
\r
1182 && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {
\r
1183 nWindowTextType = IDS_WINDOW_TEXT_MATCH_FULL;
\r
1186 return nWindowTextType;
\r
1189 BOOL CUtils::IsLunascape()
\r
1191 return !_tcsicmp(m_szApplicationName, _T("Luna.exe"));
\r
1194 BOOL CUtils::IsAtok()
\r
1196 return !_tcsnicmp(m_szApplicationName, _T("ATOK"), 4) && !_tcsnicmp(m_szApplicationName + _tcslen(m_szApplicationName) - 4, _T(".IME"), 4);
\r