https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a882ec7a02ec220e2c22c…
commit a882ec7a02ec220e2c22c129c9e993900a1dc237
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sun Jul 8 23:32:42 2018 +0900
Commit: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Jul 8 16:32:42 2018 +0200
[SHELL32][EXPLORER] Update system-wide environment variables (#663)
- Implement shell32 RegenerateUserEnvironment() function and use it.
- CShellBrowser and CDesktopBrowser implements WM_SETTINGCHANGE actions.
CORE-1459, CORE-14397
---
base/shell/explorer/traywnd.cpp | 4 +--
dll/win32/browseui/shellbrowser.cpp | 10 ++++--
dll/win32/shell32/precomp.h | 1 +
dll/win32/shell32/shell32.cpp | 42 ++++++++++++++++++++++
dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp | 3 ++
dll/win32/shell32/stubs.cpp | 11 ------
sdk/include/reactos/undocshell.h | 3 ++
7 files changed, 58 insertions(+), 16 deletions(-)
diff --git a/base/shell/explorer/traywnd.cpp b/base/shell/explorer/traywnd.cpp
index 2484b23f77..f116f3b953 100644
--- a/base/shell/explorer/traywnd.cpp
+++ b/base/shell/explorer/traywnd.cpp
@@ -2849,12 +2849,12 @@ HandleTrayContextMenu:
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_NCMOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_APP_TRAYDESTROY, OnAppTrayDestroy)
- MESSAGE_HANDLER(TWM_OPENSTARTMENU, OnOpenStartMenu)
- MESSAGE_HANDLER(TWM_DOEXITWINDOWS, OnDoExitWindows)
MESSAGE_HANDLER(WM_CLOSE, OnDoExitWindows)
MESSAGE_HANDLER(WM_HOTKEY, OnHotkey)
MESSAGE_HANDLER(WM_NCCALCSIZE, OnNcCalcSize)
MESSAGE_HANDLER(TWM_SETTINGSCHANGED, OnTaskbarSettingsChanged)
+ MESSAGE_HANDLER(TWM_OPENSTARTMENU, OnOpenStartMenu)
+ MESSAGE_HANDLER(TWM_DOEXITWINDOWS, OnDoExitWindows)
ALT_MSG_MAP(1)
END_MSG_MAP()
diff --git a/dll/win32/browseui/shellbrowser.cpp b/dll/win32/browseui/shellbrowser.cpp
index a0cac36427..5345ef3285 100644
--- a/dll/win32/browseui/shellbrowser.cpp
+++ b/dll/win32/browseui/shellbrowser.cpp
@@ -23,6 +23,7 @@
#include <shellapi.h>
#include <htiframe.h>
#include <strsafe.h>
+#include <undocshell.h>
extern HRESULT IUnknown_ShowDW(IUnknown * punk, BOOL fShow);
@@ -599,7 +600,7 @@ public:
LRESULT OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled);
LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
LRESULT RelayMsgToShellView(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled);
- LRESULT PropagateMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled);
+ LRESULT OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled);
LRESULT OnClose(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
LRESULT OnFolderOptions(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL
&bHandled);
LRESULT OnMapNetworkDrive(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL
&bHandled);
@@ -645,7 +646,7 @@ public:
MESSAGE_HANDLER(WM_MEASUREITEM, RelayMsgToShellView)
MESSAGE_HANDLER(WM_DRAWITEM, RelayMsgToShellView)
MESSAGE_HANDLER(WM_MENUSELECT, RelayMsgToShellView)
- MESSAGE_HANDLER(WM_WININICHANGE, PropagateMessage)
+ MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)
COMMAND_ID_HANDLER(IDM_FILE_CLOSE, OnClose)
COMMAND_ID_HANDLER(IDM_TOOLS_FOLDEROPTIONS, OnFolderOptions)
COMMAND_ID_HANDLER(IDM_TOOLS_MAPNETWORKDRIVE, OnMapNetworkDrive)
@@ -3512,8 +3513,11 @@ LRESULT CShellBrowser::RelayMsgToShellView(UINT uMsg, WPARAM
wParam, LPARAM lPar
return 0;
}
-LRESULT CShellBrowser::PropagateMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled)
+LRESULT CShellBrowser::OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled)
{
+ LPVOID lpEnvironment;
+ RegenerateUserEnvironment(&lpEnvironment, TRUE);
+
SHPropagateMessage(m_hWnd, uMsg, wParam, lParam, TRUE);
return 0;
}
diff --git a/dll/win32/shell32/precomp.h b/dll/win32/shell32/precomp.h
index f7d4fe2d18..75c136664d 100644
--- a/dll/win32/shell32/precomp.h
+++ b/dll/win32/shell32/precomp.h
@@ -17,6 +17,7 @@
#include <wincon.h>
#include <commdlg.h>
#include <ddeml.h>
+#include <userenv.h>
#include <shlwapi.h>
#include <shlobj.h>
diff --git a/dll/win32/shell32/shell32.cpp b/dll/win32/shell32/shell32.cpp
index ac0a3bd08c..a1d11c27ff 100644
--- a/dll/win32/shell32/shell32.cpp
+++ b/dll/win32/shell32/shell32.cpp
@@ -63,6 +63,48 @@ AddCommasW(DWORD lValue, LPWSTR lpNumber)
return lpNumber;
}
+/*
+ * Implemented
+ */
+EXTERN_C BOOL
+WINAPI
+RegenerateUserEnvironment(LPVOID *lpEnvironment, BOOL bUpdateSelf)
+{
+ HANDLE hUserToken;
+ if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ | TOKEN_WRITE,
&hUserToken))
+ return FALSE;
+
+ BOOL bResult = CreateEnvironmentBlock(lpEnvironment, hUserToken, TRUE);
+ if (!bResult || !lpEnvironment)
+ {
+ CloseHandle(hUserToken);
+ return FALSE;
+ }
+
+ if (bUpdateSelf)
+ {
+ LPWSTR pszz = (LPWSTR)*lpEnvironment;
+ if (!pszz)
+ return FALSE;
+
+ while (*pszz)
+ {
+ size_t cch = wcslen(pszz);
+ LPWSTR pchEqual = wcschr(pszz, L'=');
+ if (pchEqual)
+ {
+ CStringW strName(pszz, pchEqual - pszz);
+ SetEnvironmentVariableW(strName, pchEqual + 1);
+ }
+ pszz += cch + 1;
+ }
+ }
+
+ CloseHandle(hUserToken);
+
+ return bResult;
+}
+
/**************************************************************************
* Default ClassFactory types
*/
diff --git a/dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp
b/dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp
index e452039aa6..934f53d17b 100644
--- a/dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp
+++ b/dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp
@@ -390,6 +390,9 @@ LRESULT CDesktopBrowser::OnSize(UINT uMsg, WPARAM wParam, LPARAM
lParam, BOOL &b
LRESULT CDesktopBrowser::OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled)
{
+ LPVOID lpEnvironment;
+ RegenerateUserEnvironment(&lpEnvironment, TRUE);
+
if (m_hWndShellView)
{
/* Forward the message */
diff --git a/dll/win32/shell32/stubs.cpp b/dll/win32/shell32/stubs.cpp
index f2019e5f2d..8bc2f65296 100644
--- a/dll/win32/shell32/stubs.cpp
+++ b/dll/win32/shell32/stubs.cpp
@@ -643,17 +643,6 @@ SHChangeNotifySuspendResume(BOOL bSuspend,
return FALSE;
}
-/*
- * Unimplemented
- */
-EXTERN_C BOOL
-WINAPI
-RegenerateUserEnvironment(LPVOID *lpUnknown, BOOL bUnknown)
-{
- FIXME("RegenerateUserEnvironment() stub\n");
- return FALSE;
-}
-
/*
* Unimplemented
*/
diff --git a/sdk/include/reactos/undocshell.h b/sdk/include/reactos/undocshell.h
index e74f201f86..24d6e82f55 100644
--- a/sdk/include/reactos/undocshell.h
+++ b/sdk/include/reactos/undocshell.h
@@ -526,6 +526,9 @@ typedef struct
* Misc Stuff
*/
+BOOL WINAPI
+RegenerateUserEnvironment(LPVOID *lpEnvironment, BOOL bUpdateSelf);
+
/* SHWaitForFileToOpen flags */
#define SHWFF_ADD 0x01
#define SHWFF_REMOVE 0x02