OSDN Git Service

CUtils::IsDialog detects a sound box in Internet Explorer isn't a dialog.
[xkeymacs/xkeymacs.git] / xkeymacsdll / Utils.cpp
1 // Utils.cpp: implementation of the CUtils class\r
2 //\r
3 //////////////////////////////////////////////////////////////////////\r
4 \r
5 #include "stdafx.h"\r
6 #include "Utils.h"\r
7 #include "../xkeymacs/resource.h"\r
8 #include <Imm.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
13 #pragma data_seg()\r
14 \r
15 //////////////////////////////////////////////////////////////////////\r
16 // Construction/Destruction\r
17 //////////////////////////////////////////////////////////////////////\r
18 \r
19 CUtils::CUtils()\r
20 {\r
21 \r
22 }\r
23 \r
24 CUtils::~CUtils()\r
25 {\r
26 \r
27 }\r
28 \r
29 BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)\r
30 {\r
31         {\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
36         }\r
37 \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
53                 return TRUE;\r
54         }\r
55 \r
56         szDialogTitle->Empty();\r
57         return FALSE;\r
58 }\r
59 \r
60 BOOL CUtils::IsFindDialog()\r
61 {\r
62         CString szDialogTitle;\r
63         return GetFindDialogTitle(&szDialogTitle);\r
64 }\r
65 \r
66 BOOL CUtils::IsAstecX()\r
67 {\r
68         return !_tcsicmp(m_szApplicationName, _T("astecx.exe"));\r
69 }\r
70 \r
71 BOOL CUtils::IsBecky()\r
72 {\r
73         return !_tcsicmp(m_szApplicationName, _T("b2.exe"));\r
74 }\r
75 \r
76 BOOL CUtils::IsEmacs()\r
77 {\r
78         return !_tcsicmp(m_szApplicationName, _T("Emacs.exe"));\r
79 }\r
80 \r
81 BOOL CUtils::IsExplorer()\r
82 {\r
83         return !_tcsicmp(m_szApplicationName, _T("explorer.exe"));\r
84 }\r
85 \r
86 BOOL CUtils::IsHidemaru()\r
87 {\r
88         return !_tcsicmp(m_szApplicationName, _T("hidemaru.exe"));\r
89 }\r
90 \r
91 BOOL CUtils::IsInternetExplorer()\r
92 {\r
93         return !_tcsicmp(m_szApplicationName, _T("iexplore.exe"));\r
94 }\r
95 \r
96 BOOL CUtils::IsLotus123()\r
97 {\r
98         return !_tcsicmp(m_szApplicationName, _T("123w.exe"));\r
99 }\r
100 \r
101 BOOL CUtils::IsLotusNotes()\r
102 {\r
103         return !_tcsicmp(m_szApplicationName, _T("nlnotes.exe"));\r
104 }\r
105 \r
106 BOOL CUtils::IsLotusWordPro()\r
107 {\r
108         return !_tcsicmp(m_szApplicationName, _T("wordpro.exe"));\r
109 }\r
110 \r
111 BOOL CUtils::IsMeadow()\r
112 {\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
116 }\r
117 \r
118 BOOL CUtils::IsMicrosoftFrontPage()\r
119 {\r
120         return !_tcsicmp(m_szApplicationName, _T("frontpg.exe"));\r
121 }\r
122 \r
123 BOOL CUtils::IsMicrosoftWord()\r
124 {\r
125         return !_tcsicmp(m_szApplicationName, _T("winword.exe"));\r
126 }\r
127 \r
128 BOOL CUtils::IsMozilla()\r
129 {\r
130         return !_tcsicmp(m_szApplicationName, _T("mozilla.exe"));\r
131 }\r
132 \r
133 BOOL CUtils::IsMuleForWin32()\r
134 {\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
138 }\r
139 \r
140 BOOL CUtils::IsNetscape()\r
141 {\r
142         return !_tcsicmp(m_szApplicationName, _T("netscp6.exe"))\r
143                 || !_tcsicmp(m_szApplicationName, _T("netscp.exe"));\r
144 }\r
145 \r
146 BOOL CUtils::IsNotepad()\r
147 {\r
148         return !_tcsicmp(m_szApplicationName, _T("notepad.exe"));\r
149 }\r
150 \r
151 BOOL CUtils::IsOpera()\r
152 {\r
153         return !_tcsicmp(m_szApplicationName, _T("opera.exe"));\r
154 }\r
155 \r
156 BOOL CUtils::IsOutlook()\r
157 {\r
158         return !_tcsicmp(m_szApplicationName, _T("outlook.exe"));\r
159 }\r
160 \r
161 BOOL CUtils::IsOutlookExpress()\r
162 {\r
163         return !_tcsicmp(m_szApplicationName, _T("msimn.exe"));\r
164 }\r
165 \r
166 BOOL CUtils::IsSakuraEditor()\r
167 {\r
168         return !_tcsicmp(m_szApplicationName, _T("sakura.exe"));\r
169 }\r
170 \r
171 BOOL CUtils::IsTeraTermPro()\r
172 {\r
173         return !_tcsicmp(m_szApplicationName, _T("ttermpro.exe"));\r
174 }\r
175 \r
176 BOOL CUtils::IsVisualCpp()\r
177 {\r
178         return !_tcsicmp(m_szApplicationName, _T("msdev.exe"));\r
179 }\r
180 \r
181 BOOL CUtils::IsWordpad()\r
182 {\r
183         return !_tcsicmp(m_szApplicationName, _T("wordpad.exe"));\r
184 }\r
185 \r
186 BOOL CUtils::IsXWin()\r
187 {\r
188         return !_tcsicmp(m_szApplicationName, _T("XWin.exe"));\r
189 }\r
190 \r
191 BOOL CUtils::IsXyzzy()\r
192 {\r
193         return !_tcsicmp(m_szApplicationName, _T("xyzzy.exe"));\r
194 }\r
195 \r
196 LPCTSTR const CUtils::GetApplicationName()\r
197 {\r
198         return m_szApplicationName;\r
199 }\r
200 \r
201 void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength)\r
202 {\r
203         if (IsFindDialog()) {\r
204                 return;\r
205         }\r
206 \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
214         }\r
215 \r
216         memset(szApplicationName, 0, nApplicationNameLength);\r
217         _stprintf(szApplicationName, _T("%s"), szWindowText);\r
218 \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
222         }\r
223 }\r
224 \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
227 {\r
228         if (IsConsole(szApplicationName, nApplicationNameLength)) {\r
229                 int i = 0;\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\83\83v\83\8d\83\93\83v\83g"), _T("\94Í\88Í\8ew\92è \83R\83}\83\93\83\83v\83\8d\83\93\83v\83g"), _T("\91I\91ð \83R\83}\83\93\83\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\83\83v\83\8d\83\93\83v\83g"), _T("Visual Studio .NET 2003 \83R\83}\83\93\83\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
236 \r
237                 for (i = 0; i < sizeof(szPromptName) / sizeof(szPromptName[0]); ++i) {\r
238                         if (!_tcsicmp(szWindowText, szPromptName[i])) { // "Command Prompt"\r
239                                 return;\r
240                         }\r
241 \r
242                         TCHAR sz[0x100] = {'\0'};\r
243                         _stprintf(sz, _T("%s%s"), szPromptName[i], szSeparator);\r
244 \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
248                                 return;\r
249                         }\r
250                 }\r
251 \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
256 \r
257                         if (_tcsstr(szWindowTextLower, szPromptPath[i])) {\r
258                                 TCHAR sz[0x100] = {'\0'};\r
259                                 _stprintf(sz, _T("%s%s"), szPromptPath[i], szSeparator);\r
260 \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
264                                         return;\r
265                                 } else {                                                                        // "X:\WINNT\system32\cmd.exe"\r
266                                         return;\r
267                                 }\r
268                         }\r
269                 }\r
270 \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
317                 }\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
330                 }\r
331         }\r
332         return;\r
333 }\r
334 \r
335 void CUtils::SetApplicationName(BOOL bImeComposition)\r
336 {\r
337 //      CUtils::Log(_T("SetApplicationName: start"));\r
338 \r
339         memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
340 \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
346                         }\r
347 //                      CUtils::Log(_T("SetApplicationName: m_szIMEName == %s"), m_szIMEName);\r
348                 }\r
349         }\r
350 \r
351         if (bImeComposition) {\r
352 //              CUtils::Log(_T("SetApplicationName: bImeComposition"));\r
353 \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
358                         }\r
359                         _tcsncpy(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));\r
360                 } else {\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
364                 }\r
365         } else {\r
366 //              CUtils::Log(_T("SetApplicationName: appication (%s)"), m_szApplicationName);\r
367 \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
373 \r
374 //              CUtils::Log(_T("SetApplicationName: appication [%s]"), m_szApplicationName);\r
375 \r
376                 if (IsConsole()) {\r
377 //                      CUtils::Log(_T("SetApplicationName: console"));\r
378 \r
379                         memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
380                         if (IsNT()) {\r
381                                 _tcscpy(m_szApplicationName, _T("CMD.exe"));\r
382                         } else {\r
383                                 _tcscpy(m_szApplicationName, _T("WINOA386.MOD"));\r
384                         }\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
392                 }\r
393                 if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {\r
394 //                      CUtils::Log(_T("SetApplicationName: cygwin"));\r
395 \r
396                         memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
397                         _tcscpy(m_szApplicationName, _T("bash.exe"));\r
398                 }\r
399 //              CUtils::Log(_T("name: %s"), m_szApplicationName);\r
400         }\r
401 }\r
402 \r
403 void CUtils::SetIMEName()\r
404 {\r
405         HKL hKL = GetKeyboardLayout(0);\r
406         if (ImmIsIME(hKL)) {\r
407                 ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName));\r
408         }\r
409 }\r
410 \r
411 void CUtils::InitCUtils()\r
412 {\r
413         GetVersionEx(&m_OsVersionInfo);\r
414         SetIMEName();\r
415 }\r
416 \r
417 BOOL CUtils::IsNTor9x()\r
418 {\r
419         return ((m_OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && (m_OsVersionInfo.dwMajorVersion <= 4))\r
420                  || (m_OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);\r
421 }\r
422 \r
423 BOOL CUtils::IsXPorLater()\r
424 {\r
425         return 5 < m_OsVersionInfo.dwMajorVersion\r
426                 || 5 == m_OsVersionInfo.dwMajorVersion && 1 <= m_OsVersionInfo.dwMinorVersion;\r
427 }\r
428 \r
429 BOOL CUtils::IsNT()\r
430 {\r
431         return m_OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;\r
432 }\r
433 \r
434 BOOL CUtils::OpenClipboard()\r
435 {\r
436         const int RETRY_COUNT = 0x10;\r
437 \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
442                         bOpened = TRUE;\r
443                         break;\r
444                 } else {\r
445                         Sleep(1);       // for OpenOffice\r
446 //                      Log(_T("CUtils::OpenClipboard: %d (%d)"), GetLastError(), i);\r
447                 }\r
448         }\r
449         ASSERT(bOpened);\r
450         return bOpened;\r
451 }\r
452 \r
453 BOOL CUtils::GetClipboardText(CString *szClipboardText)\r
454 {\r
455         if (!szClipboardText) {\r
456                 return FALSE;\r
457         }\r
458 \r
459         szClipboardText->Empty();\r
460 \r
461         if (!OpenClipboard()) {\r
462 //              CUtils::Log(_T("Cannot open the Clipboard"));\r
463                 return FALSE;\r
464         }\r
465 \r
466 /*\r
467         {\r
468                 Log(_T("GetClipboardText"));\r
469                 UINT uFormat = 0;\r
470                 for (;;) {\r
471                         uFormat = EnumClipboardFormats(uFormat);\r
472                         if (uFormat) {\r
473                                 Log(_T("uFormat = %d"), uFormat);\r
474                         } else {\r
475                                 break;\r
476                         }\r
477                 }\r
478 // winuser.h\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
486 // OwnerLink                                            49155\r
487 // Native                                                       49156\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
496 // Link                                                         49408\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
502         }\r
503 */\r
504 \r
505         UINT uFormat = CF_OEMTEXT;\r
506         if (IsSakuraEditor()) {\r
507                 uFormat = CF_TEXT;\r
508         }\r
509 \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
514                 CloseClipboard();\r
515                 return FALSE;\r
516         }\r
517 \r
518         szClipboardText->Format(_T("%s"), hClipboardText);\r
519         EmptyClipboard();\r
520         CloseClipboard();\r
521         return TRUE;\r
522 }\r
523 \r
524 BOOL CUtils::SetClipboardText(CString *szClipboardText)\r
525 {\r
526         if (!OpenClipboard()) {\r
527 //              CUtils::Log(_T("Cannot open the Clipboard in SetClipboardText"));\r
528                 return FALSE;\r
529         }\r
530 \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
535                 return FALSE;\r
536         }\r
537 \r
538         LPTSTR lpStr = (LPTSTR)GlobalLock(hClipboardText);\r
539         lstrcpyn(lpStr, *szClipboardText, nLength);\r
540         GlobalUnlock(hClipboardText);\r
541         EmptyClipboard();\r
542 \r
543         UINT uFormat = CF_OEMTEXT;\r
544         if (IsSakuraEditor()) {\r
545                 uFormat = CF_TEXT;\r
546         }\r
547 \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
551                 CloseClipboard();\r
552                 return FALSE;\r
553         }\r
554 \r
555         CloseClipboard();\r
556         return TRUE;\r
557 }\r
558 \r
559 BOOL CUtils::IsDefaultIgnoreApplication()\r
560 {\r
561         if (IsAstecX()\r
562          || IsBash()\r
563          || IsCsh()\r
564          || IsEmacs()\r
565          || IsLispWorksPersonalEdition()\r
566          || IsMeadow()\r
567          || IsMuleForWin32()\r
568          || IsPdksh()\r
569          || IsSh()\r
570          || IsTcsh()\r
571          || IsTeraTermPro() && !IsDialog()\r
572          || IsVisualSlickEdit() && !IsDialog()\r
573          || IsXWin()\r
574          || IsXyzzy() && !IsDialog()\r
575          || IsZsh()) {\r
576                 return TRUE;\r
577         }\r
578         return FALSE;\r
579 }\r
580 \r
581 BOOL CUtils::IsDWFM()\r
582 {\r
583         return !_tcsicmp(m_szApplicationName, _T("dwfm.exe"));\r
584 }\r
585 \r
586 BOOL CUtils::IsK2Editor()\r
587 {\r
588         return !_tcsicmp(m_szApplicationName, _T("K2Editor.exe"));\r
589 }\r
590 \r
591 BOOL CUtils::IsEggExplorer()\r
592 {\r
593         return !_tcsicmp(m_szApplicationName, _T("EggExp.exe"));\r
594 }\r
595 \r
596 BOOL CUtils::IsDirector()\r
597 {\r
598         return !_tcsicmp(m_szApplicationName, _T("Director.exe"));\r
599 }\r
600 \r
601 BOOL CUtils::IsExcel()\r
602 {\r
603         return !_tcsicmp(m_szApplicationName, _T("Excel.exe"));\r
604 }\r
605 \r
606 BOOL CUtils::IsFireworks()\r
607 {\r
608         return !_tcsicmp(m_szApplicationName, _T("Fireworks 4.exe"))\r
609                 || !_tcsicmp(m_szApplicationName, _T("Fireworks.exe"));\r
610 }\r
611 \r
612 BOOL CUtils::IsDreamweaver()\r
613 {\r
614         return !_tcsicmp(m_szApplicationName, _T("Dreamweaver.exe"));\r
615 }\r
616 \r
617 BOOL CUtils::IsFlash()\r
618 {\r
619         return !_tcsicmp(m_szApplicationName, _T("Flash.exe"));\r
620 }\r
621 \r
622 BOOL CUtils::IsPhotoshop()\r
623 {\r
624         return !_tcsicmp(m_szApplicationName, _T("Photoshp.exe"));\r
625 }\r
626 \r
627 BOOL CUtils::IsIllustrator()\r
628 {\r
629         return !_tcsicmp(m_szApplicationName, _T("Illustrator.exe"));\r
630 }\r
631 \r
632 BOOL CUtils::IsMicrosoftPowerPoint()\r
633 {\r
634         return !_tcsicmp(m_szApplicationName, _T("PowerPnt.exe"));\r
635 }\r
636 \r
637 BOOL CUtils::IsReget()\r
638 {\r
639         return !_tcsicmp(m_szApplicationName, _T("Regetdx.exe"))\r
640                 || !_tcsicmp(m_szApplicationName, _T("Regetjr.exe"));\r
641 }\r
642 \r
643 BOOL CUtils::IsPaint()\r
644 {\r
645         return !_tcsicmp(m_szApplicationName, _T("mspaint.exe"));\r
646 }\r
647 \r
648 BOOL CUtils::IsConsole()\r
649 {\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
662 }\r
663 \r
664 BOOL CUtils::IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength)\r
665 {\r
666         return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), nApplicationNameLength)\r
667                 || !_tcsnicmp(szApplicationName, _T("CMD.exe"), nApplicationNameLength);\r
668 }\r
669 \r
670 BOOL CUtils::IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength)\r
671 {\r
672         return !_tcsnicmp(szApplicationName, _T("javaw.exe"), nApplicationNameLength);\r
673 }\r
674 \r
675 BOOL CUtils::IsSleipnir()\r
676 {\r
677         return !_tcsicmp(m_szApplicationName, _T("Sleipnir.exe"));\r
678 }\r
679 \r
680 BOOL CUtils::IsBash()\r
681 {\r
682         return !_tcsicmp(m_szApplicationName, _T("bash.exe"));\r
683 }\r
684 \r
685 // for debug\r
686 void CUtils::Log(LPTSTR fmt, ...)\r
687 {\r
688         va_list ap;\r
689         va_start(ap, fmt);\r
690 \r
691         static const int LOG_MAX = 0x10000;\r
692         TCHAR szLog[LOG_MAX] = {'\0'};\r
693 \r
694         for (unsigned int nIndex = 0; nIndex < _tcslen(fmt); ) {\r
695                 LPTSTR pNextString = fmt + nIndex;\r
696                 LPTSTR pLogEnd = szLog + _tcslen(szLog);\r
697 \r
698                 if (*pNextString == _T('%')) {\r
699                         TCHAR szFormatTag[LOG_MAX] = {'0'};\r
700                         _tcscpy(szFormatTag, pNextString);\r
701 \r
702                         switch (GetFormatTag(szFormatTag)) {\r
703                         case _T('d'):\r
704                         case _T('i'):\r
705                         case _T('o'):\r
706                         case _T('x'):\r
707                         case _T('X'):\r
708                         case _T('u'):\r
709                         case _T('c'):\r
710                                 _stprintf(pLogEnd, szFormatTag, va_arg(ap, int));\r
711                                 break;\r
712                         case _T('s'):\r
713                                 _stprintf(pLogEnd, szFormatTag, va_arg(ap, LPTSTR));\r
714                                 break;\r
715                         case _T('f'):\r
716                         case _T('e'):\r
717                         case _T('E'):\r
718                         case _T('g'):\r
719                         case _T('G'):\r
720                                 _stprintf(pLogEnd, szFormatTag, va_arg(ap, double));\r
721                                 break;\r
722                         case _T('p'):\r
723                                 _stprintf(pLogEnd, szFormatTag, va_arg(ap, void *));\r
724                                 break;\r
725                         case _T('n'):\r
726                                 _stprintf(pLogEnd, szFormatTag, va_arg(ap, int *));\r
727                                 break;\r
728                         case _T('%'):\r
729                         default:\r
730                                 _stprintf(pLogEnd, _T("%s"), szFormatTag);\r
731                                 break;\r
732                         }\r
733 \r
734                         nIndex += _tcslen(szFormatTag);\r
735                 } else {\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
740 \r
741                         nIndex += _tcslen(pString);\r
742                 }\r
743         }\r
744 \r
745         va_end(ap);\r
746 \r
747         static int n = 0;\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
751         } else {\r
752                 _tcscpy(szPath, _T("c:\\xkeylog.txt"));\r
753         }\r
754         FILE *fp = _tfopen(szPath, _T("a"));\r
755         _ftprintf(fp, _T("%8d: %s       %s\n"), n++, m_szApplicationName, szLog);\r
756         fflush(fp);\r
757         fclose(fp);\r
758 }\r
759 \r
760 BOOL CUtils::IsSh()\r
761 {\r
762         return !_tcsicmp(m_szApplicationName, _T("sh.exe"));\r
763 }\r
764 \r
765 BOOL CUtils::IsCsh()\r
766 {\r
767         return !_tcsicmp(m_szApplicationName, _T("csh.exe"));\r
768 }\r
769 \r
770 BOOL CUtils::IsVisualStudioDotNet()\r
771 {\r
772         return !_tcsicmp(m_szApplicationName, _T("devenv.exe"));\r
773 }\r
774 \r
775 BOOL CUtils::IsAccess()\r
776 {\r
777         return !_tcsicmp(m_szApplicationName, _T("MSACCESS.EXE"));\r
778 }\r
779 \r
780 BOOL CUtils::IsProject()\r
781 {\r
782         return !_tcsicmp(m_szApplicationName, _T("WINPROJ.EXE"));\r
783 }\r
784 \r
785 BOOL CUtils::IsVisualBasic()\r
786 {\r
787         return !_tcsicmp(m_szApplicationName, _T("VB6.EXE"));\r
788 }\r
789 \r
790 BOOL CUtils::IsVisualBasicEditor()\r
791 {\r
792         if (IsVisualBasic()) {\r
793                 return TRUE;\r
794         }\r
795 \r
796         if (IsAccess()\r
797          || IsExcel()\r
798          || IsMicrosoftFrontPage()\r
799          || IsMicrosoftPowerPoint()\r
800          || IsMicrosoftWord()\r
801          || IsOutlook()\r
802          || IsProject()) {\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
807                         return TRUE;\r
808                 }\r
809         }\r
810         return FALSE;\r
811 }\r
812 \r
813 BOOL CUtils::IsEclipse()\r
814 {\r
815         TCHAR szWindowText[0x100] = {'\0'};\r
816         GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
817 \r
818         LPCTSTR szEclipse = _T(" - Eclipse Platform");\r
819         LPCTSTR szFind = _T("Find/Replace");\r
820 \r
821         return IsJavaW()\r
822                 && (_tcslen(szEclipse) < _tcslen(szWindowText) && !_tcsicmp(szWindowText + _tcslen(szWindowText) - _tcslen(szEclipse), szEclipse)\r
823                  || _tcslen(szFind) == _tcslen(szWindowText) && !_tcsicmp(szWindowText, szFind));\r
824 }\r
825 \r
826 int CUtils::GetClipboardTextLength()\r
827 {\r
828         CString szClipboardText;\r
829         CUtils::GetClipboardText(&szClipboardText);\r
830         CUtils::SetClipboardText(&szClipboardText);\r
831 \r
832 //      return sz.GetLength();\r
833 \r
834         int nLength = 0;\r
835         for (int i = 0; i < szClipboardText.GetLength(); ++i) {\r
836                 if (szClipboardText.GetAt(i) & 0x80) {\r
837                         ++i;\r
838                 }\r
839                 ++nLength;\r
840         }\r
841         return nLength;\r
842 }\r
843 \r
844 BOOL CUtils::IsDialog()\r
845 {\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
851 }\r
852 \r
853 int CUtils::GetFormatTag(LPTSTR szFormatTag)\r
854 {\r
855         if (*(szFormatTag) != _T('%')) {\r
856                 return NULL;\r
857         }\r
858 \r
859         unsigned int nIndex = 1;\r
860 \r
861         // flags\r
862         while (nIndex < _tcslen(szFormatTag)) {\r
863                 switch (*(szFormatTag + nIndex)) {\r
864                 case _T('-'):\r
865                 case _T('+'):\r
866                 case _T(' '):\r
867                 case _T('0'):\r
868                 case _T('#'):\r
869                         ++nIndex;\r
870                         continue;\r
871                 default:\r
872                         break;\r
873                 }\r
874 \r
875                 break;\r
876         }\r
877 \r
878         // width\r
879         while (_istdigit(*(szFormatTag + nIndex))) {\r
880                 ++nIndex;\r
881         }\r
882 \r
883         // precision\r
884         if (*(szFormatTag + nIndex) == _T('.')) {\r
885                 ++nIndex;\r
886                 while (_istdigit(*(szFormatTag + nIndex))) {\r
887                         ++nIndex;\r
888                 }\r
889         }\r
890 \r
891         // prefix\r
892         switch (*(szFormatTag + nIndex)) {\r
893         case _T('h'):\r
894         case _T('l'):\r
895         case _T('L'):\r
896                 ++nIndex;\r
897                 break;\r
898         }\r
899 \r
900         // type\r
901         switch (*(szFormatTag + nIndex)) {\r
902         case _T('d'):\r
903         case _T('i'):\r
904         case _T('o'):\r
905         case _T('x'):\r
906         case _T('X'):\r
907         case _T('u'):\r
908         case _T('c'):\r
909         case _T('s'):\r
910         case _T('f'):\r
911         case _T('e'):\r
912         case _T('E'):\r
913         case _T('g'):\r
914         case _T('G'):\r
915         case _T('p'):\r
916         case _T('n'):\r
917         case _T('%'):\r
918                 *(szFormatTag + nIndex + 1) = NULL;\r
919                 return *(szFormatTag + nIndex);\r
920         default:\r
921                 *(szFormatTag + nIndex) = NULL;\r
922                 return NULL;\r
923         }\r
924 }\r
925 \r
926 BOOL CUtils::IsEudora()\r
927 {\r
928         return !_tcsicmp(m_szApplicationName, _T("Eudora.exe"));\r
929 }\r
930 \r
931 BOOL CUtils::IsCodeWarrior()\r
932 {\r
933         return !_tcsicmp(m_szApplicationName, _T("IDE.exe"));\r
934 }\r
935 \r
936 BOOL CUtils::IseMemoPad()\r
937 {\r
938         return !_tcsicmp(m_szApplicationName, _T("eMemoPad.exe"));\r
939 }\r
940 \r
941 BOOL CUtils::IsStoryEditor()\r
942 {\r
943         return !_tcsicmp(m_szApplicationName, _T("STRYEDIT.EXE"));\r
944 }\r
945 \r
946 BOOL CUtils::IsNami2000()\r
947 {\r
948         return !_tcsicmp(m_szApplicationName, _T("Nami2000.exe"));\r
949 }\r
950 \r
951 BOOL CUtils::IsCorelDRAW()\r
952 {\r
953         return !_tcsicmp(m_szApplicationName, _T("CorelDrw.exe"));\r
954 }\r
955 \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
960 {\r
961         return IsTOForEOF();\r
962 }\r
963 \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
968 {\r
969         return IsTOForEOF();\r
970 }\r
971 \r
972 BOOL CUtils::IsTOForEOF()\r
973 {\r
974         CString szClipboardText;\r
975         GetClipboardText(&szClipboardText);\r
976         return szClipboardText.IsEmpty()                        // for normal application\r
977                 || szClipboardText.GetLength() >= 3;    // for VC++\r
978 }\r
979 \r
980 BOOL CUtils::IsHusen()\r
981 {\r
982         return !_tcsicmp(m_szApplicationName, _T("husen.exe"));\r
983 }\r
984 \r
985 BOOL CUtils::IsAdobeReader()\r
986 {\r
987         return !_tcsicmp(m_szApplicationName, _T("AcroRd32.exe"));\r
988 }\r
989 \r
990 BOOL CUtils::IsOpenOffice()\r
991 {\r
992         return !_tcsicmp(m_szApplicationName, _T("soffice.exe"))\r
993                 || !_tcsicmp(m_szApplicationName, _T("soffice.bin"));\r
994 }\r
995 \r
996 BOOL CUtils::IsTuruKameMail()\r
997 {\r
998         return !_tcsicmp(m_szApplicationName, _T("TuruKame.exe"));\r
999 }\r
1000 \r
1001 BOOL CUtils::IsOedit()\r
1002 {\r
1003         return !_tcsicmp(m_szApplicationName, _T("oedit.exe"));\r
1004 }\r
1005 \r
1006 BOOL CUtils::IsAutla()\r
1007 {\r
1008         return !_tcsicmp(m_szApplicationName, _T("Autla.exe"));\r
1009 }\r
1010 \r
1011 BOOL CUtils::IsShuriken()\r
1012 {\r
1013         return !_tcsicmp(m_szApplicationName, _T("JsvMail.exe"));\r
1014 }\r
1015 \r
1016 BOOL CUtils::IsEdLeaf()\r
1017 {\r
1018         return !_tcsicmp(m_szApplicationName, _T("edleaf.exe"));\r
1019 }\r
1020 \r
1021 BOOL CUtils::IsJmEditor()\r
1022 {\r
1023         return !_tcsicmp(m_szApplicationName, _T("JmEdit.exe"))\r
1024                 || !_tcsicmp(m_szApplicationName, _T("JmEdit2.exe"));\r
1025 }\r
1026 \r
1027 BOOL CUtils::IsDana()\r
1028 {\r
1029         return !_tcsicmp(m_szApplicationName, _T("Dana.exe"));\r
1030 }\r
1031 \r
1032 BOOL CUtils::IsIPMessenger()\r
1033 {\r
1034         return !_tcsicmp(m_szApplicationName, _T("ipmsg.exe"));\r
1035 }\r
1036 \r
1037 BOOL CUtils::IsezHTML()\r
1038 {\r
1039         return !_tcsicmp(m_szApplicationName, _T("ezhtml.exe"));\r
1040 }\r
1041 \r
1042 BOOL CUtils::IsTcsh()\r
1043 {\r
1044         return !_tcsicmp(m_szApplicationName, _T("tcsh.exe"));\r
1045 }\r
1046 \r
1047 BOOL CUtils::IsZsh()\r
1048 {\r
1049         return !_tcsicmp(m_szApplicationName, _T("zsh.exe"));\r
1050 }\r
1051 \r
1052 BOOL CUtils::IsPdksh()\r
1053 {\r
1054         return !_tcsicmp(m_szApplicationName, _T("pdksh.exe"));\r
1055 }\r
1056 \r
1057 BOOL CUtils::IsFirefox()\r
1058 {\r
1059         return !_tcsicmp(m_szApplicationName, _T("firefox.exe"));\r
1060 }\r
1061 \r
1062 BOOL CUtils::IsPHPEditor()\r
1063 {\r
1064         return !_tcsicmp(m_szApplicationName, _T("php_editor.exe"));\r
1065 }\r
1066 \r
1067 BOOL CUtils::IsTeraPad()\r
1068 {\r
1069         return !_tcsicmp(m_szApplicationName, _T("TeraPad.exe"));\r
1070 }\r
1071 \r
1072 BOOL CUtils::IsLispWorksPersonalEdition()\r
1073 {\r
1074         CString szLispWorks(_T("lispworks-personal-"));\r
1075         return !_tcsnicmp(m_szApplicationName, szLispWorks, szLispWorks.GetLength());\r
1076 \r
1077 //      return !_tcsicmp(m_szApplicationName, _T("lispworks-personal-4300.exe"));\r
1078 }\r
1079 \r
1080 BOOL CUtils::IsBorlandCppBuilder()\r
1081 {\r
1082         return !_tcsicmp(m_szApplicationName, _T("bcb.exe"));\r
1083 }\r
1084 \r
1085 BOOL CUtils::Run(CString szCommandLine, BOOL isWait)\r
1086 {\r
1087         STARTUPINFO si;\r
1088         ZeroMemory(&si, sizeof(si));\r
1089         si.cb = sizeof(si);\r
1090 \r
1091         PROCESS_INFORMATION pi;\r
1092         ZeroMemory(&pi, sizeof(pi));\r
1093 \r
1094         BOOL rc = CreateProcess(NULL, szCommandLine.GetBuffer(szCommandLine.GetLength() + 1), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);\r
1095         if (rc) {\r
1096                 if (isWait) {\r
1097                         WaitForSingleObject( pi.hProcess, INFINITE );\r
1098                 }\r
1099 \r
1100                 CloseHandle(pi.hThread);\r
1101                 CloseHandle(pi.hProcess);\r
1102         }\r
1103 \r
1104         return rc;\r
1105 }\r
1106 \r
1107 BOOL CUtils::IsJavaW()\r
1108 {\r
1109         return !_tcsicmp(m_szApplicationName, _T("javaw.exe"));\r
1110 }\r
1111 \r
1112 BOOL CUtils::IsMSDN()\r
1113 {\r
1114         return !_tcsicmp(m_szApplicationName, _T("hh.exe"));\r
1115 }\r
1116 \r
1117 BOOL CUtils::IsVisualSlickEdit()\r
1118 {\r
1119         return !_tcsicmp(m_szApplicationName, _T("vs.exe"));\r
1120 }\r
1121 \r
1122 void CUtils::PrintWindowInfo(WINDOWINFO *pwi)\r
1123 {\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
1140 }\r
1141 \r
1142 BOOL CUtils::IsOpenJane()\r
1143 {\r
1144         return !_tcsicmp(m_szApplicationName, _T("Jane2ch.exe"));\r
1145 }\r
1146 \r
1147 BOOL CUtils::UpdateKeyboardState(BYTE bVk, BYTE bState)\r
1148 {\r
1149         BYTE ks[256] = {'\0'};\r
1150         BOOL rc = FALSE;\r
1151 \r
1152         if ((rc = GetKeyboardState(ks)) != FALSE) {\r
1153                 ks[bVk] = bState;\r
1154                 rc = SetKeyboardState(ks);\r
1155         }\r
1156         return rc;\r
1157 }\r
1158 \r
1159 BOOL CUtils::IsThunderbird()\r
1160 {\r
1161         return !_tcsicmp(m_szApplicationName, _T("thunderbird.exe"));\r
1162 }\r
1163 \r
1164 int CUtils::GetWindowTextType(CString strWindowText)\r
1165 {\r
1166         int nWindowTextType = IDS_WINDOW_TEXT_IGNORE;\r
1167 \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
1184         }\r
1185 \r
1186         return nWindowTextType;\r
1187 }\r
1188 \r
1189 BOOL CUtils::IsLunascape()\r
1190 {\r
1191         return !_tcsicmp(m_szApplicationName, _T("Luna.exe"));\r
1192 }\r
1193 \r
1194 BOOL CUtils::IsAtok()\r
1195 {\r
1196         return !_tcsnicmp(m_szApplicationName, _T("ATOK"), 4) && !_tcsnicmp(m_szApplicationName + _tcslen(m_szApplicationName) - 4, _T(".IME"), 4);\r
1197 }\r