Editor should come up on the monitor with the foreground window. Defaults to primary monitor if there is no foreground window.

This commit is contained in:
Bret Anderson
2019-09-08 01:47:12 -07:00
parent 5f5402aa0a
commit e562b29ecd
7 changed files with 206 additions and 185 deletions

View File

@@ -32,22 +32,32 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
// This function is exported and called from FancyZonesEditor.exe to save a layout from the editor.
STDAPI PersistZoneSet(
PCWSTR activeKey, // Registry key holding ActiveZoneSet
PCWSTR resolutionKey, // Registry key for screen resolution
HMONITOR monitor,
WORD layoutId, // LayoutModel Id
int zoneCount, // Number of zones in zones
int zones[]) // Array of zones serialized in left/top/right/bottom chunks
{
// See if we have already persisted this layout we can update.
UUID id{GUID_NULL};
if (wil::unique_hkey key{ RegistryHelpers::OpenKey(resolutionKey) })
{
ZoneSetPersistedData data{};
DWORD dataSize = sizeof(data);
wchar_t value[256]{};
DWORD valueLength = ARRAYSIZE(value);
DWORD i = 0;
while (RegEnumValueW(key.get(), i++, value, &valueLength, nullptr, nullptr, reinterpret_cast<BYTE*>(&data), &dataSize) == ERROR_SUCCESS)
{
std::wstringstream stream;
MONITORINFOEX mi;
mi.cbSize = sizeof(mi);
if (GetMonitorInfo(monitor, &mi))
{
stream << (mi.rcMonitor.right - mi.rcMonitor.left) << "_";
stream << (mi.rcMonitor.bottom - mi.rcMonitor.top);
}
std::wstring resolutionKey(stream.str());
UUID id{GUID_NULL};
if (wil::unique_hkey key{ RegistryHelpers::OpenKey(resolutionKey.c_str()) })
{
ZoneSetPersistedData data{};
DWORD dataSize = sizeof(data);
wchar_t value[256]{};
DWORD valueLength = ARRAYSIZE(value);
DWORD i = 0;
while (RegEnumValueW(key.get(), i++, value, &valueLength, nullptr, nullptr, reinterpret_cast<BYTE*>(&data), &dataSize) == ERROR_SUCCESS)
{
if (data.LayoutId == layoutId)
{
if (data.ZoneCount == zoneCount)
@@ -73,8 +83,8 @@ STDAPI PersistZoneSet(
ZoneSetConfig(
id,
layoutId,
MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY),
resolutionKey,
reinterpret_cast<HMONITOR>(monitor),
resolutionKey.c_str(),
ZoneSetLayout::Custom,
0, 0, 0));