[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
This commit is contained in:
Katayama Hirofumi MZ 2018-07-08 23:32:42 +09:00 committed by Hermès BÉLUSCA - MAÏTO
parent 25004bb5b4
commit a882ec7a02
7 changed files with 58 additions and 16 deletions

View file

@ -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()

View file

@ -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;
}

View file

@ -17,6 +17,7 @@
#include <wincon.h>
#include <commdlg.h>
#include <ddeml.h>
#include <userenv.h>
#include <shlwapi.h>
#include <shlobj.h>

View file

@ -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
*/

View file

@ -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 */

View file

@ -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
*/

View file

@ -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