示例#1
0
// Поставить хук в процесс шелла (explorer.exe)
bool CDefaultTerminal::CheckShellWindow()
{
	bool bHooked = false;
	HWND hFore = GetForegroundWindow();
	HWND hDesktop = GetDesktopWindow(); //csrss.exe on Windows 8
	HWND hShell = GetShellWindow();
	HWND hTrayWnd = FindWindowEx(NULL, NULL, L"Shell_TrayWnd", NULL);
	DWORD nDesktopPID = 0, nShellPID = 0, nTrayPID = 0, nForePID = 0;

	if (!bHooked && hShell)
	{
		if (GetWindowThreadProcessId(hShell, &nShellPID) && nShellPID)
		{
			bHooked = CheckForeground(hShell, nShellPID, false);
		}
	}

	if (!bHooked && hTrayWnd)
	{
		if (GetWindowThreadProcessId(hTrayWnd, &nTrayPID) && nTrayPID
			&& (nTrayPID != nShellPID))
		{
			bHooked = CheckForeground(hTrayWnd, nTrayPID, false);
		}
	}

	if (!bHooked && hDesktop)
	{
		if (GetWindowThreadProcessId(hDesktop, &nDesktopPID) && nDesktopPID
			&& (nDesktopPID != nTrayPID) && (nDesktopPID != nShellPID))
		{
			bHooked = CheckForeground(hDesktop, nDesktopPID, false);
		}
	}

	// Поскольку это выполняется на старте, то ConEmu могли запустить специально
	// для установки перехвата терминала. Поэтому нужно проверить и ForegroundWindow!
	if (hFore)
	{
		if (GetWindowThreadProcessId(hFore, &nForePID)
			&& (nForePID != nShellPID) && (nForePID != nDesktopPID) && (nForePID != nTrayPID))
		{
			CheckForeground(hFore, nForePID, false);
		}
	}

	return bHooked;
}
示例#2
0
// Поставить хук в процесс шелла (explorer.exe)
bool CDefaultTerminal::CheckShellWindow()
{
	bool bHooked = false;
	HWND hDesktop = GetDesktopWindow(); //csrss.exe on Windows 8
	HWND hShell = GetShellWindow();
	HWND hTrayWnd = FindWindowEx(NULL, NULL, L"Shell_TrayWnd", NULL);
	DWORD nDesktopPID = 0, nShellPID = 0, nTrayPID = 0;

	if (!bHooked && hShell)
	{
		if (GetWindowThreadProcessId(hShell, &nShellPID) && nShellPID)
		{
			bHooked = CheckForeground(hShell, nShellPID, false);
		}
	}

	if (!bHooked && hTrayWnd)
	{
		if (GetWindowThreadProcessId(hTrayWnd, &nTrayPID) && nTrayPID
			&& (nTrayPID != nShellPID))
		{
			bHooked = CheckForeground(hTrayWnd, nTrayPID, false);
		}
	}

	if (!bHooked && hDesktop)
	{
		if (GetWindowThreadProcessId(hDesktop, &nDesktopPID) && nDesktopPID
			&& (nDesktopPID != nTrayPID) && (nDesktopPID != nShellPID))
		{
			bHooked = CheckForeground(hDesktop, nDesktopPID, false);
		}
	}

	return bHooked;
}
示例#3
0
void CDefTermHk::PostCreateThreadFinished()
{
	// Запустить цикл проверки, необходимый для Agressive mode
	DWORD dwWait = WAIT_TIMEOUT;
	DWORD nForePID = 0;
	HWND  hFore = NULL;
	while ((dwWait = WaitForSingleObject(mh_StopEvent, FOREGROUND_CHECK_DELAY)) == WAIT_TIMEOUT)
	{
		hFore = GetForegroundWindow();
		if (!hFore)
			continue;
		if (!GetWindowThreadProcessId(hFore, &nForePID))
			continue;
		CheckForeground(hFore, nForePID, false);
	}
}
示例#4
0
void CDefTermHk::PostCreateThreadFinished()
{
	// Запустить цикл проверки, необходимый для Agressive mode
	DWORD dwWait = WAIT_TIMEOUT;
	DWORD nForePID = 0;
	HWND  hFore = NULL;
	while ((dwWait = WaitForSingleObject(mh_StopEvent, FOREGROUND_CHECK_DELAY)) == WAIT_TIMEOUT)
	{
		// If non-aggressive - don't do anything here...
		if (!isDefaultTerminalAllowed(true) || !m_Opt.bAgressive)
			continue;

		// Aggressive mode
		hFore = GetForegroundWindow();
		if (!hFore)
			continue;
		if (!GetWindowThreadProcessId(hFore, &nForePID))
			continue;
		CheckForeground(hFore, nForePID, false);
	}
}