[SNDVOL32] Restore the previous placement data of the window (#2420)

Save the current coordinate data of the window to the Registry when the user closes the Sound Volume applet.
This commit is contained in:
Bișoc George 2020-03-13 23:33:36 +01:00 committed by GitHub
parent 72c51aabba
commit 3af1141a61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 134 additions and 0 deletions

View file

@ -158,6 +158,116 @@ CloseAppConfig(VOID)
}
}
BOOL
LoadXYCoordWnd(IN PPREFERENCES_CONTEXT PrefContext)
{
HKEY hKey;
LONG lResult;
TCHAR DeviceMixerSettings[256];
DWORD dwData;
DWORD cbData = sizeof(dwData);
/* Append the registry key path and device name key into one single string */
StringCchPrintf(DeviceMixerSettings, _countof(DeviceMixerSettings), TEXT("%s\\%s"), AppRegSettings, PrefContext->DeviceName);
lResult = RegOpenKeyEx(HKEY_CURRENT_USER,
DeviceMixerSettings,
0,
KEY_READ,
&hKey);
if (lResult != ERROR_SUCCESS)
{
return FALSE;
}
lResult = RegQueryValueEx(hKey,
TEXT("X"),
0,
0,
(LPBYTE)&dwData,
&cbData);
if (lResult != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
}
/* Cache the X coordinate point */
PrefContext->MixerWindow->WndPosX = dwData;
lResult = RegQueryValueEx(hKey,
TEXT("Y"),
0,
0,
(LPBYTE)&dwData,
&cbData);
if (lResult != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
}
/* Cache the Y coordinate point */
PrefContext->MixerWindow->WndPosY = dwData;
RegCloseKey(hKey);
return TRUE;
}
BOOL
SaveXYCoordWnd(IN HWND hWnd,
IN PPREFERENCES_CONTEXT PrefContext)
{
HKEY hKey;
LONG lResult;
TCHAR DeviceMixerSettings[256];
WINDOWPLACEMENT wp;
/* Get the placement coordinate data from the window */
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hWnd, &wp);
/* Append the registry key path and device name key into one single string */
StringCchPrintf(DeviceMixerSettings, _countof(DeviceMixerSettings), TEXT("%s\\%s"), AppRegSettings, PrefContext->DeviceName);
lResult = RegOpenKeyEx(HKEY_CURRENT_USER,
DeviceMixerSettings,
0,
KEY_SET_VALUE,
&hKey);
if (lResult != ERROR_SUCCESS)
{
return FALSE;
}
lResult = RegSetValueEx(hKey,
TEXT("X"),
0,
REG_DWORD,
(LPBYTE)&wp.rcNormalPosition.left,
sizeof(wp.rcNormalPosition.left));
if (lResult != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
}
lResult = RegSetValueEx(hKey,
TEXT("Y"),
0,
REG_DWORD,
(LPBYTE)&wp.rcNormalPosition.top,
sizeof(wp.rcNormalPosition.top));
if (lResult != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
return TRUE;
}
BOOL
WriteLineConfig(IN LPTSTR szDeviceName,
IN LPTSTR szLineName,