https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3af1141a61fecbf67df2f…
commit 3af1141a61fecbf67df2fcbf0cf3ecf64de20fdf
Author: Bișoc George <fraizeraust99(a)gmail.com>
AuthorDate: Fri Mar 13 23:33:36 2020 +0100
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Mar 14 07:33:36 2020 +0900
[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.
---
base/applications/sndvol32/misc.c | 110 ++++++++++++++++++++++++++++++++++
base/applications/sndvol32/sndvol32.c | 14 +++++
base/applications/sndvol32/sndvol32.h | 10 ++++
3 files changed, 134 insertions(+)
diff --git a/base/applications/sndvol32/misc.c b/base/applications/sndvol32/misc.c
index 670fa12f250..86bbbe67927 100644
--- a/base/applications/sndvol32/misc.c
+++ b/base/applications/sndvol32/misc.c
@@ -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,
diff --git a/base/applications/sndvol32/sndvol32.c
b/base/applications/sndvol32/sndvol32.c
index 64ce3ac5565..e39fceb46b5 100644
--- a/base/applications/sndvol32/sndvol32.c
+++ b/base/applications/sndvol32/sndvol32.c
@@ -880,6 +880,7 @@ MainWindowProc(HWND hwnd,
{
PMIXER_WINDOW MixerWindow;
DWORD CtrlID, LineOffset;
+ BOOL bRet;
LRESULT Result = 0;
SET_VOLUME_CONTEXT Context;
@@ -1211,6 +1212,18 @@ MainWindowProc(HWND hwnd,
/* Disable the 'Advanced Controls' menu item */
EnableMenuItem(GetMenu(hwnd), IDM_ADVANCED_CONTROLS, MF_BYCOMMAND |
MF_GRAYED);
+ /* Load the placement coordinate data of the window */
+ bRet = LoadXYCoordWnd(&Preferences);
+ if (bRet)
+ {
+ /*
+ * LoadXYCoordWnd() might fail for the first time of opening the
application which is normal as
+ * the Sound Control's applet settings haven't been saved yet
to the Registry. At this point SetWindowPos()
+ * call is skipped.
+ */
+ SetWindowPos(hwnd, NULL, MixerWindow->WndPosX,
MixerWindow->WndPosY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
+ }
+
/* create status window */
if (MixerWindow->Mode == NORMAL_MODE)
{
@@ -1257,6 +1270,7 @@ MainWindowProc(HWND hwnd,
case WM_CLOSE:
{
+ SaveXYCoordWnd(hwnd, &Preferences);
PostQuitMessage(0);
break;
}
diff --git a/base/applications/sndvol32/sndvol32.h
b/base/applications/sndvol32/sndvol32.h
index 4dcf58bebba..970d98238f2 100644
--- a/base/applications/sndvol32/sndvol32.h
+++ b/base/applications/sndvol32/sndvol32.h
@@ -55,6 +55,8 @@ typedef struct _MIXER_WINDOW
RECT rect;
HFONT hFont;
SIZE baseUnit;
+ INT WndPosX;
+ INT WndPosY;
} MIXER_WINDOW, *PMIXER_WINDOW;
extern HINSTANCE hAppInstance;
@@ -63,6 +65,7 @@ extern HWND hMainWnd;
extern HANDLE hAppHeap;
#define SZ_APP_CLASS TEXT("Volume Control")
+#define _countof(array) (sizeof(array) / sizeof(array[0]))
ULONG DbgPrint(PCH , ...);
#define DPRINT DbgPrint("SNDVOL32: %s:%i: ", __FILE__, __LINE__); DbgPrint
@@ -192,6 +195,13 @@ InitAppConfig(VOID);
VOID
CloseAppConfig(VOID);
+BOOL
+LoadXYCoordWnd(IN PPREFERENCES_CONTEXT PrefContext);
+
+BOOL
+SaveXYCoordWnd(IN HWND hWnd,
+ IN PPREFERENCES_CONTEXT PrefContext);
+
INT
AllocAndLoadString(OUT LPWSTR *lpTarget,
IN HINSTANCE hInst,