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
parent
aaab190763
commit
39f32bda96
|
@ -2488,31 +2488,16 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NPPM_INTERNAL_RESTOREMONOINSTANCE:
|
case NPPM_INTERNAL_RESTOREFROMTRAY:
|
||||||
{
|
{
|
||||||
// When mono instance, bring this one to front
|
// When mono instance, bring this one to front
|
||||||
if (_pTrayIco != nullptr && _pTrayIco->isInTray())
|
if (_pTrayIco != nullptr && _pTrayIco->isInTray())
|
||||||
{
|
{
|
||||||
// We are in tray, restore properly..
|
// We are in tray, restore properly..
|
||||||
::SendMessage(hwnd, NPPM_INTERNAL_MINIMIZED_TRAY, 0, WM_LBUTTONUP);
|
::SendMessage(hwnd, NPPM_INTERNAL_MINIMIZED_TRAY, 0, WM_LBUTTONUP);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
return FALSE;
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case WM_SYSCOMMAND:
|
case WM_SYSCOMMAND:
|
||||||
|
|
|
@ -644,7 +644,7 @@
|
||||||
#define NPPM_INTERNAL_CLEANSMARTHILITING (NOTEPADPLUS_USER_INTERNAL + 68)
|
#define NPPM_INTERNAL_CLEANSMARTHILITING (NOTEPADPLUS_USER_INTERNAL + 68)
|
||||||
#define NPPM_INTERNAL_CLEANBRACEMATCH (NOTEPADPLUS_USER_INTERNAL + 69)
|
#define NPPM_INTERNAL_CLEANBRACEMATCH (NOTEPADPLUS_USER_INTERNAL + 69)
|
||||||
#define NPPM_INTERNAL_WINDOWSSESSIONEXIT (NOTEPADPLUS_USER_INTERNAL + 70)
|
#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_SETNPC (NOTEPADPLUS_USER_INTERNAL + 72)
|
||||||
#define NPPM_INTERNAL_NPCFORMCHANGED (NOTEPADPLUS_USER_INTERNAL + 73)
|
#define NPPM_INTERNAL_NPCFORMCHANGED (NOTEPADPLUS_USER_INTERNAL + 73)
|
||||||
#define NPPM_INTERNAL_NPCLAUNCHSTYLECONF (NOTEPADPLUS_USER_INTERNAL + 74)
|
#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
|
#ifndef MSGFLT_ADD
|
||||||
const DWORD MSGFLT_ADD = 1;
|
const DWORD MSGFLT_ADD = 1;
|
||||||
|
@ -37,32 +37,38 @@ void allowWmCopydataMessages(Notepad_plus_Window& notepad_plus_plus, const NppPa
|
||||||
#ifndef MSGFLT_ALLOW
|
#ifndef MSGFLT_ALLOW
|
||||||
const DWORD MSGFLT_ALLOW = 1;
|
const DWORD MSGFLT_ALLOW = 1;
|
||||||
#endif
|
#endif
|
||||||
// Tell UAC that lower integrity processes are allowed to send WM_COPYDATA messages to this process (or window)
|
// Tell UAC that lower integrity processes are allowed to send WM_COPYDATA (or other) messages to this process (or window)
|
||||||
// This allows opening new files to already opened elevated Notepad++ process via explorer context menu.
|
// This (WM_COPYDATA) allows opening new files to already opened elevated Notepad++ process via explorer context menu.
|
||||||
if (ver >= WV_VISTA || ver == WV_UNKNOWN)
|
if (winVer >= WV_VISTA || winVer == WV_UNKNOWN)
|
||||||
{
|
{
|
||||||
HMODULE hDll = GetModuleHandle(TEXT("user32.dll"));
|
HMODULE hDll = GetModuleHandle(TEXT("user32.dll"));
|
||||||
if (hDll)
|
if (hDll)
|
||||||
{
|
{
|
||||||
// According to MSDN ChangeWindowMessageFilter may not be supported in future versions of Windows,
|
// 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).
|
// 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);
|
typedef BOOL (WINAPI *MESSAGEFILTERFUNC)(UINT message,DWORD dwFlag);
|
||||||
|
|
||||||
MESSAGEFILTERFUNC func = (MESSAGEFILTERFUNC)::GetProcAddress( hDll, "ChangeWindowMessageFilter" );
|
MESSAGEFILTERFUNC func = (MESSAGEFILTERFUNC)::GetProcAddress( hDll, "ChangeWindowMessageFilter" );
|
||||||
|
|
||||||
if (func)
|
if (func)
|
||||||
|
{
|
||||||
func(WM_COPYDATA, MSGFLT_ADD);
|
func(WM_COPYDATA, MSGFLT_ADD);
|
||||||
|
func(NPPM_INTERNAL_RESTOREFROMTRAY, MSGFLT_ADD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
typedef BOOL (WINAPI *MESSAGEFILTERFUNCEX)(HWND hWnd,UINT message,DWORD action,VOID* pChangeFilterStruct);
|
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)
|
if (funcEx)
|
||||||
func(notepad_plus_plus.getHSelf(), WM_COPYDATA, MSGFLT_ALLOW, NULL );
|
{
|
||||||
|
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();
|
nppParameters.destroyInstance();
|
||||||
|
|
||||||
// Restore the window, bring it to front, etc
|
// 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
|
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
|
try
|
||||||
{
|
{
|
||||||
notepad_plus_plus.init(hInstance, NULL, quotFileName.c_str(), &cmdLineParams);
|
notepad_plus_plus.init(hInstance, NULL, quotFileName.c_str(), &cmdLineParams);
|
||||||
allowWmCopydataMessages(notepad_plus_plus, nppParameters, ver);
|
allowPrivilegeMessages(notepad_plus_plus, ver);
|
||||||
bool going = true;
|
bool going = true;
|
||||||
while (going)
|
while (going)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue