Improve window filter to include start menu and Cortana search box. (#474)

Also moves GetProcessPath* functions to common, renaming both to
get_process_path.
This commit is contained in:
Bartosz Sosnowski
2019-10-07 11:12:44 +02:00
committed by GitHub
parent 298a8787d5
commit 5f8c4ea143
6 changed files with 68 additions and 55 deletions

View File

@@ -169,7 +169,7 @@ IFACEMETHODIMP_(void) FancyZones::WindowCreated(HWND window) noexcept
{
if (m_settings->GetSettings().appLastZone_moveWindows)
{
auto processPath = GetProcessPath(window);
auto processPath = get_process_path(window);
if (!processPath.empty())
{
INT zoneIndex = -1;
@@ -697,7 +697,7 @@ void FancyZones::MoveSizeEndInternal(HWND window, POINT const& ptScreen, require
{
::RemoveProp(window, ZONE_STAMP);
auto processPath = GetProcessPath(window);
auto processPath = get_process_path(window);
if (!processPath.empty())
{
RegistryHelpers::SaveAppLastZone(window, processPath.data(), -1);

View File

@@ -1252,7 +1252,7 @@ int ZoneWindow::GetSwitchButtonIndexFromPoint(POINT ptClient) noexcept
IFACEMETHODIMP_(void) ZoneWindow::SaveWindowProcessToZoneIndex(HWND window) noexcept
{
auto processPath = GetProcessPath(window);
auto processPath = get_process_path(window);
if (!processPath.empty())
{
DWORD zoneIndex = static_cast<DWORD>(m_activeZoneSet->GetZoneIndexFromWindow(window));

View File

@@ -133,53 +133,3 @@ inline void ParseDeviceId(PCWSTR deviceId, PWSTR parsedId, size_t size)
StringCchCopy(parsedId, size, L"FallbackDevice");
}
}
inline std::wstring GetProcessPathByPID(DWORD pid)
{
wil::unique_handle process(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, TRUE, pid));
std::wstring name;
if (process && process.get() != INVALID_HANDLE_VALUE)
{
name.resize(MAX_PATH);
DWORD name_length = static_cast<DWORD>(name.length());
QueryFullProcessImageNameW(process.get(), 0, (LPWSTR)name.data(), &name_length);
name.resize(name_length);
}
return name;
}
inline std::wstring GetProcessPath(HWND window) noexcept
{
const static std::wstring app_frame_host = L"ApplicationFrameHost.exe";
DWORD pid{};
GetWindowThreadProcessId(window, &pid);
auto name = GetProcessPathByPID(pid);
if (name.length() >= app_frame_host.length() &&
name.compare(name.length() - app_frame_host.length(), app_frame_host.length(), app_frame_host) == 0)
{
// It is a UWP app. We will enumarate the windows and look for one created
// by something with a different PID
DWORD new_pid = pid;
EnumChildWindows(window, [](HWND hwnd, LPARAM param) -> BOOL
{
auto new_pid_ptr = reinterpret_cast<DWORD*>(param);
DWORD pid;
GetWindowThreadProcessId(hwnd, &pid);
if (pid != *new_pid_ptr)
{
*new_pid_ptr = pid;
return FALSE;
}
else
{
return TRUE;
}
}, reinterpret_cast<LPARAM>(&new_pid));
// If we have a new pid, get the new name.
if (new_pid != pid)
{
return GetProcessPathByPID(new_pid);
}
}
return name;
}

View File

@@ -111,6 +111,9 @@
<ClInclude Include="Util.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\common\common.vcxproj">
<Project>{74485049-c722-400f-abe5-86ac52d929b3}</Project>
</ProjectReference>
<ProjectReference Include="..\..\lib\FancyZonesLib.vcxproj">
<Project>{f9c68edf-ac74-4b77-9af1-005d9c9f6a99}</Project>
</ProjectReference>