Fix panels not restored from systemtray with "Edit with Notepad++" in admin mode

Continue the fix from:
afacc8338e

Eventualy fix Notepad++ not being restored on the foreground issue.

Fix #13041, close #13058
pull/13072/head
Don Ho 2 years ago
parent aaab190763
commit 39f32bda96

@ -2488,32 +2488,17 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return TRUE;
}
case NPPM_INTERNAL_RESTOREMONOINSTANCE:
case NPPM_INTERNAL_RESTOREFROMTRAY:
{
// When mono instance, bring this one to front
if (_pTrayIco != nullptr && _pTrayIco->isInTray())
{
// We are in tray, restore properly..
::SendMessage(hwnd, NPPM_INTERNAL_MINIMIZED_TRAY, 0, WM_LBUTTONUP);
}
else
{
// We were not in tray..
int sw = 0;
if (::IsZoomed(hwnd))
sw = SW_MAXIMIZE;
else if (::IsIconic(hwnd))
sw = SW_RESTORE;
if (sw != 0)
::ShowWindow(hwnd, sw);
::SetForegroundWindow(hwnd);
}
return TRUE;
}
return FALSE;
}
case WM_SYSCOMMAND:
{

@ -644,7 +644,7 @@
#define NPPM_INTERNAL_CLEANSMARTHILITING (NOTEPADPLUS_USER_INTERNAL + 68)
#define NPPM_INTERNAL_CLEANBRACEMATCH (NOTEPADPLUS_USER_INTERNAL + 69)
#define NPPM_INTERNAL_WINDOWSSESSIONEXIT (NOTEPADPLUS_USER_INTERNAL + 70)
#define NPPM_INTERNAL_RESTOREMONOINSTANCE (NOTEPADPLUS_USER_INTERNAL + 71)
#define NPPM_INTERNAL_RESTOREFROMTRAY (NOTEPADPLUS_USER_INTERNAL + 71)
#define NPPM_INTERNAL_SETNPC (NOTEPADPLUS_USER_INTERNAL + 72)
#define NPPM_INTERNAL_NPCFORMCHANGED (NOTEPADPLUS_USER_INTERNAL + 73)
#define NPPM_INTERNAL_NPCLAUNCHSTYLECONF (NOTEPADPLUS_USER_INTERNAL + 74)

@ -29,7 +29,7 @@ namespace
{
void allowWmCopydataMessages(Notepad_plus_Window& notepad_plus_plus, const NppParameters& nppParameters, winVer ver)
void allowPrivilegeMessages(Notepad_plus_Window& notepad_plus_plus, winVer winVer)
{
#ifndef MSGFLT_ADD
const DWORD MSGFLT_ADD = 1;
@ -37,32 +37,38 @@ void allowWmCopydataMessages(Notepad_plus_Window& notepad_plus_plus, const NppPa
#ifndef MSGFLT_ALLOW
const DWORD MSGFLT_ALLOW = 1;
#endif
// Tell UAC that lower integrity processes are allowed to send WM_COPYDATA messages to this process (or window)
// This allows opening new files to already opened elevated Notepad++ process via explorer context menu.
if (ver >= WV_VISTA || ver == WV_UNKNOWN)
// Tell UAC that lower integrity processes are allowed to send WM_COPYDATA (or other) messages to this process (or window)
// This (WM_COPYDATA) allows opening new files to already opened elevated Notepad++ process via explorer context menu.
if (winVer >= WV_VISTA || winVer == WV_UNKNOWN)
{
HMODULE hDll = GetModuleHandle(TEXT("user32.dll"));
if (hDll)
{
// According to MSDN ChangeWindowMessageFilter may not be supported in future versions of Windows,
// that is why we use ChangeWindowMessageFilterEx if it is available (windows version >= Win7).
if (nppParameters.getWinVersion() == WV_VISTA)
if (winVer == WV_VISTA)
{
typedef BOOL (WINAPI *MESSAGEFILTERFUNC)(UINT message,DWORD dwFlag);
MESSAGEFILTERFUNC func = (MESSAGEFILTERFUNC)::GetProcAddress( hDll, "ChangeWindowMessageFilter" );
if (func)
{
func(WM_COPYDATA, MSGFLT_ADD);
func(NPPM_INTERNAL_RESTOREFROMTRAY, MSGFLT_ADD);
}
}
else
{
typedef BOOL (WINAPI *MESSAGEFILTERFUNCEX)(HWND hWnd,UINT message,DWORD action,VOID* pChangeFilterStruct);
MESSAGEFILTERFUNCEX func = (MESSAGEFILTERFUNCEX)::GetProcAddress( hDll, "ChangeWindowMessageFilterEx" );
MESSAGEFILTERFUNCEX funcEx = (MESSAGEFILTERFUNCEX)::GetProcAddress( hDll, "ChangeWindowMessageFilterEx" );
if (func)
func(notepad_plus_plus.getHSelf(), WM_COPYDATA, MSGFLT_ALLOW, NULL );
if (funcEx)
{
funcEx(notepad_plus_plus.getHSelf(), WM_COPYDATA, MSGFLT_ALLOW, NULL);
funcEx(notepad_plus_plus.getHSelf(), NPPM_INTERNAL_RESTOREFROMTRAY, MSGFLT_ALLOW, NULL);
}
}
}
}
@ -559,7 +565,21 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int)
nppParameters.destroyInstance();
// Restore the window, bring it to front, etc
::SendMessage(hNotepad_plus, NPPM_INTERNAL_RESTOREMONOINSTANCE, 0, 0);
bool isInSystemTray = ::SendMessage(hNotepad_plus, NPPM_INTERNAL_RESTOREFROMTRAY, 0, 0);
if (!isInSystemTray)
{
int sw = 0;
if (::IsZoomed(hNotepad_plus))
sw = SW_MAXIMIZE;
else if (::IsIconic(hNotepad_plus))
sw = SW_RESTORE;
if (sw != 0)
::ShowWindow(hNotepad_plus, sw);
}
::SetForegroundWindow(hNotepad_plus);
if (params.size() > 0) //if there are files to open, use the WM_COPYDATA system
{
@ -683,7 +703,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int)
try
{
notepad_plus_plus.init(hInstance, NULL, quotFileName.c_str(), &cmdLineParams);
allowWmCopydataMessages(notepad_plus_plus, nppParameters, ver);
allowPrivilegeMessages(notepad_plus_plus, ver);
bool going = true;
while (going)
{

Loading…
Cancel
Save