XKeymacs for 64bit Windows
Révision | f03357a27dc665bd9afa5890152eba0582c9eb36 (tree) |
---|---|
l'heure | 2011-05-27 08:44:18 |
Auteur | Kazuhiro Fujieda <fujieda@user...> |
Commiter | Kazuhiro Fujieda |
Use WINDOW_TEXT_LENGTH instead of 0x100 as the buffer size for
GetWindowText. Remove size arguments from SetCorrectApplicationName,
FairConsoleApplicationName, IsConsole and IsJavaW in CUtils.
@@ -454,7 +454,7 @@ BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam) | ||
454 | 454 | } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vim.exe"), sizeof(pTask[i].ProcessName))) { |
455 | 455 | szAppName.Format(_T("VIM")); |
456 | 456 | } else { |
457 | - CUtils::SetCorrectApplicationName(pTask[i].ProcessName, sizeof(pTask[i].ProcessName), szWindowName, sizeof(szWindowName)); | |
457 | + CUtils::SetCorrectApplicationName(pTask[i].ProcessName, szWindowName); | |
458 | 458 | GetAppName(&szAppName, szWindowName); |
459 | 459 | } |
460 | 460 | break; |
@@ -666,7 +666,7 @@ int CCommands::EndOfLine() | ||
666 | 666 | // C-f: Right |
667 | 667 | int CCommands::ForwardChar() |
668 | 668 | { |
669 | -// TCHAR szWindowText[0x100] = {'\0'}; | |
669 | +// TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'}; | |
670 | 670 | // GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText)); |
671 | 671 | // CUtils::Log("C-f: %s", szWindowText); |
672 | 672 |
@@ -29,7 +29,7 @@ CUtils::~CUtils() | ||
29 | 29 | BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle) |
30 | 30 | { |
31 | 31 | { |
32 | - TCHAR buf[0x100] = {'\0'}; | |
32 | + TCHAR buf[WINDOW_TEXT_LENGTH] = {'\0'}; | |
33 | 33 | GetWindowText(GetForegroundWindow(), buf, sizeof(buf)); |
34 | 34 | // CUtils::Log(_T("Window Text --%s--"), buf); |
35 | 35 | szDialogTitle->Format(_T("%s"), buf); |
@@ -198,7 +198,7 @@ LPCTSTR const CUtils::GetApplicationName() | ||
198 | 198 | return m_szApplicationName; |
199 | 199 | } |
200 | 200 | |
201 | -void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength) | |
201 | +void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText) | |
202 | 202 | { |
203 | 203 | if (IsFindDialog()) { |
204 | 204 | return; |
@@ -207,13 +207,13 @@ void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicati | ||
207 | 207 | if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) { // "foo bar" -> foo bar |
208 | 208 | int nApplicationName = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar" |
209 | 209 | _tcsncpy(szWindowText, szWindowText + 1, nApplicationName); |
210 | - memset(szWindowText + nApplicationName, 0, nWindowTextLength - nApplicationName); | |
210 | + memset(szWindowText + nApplicationName, 0, WINDOW_TEXT_LENGTH - nApplicationName); | |
211 | 211 | } else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo |
212 | 212 | LPTSTR pFirstSpace = _tcschr(szWindowText, _T(' ')); |
213 | - memset(pFirstSpace, 0, nWindowTextLength - (pFirstSpace - szWindowText)); | |
213 | + memset(pFirstSpace, 0, WINDOW_TEXT_LENGTH - (pFirstSpace - szWindowText)); | |
214 | 214 | } |
215 | 215 | |
216 | - memset(szApplicationName, 0, nApplicationNameLength); | |
216 | + memset(szApplicationName, 0, MAX_PATH); | |
217 | 217 | _stprintf(szApplicationName, _T("%s"), szWindowText); |
218 | 218 | |
219 | 219 | static LPCTSTR const szExe = _T(".exe"); |
@@ -223,9 +223,9 @@ void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicati | ||
223 | 223 | } |
224 | 224 | |
225 | 225 | // Set real application name in the szApplicationName. |
226 | -void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nApplicationNameLength, LPTSTR szWindowText, const int nWindowTextLength) | |
226 | +void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText) | |
227 | 227 | { |
228 | - if (IsConsole(szApplicationName, nApplicationNameLength)) { | |
228 | + if (IsConsole(szApplicationName)) { | |
229 | 229 | int i = 0; |
230 | 230 | static LPCTSTR const szPromptName[] = {_T("Command Prompt"), _T("Mark Command Prompt"), _T("Select Command Prompt"), _T("MS-DOS Prompt"), |
231 | 231 | _T("Visual Studio .NET Command Prompt"), _T("Visual Studio .NET 2003 Command Prompt"), |
@@ -239,28 +239,28 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nAppl | ||
239 | 239 | return; |
240 | 240 | } |
241 | 241 | |
242 | - TCHAR sz[0x100] = {'\0'}; | |
242 | + TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'}; | |
243 | 243 | _stprintf(sz, _T("%s%s"), szPromptName[i], szSeparator); |
244 | 244 | |
245 | 245 | if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) { // "Command Promp - foo" |
246 | 246 | _tcscpy(szWindowText, szWindowText + _tcslen(sz)); |
247 | - FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength); | |
247 | + FairConsoleApplicationName(szApplicationName, szWindowText); | |
248 | 248 | return; |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | 252 | for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) { |
253 | - TCHAR szWindowTextLower[0x100] = {'\0'}; | |
253 | + TCHAR szWindowTextLower[WINDOW_TEXT_LENGTH] = {'\0'}; | |
254 | 254 | _tcscpy(szWindowTextLower, szWindowText); |
255 | 255 | _tcslwr(szWindowTextLower); |
256 | 256 | |
257 | 257 | if (_tcsstr(szWindowTextLower, szPromptPath[i])) { |
258 | - TCHAR sz[0x100] = {'\0'}; | |
258 | + TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'}; | |
259 | 259 | _stprintf(sz, _T("%s%s"), szPromptPath[i], szSeparator); |
260 | 260 | |
261 | 261 | if (_tcsstr(szWindowTextLower, sz)) { // "X:\WINNT\system32\cmd.exe - foo" |
262 | 262 | _tcscpy(szWindowText, _tcsstr(szWindowTextLower, sz) + _tcslen(sz)); |
263 | - FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength); | |
263 | + FairConsoleApplicationName(szApplicationName, szWindowText); | |
264 | 264 | return; |
265 | 265 | } else { // "X:\WINNT\system32\cmd.exe" |
266 | 266 | return; |
@@ -268,65 +268,58 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nAppl | ||
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | - if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell")) | |
271 | + LPTSTR newName = NULL, newText = NULL; | |
272 | + if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell")) | |
272 | 273 | || (*szWindowText == _T('~')) |
273 | 274 | || (*szWindowText == _T('/'))) { // Bash |
274 | - memset(szApplicationName, 0, nApplicationNameLength); | |
275 | - _stprintf(szApplicationName, _T("bash.exe")); | |
276 | - memset(szWindowText, 0, nWindowTextLength); | |
277 | - _stprintf(szWindowText, _T("bash")); | |
275 | + newName = _T("bash.exe"); | |
276 | + newText = _T("bash"); | |
278 | 277 | } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) { |
279 | - memset(szApplicationName, 0, nApplicationNameLength); | |
280 | - _stprintf(szApplicationName, _T("pdksh.exe")); | |
281 | - memset(szWindowText, 0, nWindowTextLength); | |
282 | - _stprintf(szWindowText, _T("pdksh")); | |
278 | + newName = _T("pdksh.exe"); | |
279 | + newText = _T("pdksh"); | |
283 | 280 | } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) { |
284 | - memset(szApplicationName, 0, nApplicationNameLength); | |
285 | - _stprintf(szApplicationName, _T("tcsh.exe")); | |
286 | - memset(szWindowText, 0, nWindowTextLength); | |
287 | - _stprintf(szWindowText, _T("tcsh")); | |
281 | + newName = _T("tcsh.exe"); | |
282 | + newText = _T("tcsh"); | |
288 | 283 | } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) { |
289 | - memset(szApplicationName, 0, nApplicationNameLength); | |
290 | - _stprintf(szApplicationName, _T("zsh.exe")); | |
291 | - memset(szWindowText, 0, nWindowTextLength); | |
292 | - _stprintf(szWindowText, _T("zsh")); | |
284 | + newName = _T("zsh.exe"); | |
285 | + newText = _T("zsh"); | |
293 | 286 | } else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14) |
294 | 287 | || !_tcsnicmp(szWindowText, _T("cat"), 3)) { |
295 | - memset(szApplicationName, 0, nApplicationNameLength); | |
296 | - _stprintf(szApplicationName, _T("sh.exe")); | |
297 | - memset(szWindowText, 0, nWindowTextLength); | |
298 | - _stprintf(szWindowText, _T("MKS Korn Shell")); | |
288 | + newName = _T("sh.exe"); | |
289 | + newText = _T("MKS Korn Shell"); | |
299 | 290 | } else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2) |
300 | 291 | || !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) { |
301 | - memset(szApplicationName, 0, nApplicationNameLength); | |
302 | - _stprintf(szApplicationName, _T("csh.exe")); | |
303 | - memset(szWindowText, 0, nWindowTextLength); | |
304 | - _stprintf(szWindowText, _T("C Shell")); | |
292 | + newName = _T("csh.exe"); | |
293 | + newText = _T("C Shell"); | |
305 | 294 | } else if (_tcsstr(szWindowText, _T(" - VIM"))) { |
306 | - memset(szApplicationName, 0, nApplicationNameLength); | |
307 | - _stprintf(szApplicationName, _T("vim.exe")); | |
308 | - memset(szWindowText, 0, nWindowTextLength); | |
309 | - _stprintf(szWindowText, _T("VIM")); | |
295 | + newName = _T("vim.exe"); | |
296 | + newText = _T("VIM"); | |
310 | 297 | } else if (_tcsstr(szWindowText, _T(" - Poderosa"))) { |
311 | - memset(szApplicationName, 0, nApplicationNameLength); | |
312 | - _stprintf(szApplicationName, _T("Poderosa.exe")); | |
313 | - memset(szWindowText, 0, nWindowTextLength); | |
314 | - _stprintf(szWindowText, _T("Poderosa")); | |
298 | + newName = _T("Poderosa.exe"); | |
299 | + newText = _T("Poderosa"); | |
315 | 300 | } else { // unknown console application |
316 | - FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength); | |
301 | + FairConsoleApplicationName(szApplicationName, szWindowText); | |
317 | 302 | } |
318 | - } else if (IsJavaW(szApplicationName, nApplicationNameLength)) { | |
303 | + if (newName) { | |
304 | + memset(szApplicationName, 0, MAX_PATH); | |
305 | + _stprintf(szApplicationName, newName); | |
306 | + memset(szWindowText, 0, WINDOW_TEXT_LENGTH); | |
307 | + _stprintf(szWindowText, newText); | |
308 | + } | |
309 | + } else if (IsJavaW(szApplicationName)) { | |
310 | + LPTSTR newName = NULL; | |
319 | 311 | if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) { |
320 | - memset(szApplicationName, 0, nApplicationNameLength); | |
321 | - _stprintf(szApplicationName, _T("eclipse.exe")); | |
312 | + newName = _T("eclipse.exe"); | |
322 | 313 | } else if (!_tcsicmp(szWindowText, _T("BlueJ")) |
323 | 314 | || !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) { |
324 | - memset(szApplicationName, 0, nApplicationNameLength); | |
325 | - _stprintf(szApplicationName, _T("bluej.exe")); | |
315 | + newName = _T("bluej.exe"); | |
326 | 316 | } else if (!_tcsicmp(szWindowText, _T("JUDE")) |
327 | 317 | || !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) { |
328 | - memset(szApplicationName, 0, nApplicationNameLength); | |
329 | - _stprintf(szApplicationName, _T("jude.exe")); | |
318 | + newName = _T("jude.exe"); | |
319 | + } | |
320 | + if (newName) { | |
321 | + memset(szApplicationName, 0, MAX_PATH); | |
322 | + _stprintf(szApplicationName, newName); | |
330 | 323 | } |
331 | 324 | } |
332 | 325 | return; |
@@ -378,13 +371,13 @@ void CUtils::SetApplicationName(BOOL bImeComposition) | ||
378 | 371 | |
379 | 372 | memset(m_szApplicationName, 0, sizeof(m_szApplicationName)); |
380 | 373 | _tcscpy(m_szApplicationName, _T("CMD.exe")); |
381 | - TCHAR szWindowText[0x100] = {'\0'}; | |
374 | + TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'}; | |
382 | 375 | GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText)); |
383 | - SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText)); | |
376 | + SetCorrectApplicationName(m_szApplicationName, szWindowText); | |
384 | 377 | } else if (IsJavaW()) { |
385 | - TCHAR szWindowText[0x100] = {'\0'}; | |
378 | + TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'}; | |
386 | 379 | GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText)); |
387 | - SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText)); | |
380 | + SetCorrectApplicationName(m_szApplicationName, szWindowText); | |
388 | 381 | } |
389 | 382 | if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) { |
390 | 383 | // CUtils::Log(_T("SetApplicationName: cygwin")); |
@@ -646,15 +639,15 @@ BOOL CUtils::IsConsole() | ||
646 | 639 | || !_tcsicmp(m_szApplicationName, _T("telnet.exe")); |
647 | 640 | } |
648 | 641 | |
649 | -BOOL CUtils::IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength) | |
642 | +BOOL CUtils::IsConsole(LPCTSTR szApplicationName) | |
650 | 643 | { |
651 | - return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), nApplicationNameLength) | |
652 | - || !_tcsnicmp(szApplicationName, _T("CMD.exe"), nApplicationNameLength); | |
644 | + return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), MAX_PATH) | |
645 | + || !_tcsnicmp(szApplicationName, _T("CMD.exe"), MAX_PATH); | |
653 | 646 | } |
654 | 647 | |
655 | -BOOL CUtils::IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength) | |
648 | +BOOL CUtils::IsJavaW(LPCTSTR szApplicationName) | |
656 | 649 | { |
657 | - return !_tcsnicmp(szApplicationName, _T("javaw.exe"), nApplicationNameLength); | |
650 | + return !_tcsnicmp(szApplicationName, _T("javaw.exe"), MAX_PATH); | |
658 | 651 | } |
659 | 652 | |
660 | 653 | BOOL CUtils::IsSleipnir() |
@@ -789,7 +782,7 @@ BOOL CUtils::IsVisualBasicEditor() | ||
789 | 782 | || IsMicrosoftWord() |
790 | 783 | || IsOutlook() |
791 | 784 | || IsProject()) { |
792 | - TCHAR szWindowText[0x100] = {'\0'}; | |
785 | + TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'}; | |
793 | 786 | GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText)); |
794 | 787 | static LPCTSTR const szVBE = _T("Microsoft Visual Basic - "); |
795 | 788 | if (!_tcsnicmp(szWindowText, szVBE, _tcslen(szVBE))) { |
@@ -801,7 +794,7 @@ BOOL CUtils::IsVisualBasicEditor() | ||
801 | 794 | |
802 | 795 | BOOL CUtils::IsEclipse() |
803 | 796 | { |
804 | - TCHAR szWindowText[0x100] = {'\0'}; | |
797 | + TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'}; | |
805 | 798 | GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText)); |
806 | 799 | |
807 | 800 | LPCTSTR szEclipse = _T(" - Eclipse Platform"); |
@@ -833,7 +826,7 @@ int CUtils::GetClipboardTextLength() | ||
833 | 826 | BOOL CUtils::IsDialog() |
834 | 827 | { |
835 | 828 | HWND hwnd = GetForegroundWindow(); |
836 | - TCHAR szWindowText[0x100] = {'\0'}; | |
829 | + TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'}; | |
837 | 830 | if (!GetWindowText(hwnd, szWindowText, sizeof(szWindowText))) |
838 | 831 | return FALSE; // inside sound box |
839 | 832 | return GetParent(GetForegroundWindow()) != NULL; |
@@ -9,6 +9,8 @@ | ||
9 | 9 | #pragma once |
10 | 10 | #endif // _MSC_VER > 1000 |
11 | 11 | |
12 | +#include "xkeymacsdll.h" | |
13 | + | |
12 | 14 | class AFX_EXT_CLASS CUtils |
13 | 15 | { |
14 | 16 | public: |
@@ -65,7 +67,7 @@ public: | ||
65 | 67 | static BOOL IsCsh(); |
66 | 68 | static BOOL IsSh(); |
67 | 69 | static BOOL IsBash(); |
68 | - static void SetCorrectApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength); | |
70 | + static void SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText); | |
69 | 71 | static void Log(LPTSTR fmt, ...); |
70 | 72 | static BOOL IsSleipnir(); |
71 | 73 | static BOOL IsConsole(); |
@@ -120,9 +122,9 @@ public: | ||
120 | 122 | private: |
121 | 123 | static BOOL IsTOForEOF(); |
122 | 124 | static int GetFormatTag(LPTSTR szFormatTag); |
123 | - static void FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength); | |
124 | - static BOOL IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength); | |
125 | - static BOOL IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength); | |
125 | + static void FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText); | |
126 | + static BOOL IsConsole(LPCTSTR szApplicationName); | |
127 | + static BOOL IsJavaW(LPCTSTR szApplicationName); | |
126 | 128 | static void SetIMEName(); |
127 | 129 | static OSVERSIONINFO m_OsVersionInfo; |
128 | 130 | static TCHAR m_szIMEName[MAX_PATH]; |
@@ -2041,7 +2041,7 @@ BOOL CXkeymacsDll::IsMatchWindowText(CString szWindowText) | ||
2041 | 2041 | { |
2042 | 2042 | BOOL bIsMatchWindowText = TRUE; |
2043 | 2043 | |
2044 | - TCHAR szCurrentWindowText[0x100] = {'\0'}; | |
2044 | + TCHAR szCurrentWindowText[WINDOW_TEXT_LENGTH] = {'\0'}; | |
2045 | 2045 | GetWindowText(GetForegroundWindow(), szCurrentWindowText, sizeof(szCurrentWindowText)); |
2046 | 2046 | |
2047 | 2047 | switch (CUtils::GetWindowTextType(szWindowText)) { |