BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)\r
{\r
{\r
- TCHAR buf[0x100] = {'\0'};\r
+ TCHAR buf[WINDOW_TEXT_LENGTH] = {'\0'};\r
GetWindowText(GetForegroundWindow(), buf, sizeof(buf));\r
// CUtils::Log(_T("Window Text --%s--"), buf);\r
szDialogTitle->Format(_T("%s"), buf);\r
return m_szApplicationName;\r
}\r
\r
-void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength)\r
+void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)\r
{\r
if (IsFindDialog()) {\r
return;\r
if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) { // "foo bar" -> foo bar\r
int nApplicationName = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"\r
_tcsncpy(szWindowText, szWindowText + 1, nApplicationName);\r
- memset(szWindowText + nApplicationName, 0, nWindowTextLength - nApplicationName);\r
+ memset(szWindowText + nApplicationName, 0, WINDOW_TEXT_LENGTH - nApplicationName);\r
} else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo\r
LPTSTR pFirstSpace = _tcschr(szWindowText, _T(' '));\r
- memset(pFirstSpace, 0, nWindowTextLength - (pFirstSpace - szWindowText));\r
+ memset(pFirstSpace, 0, WINDOW_TEXT_LENGTH - (pFirstSpace - szWindowText));\r
}\r
\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
+ memset(szApplicationName, 0, MAX_PATH);\r
_stprintf(szApplicationName, _T("%s"), szWindowText);\r
\r
static LPCTSTR const szExe = _T(".exe");\r
}\r
\r
// Set real application name in the szApplicationName.\r
-void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nApplicationNameLength, LPTSTR szWindowText, const int nWindowTextLength)\r
+void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)\r
{\r
- if (IsConsole(szApplicationName, nApplicationNameLength)) {\r
+ if (IsConsole(szApplicationName)) {\r
int i = 0;\r
static LPCTSTR const szPromptName[] = {_T("Command Prompt"), _T("Mark Command Prompt"), _T("Select Command Prompt"), _T("MS-DOS Prompt"),\r
_T("Visual Studio .NET Command Prompt"), _T("Visual Studio .NET 2003 Command Prompt"),\r
return;\r
}\r
\r
- TCHAR sz[0x100] = {'\0'};\r
+ TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
_stprintf(sz, _T("%s%s"), szPromptName[i], szSeparator);\r
\r
if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) { // "Command Promp - foo"\r
_tcscpy(szWindowText, szWindowText + _tcslen(sz));\r
- FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);\r
+ FairConsoleApplicationName(szApplicationName, szWindowText);\r
return;\r
}\r
}\r
\r
for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {\r
- TCHAR szWindowTextLower[0x100] = {'\0'};\r
+ TCHAR szWindowTextLower[WINDOW_TEXT_LENGTH] = {'\0'};\r
_tcscpy(szWindowTextLower, szWindowText);\r
_tcslwr(szWindowTextLower);\r
\r
if (_tcsstr(szWindowTextLower, szPromptPath[i])) {\r
- TCHAR sz[0x100] = {'\0'};\r
+ TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
_stprintf(sz, _T("%s%s"), szPromptPath[i], szSeparator);\r
\r
if (_tcsstr(szWindowTextLower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"\r
_tcscpy(szWindowText, _tcsstr(szWindowTextLower, sz) + _tcslen(sz));\r
- FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);\r
+ FairConsoleApplicationName(szApplicationName, szWindowText);\r
return;\r
} else { // "X:\WINNT\system32\cmd.exe"\r
return;\r
}\r
}\r
\r
- if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))\r
+ LPTSTR newName = NULL, newText = NULL;\r
+ if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))\r
|| (*szWindowText == _T('~'))\r
|| (*szWindowText == _T('/'))) { // Bash\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("bash.exe"));\r
- memset(szWindowText, 0, nWindowTextLength);\r
- _stprintf(szWindowText, _T("bash"));\r
+ newName = _T("bash.exe");\r
+ newText = _T("bash");\r
} else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("pdksh.exe"));\r
- memset(szWindowText, 0, nWindowTextLength);\r
- _stprintf(szWindowText, _T("pdksh"));\r
+ newName = _T("pdksh.exe");\r
+ newText = _T("pdksh");\r
} else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("tcsh.exe"));\r
- memset(szWindowText, 0, nWindowTextLength);\r
- _stprintf(szWindowText, _T("tcsh"));\r
+ newName = _T("tcsh.exe");\r
+ newText = _T("tcsh");\r
} else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("zsh.exe"));\r
- memset(szWindowText, 0, nWindowTextLength);\r
- _stprintf(szWindowText, _T("zsh"));\r
+ newName = _T("zsh.exe");\r
+ newText = _T("zsh");\r
} else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14)\r
|| !_tcsnicmp(szWindowText, _T("cat"), 3)) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("sh.exe"));\r
- memset(szWindowText, 0, nWindowTextLength);\r
- _stprintf(szWindowText, _T("MKS Korn Shell"));\r
+ newName = _T("sh.exe");\r
+ newText = _T("MKS Korn Shell");\r
} else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2)\r
|| !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("csh.exe"));\r
- memset(szWindowText, 0, nWindowTextLength);\r
- _stprintf(szWindowText, _T("C Shell"));\r
+ newName = _T("csh.exe");\r
+ newText = _T("C Shell");\r
} else if (_tcsstr(szWindowText, _T(" - VIM"))) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("vim.exe"));\r
- memset(szWindowText, 0, nWindowTextLength);\r
- _stprintf(szWindowText, _T("VIM"));\r
+ newName = _T("vim.exe");\r
+ newText = _T("VIM");\r
} else if (_tcsstr(szWindowText, _T(" - Poderosa"))) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("Poderosa.exe"));\r
- memset(szWindowText, 0, nWindowTextLength);\r
- _stprintf(szWindowText, _T("Poderosa"));\r
+ newName = _T("Poderosa.exe");\r
+ newText = _T("Poderosa");\r
} else { // unknown console application\r
- FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);\r
+ FairConsoleApplicationName(szApplicationName, szWindowText);\r
}\r
- } else if (IsJavaW(szApplicationName, nApplicationNameLength)) {\r
+ if (newName) {\r
+ memset(szApplicationName, 0, MAX_PATH);\r
+ _stprintf(szApplicationName, newName);\r
+ memset(szWindowText, 0, WINDOW_TEXT_LENGTH);\r
+ _stprintf(szWindowText, newText);\r
+ }\r
+ } else if (IsJavaW(szApplicationName)) {\r
+ LPTSTR newName = NULL;\r
if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("eclipse.exe"));\r
+ newName = _T("eclipse.exe");\r
} else if (!_tcsicmp(szWindowText, _T("BlueJ"))\r
|| !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("bluej.exe"));\r
+ newName = _T("bluej.exe");\r
} else if (!_tcsicmp(szWindowText, _T("JUDE"))\r
|| !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) {\r
- memset(szApplicationName, 0, nApplicationNameLength);\r
- _stprintf(szApplicationName, _T("jude.exe"));\r
+ newName = _T("jude.exe");\r
+ }\r
+ if (newName) {\r
+ memset(szApplicationName, 0, MAX_PATH);\r
+ _stprintf(szApplicationName, newName);\r
}\r
}\r
return;\r
\r
memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
_tcscpy(m_szApplicationName, _T("CMD.exe"));\r
- TCHAR szWindowText[0x100] = {'\0'};\r
+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
- SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText));\r
+ SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
} else if (IsJavaW()) {\r
- TCHAR szWindowText[0x100] = {'\0'};\r
+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
- SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText));\r
+ SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
}\r
if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {\r
// CUtils::Log(_T("SetApplicationName: cygwin"));\r
|| !_tcsicmp(m_szApplicationName, _T("telnet.exe"));\r
}\r
\r
-BOOL CUtils::IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength)\r
+BOOL CUtils::IsConsole(LPCTSTR szApplicationName)\r
{\r
- return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), nApplicationNameLength)\r
- || !_tcsnicmp(szApplicationName, _T("CMD.exe"), nApplicationNameLength);\r
+ return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), MAX_PATH)\r
+ || !_tcsnicmp(szApplicationName, _T("CMD.exe"), MAX_PATH);\r
}\r
\r
-BOOL CUtils::IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength)\r
+BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)\r
{\r
- return !_tcsnicmp(szApplicationName, _T("javaw.exe"), nApplicationNameLength);\r
+ return !_tcsnicmp(szApplicationName, _T("javaw.exe"), MAX_PATH);\r
}\r
\r
BOOL CUtils::IsSleipnir()\r
|| IsMicrosoftWord()\r
|| IsOutlook()\r
|| IsProject()) {\r
- TCHAR szWindowText[0x100] = {'\0'};\r
+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
static LPCTSTR const szVBE = _T("Microsoft Visual Basic - ");\r
if (!_tcsnicmp(szWindowText, szVBE, _tcslen(szVBE))) {\r
\r
BOOL CUtils::IsEclipse()\r
{\r
- TCHAR szWindowText[0x100] = {'\0'};\r
+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
\r
LPCTSTR szEclipse = _T(" - Eclipse Platform");\r
BOOL CUtils::IsDialog()\r
{\r
HWND hwnd = GetForegroundWindow();\r
- TCHAR szWindowText[0x100] = {'\0'};\r
+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
if (!GetWindowText(hwnd, szWindowText, sizeof(szWindowText)))\r
return FALSE; // inside sound box\r
return GetParent(GetForegroundWindow()) != NULL;\r