From 2e238a03b84e92f0c4aa51b8eb3adbc1cad730a5 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 26 Jan 2013 22:40:42 +0000 Subject: [PATCH] =?UTF-8?q?[BUG=5FFIXED]=20(Author:=20Pekka=20P=C3=B6yry)?= =?UTF-8?q?=20Can't=20open=20file=20via=20Explorer=20context=20menu=20when?= =?UTF-8?q?=20Notepad++=20is=20run=20as=20administrator.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1011 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/winmain.cpp | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 1f780bb0..0f9a7015 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -371,6 +371,44 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) Win32Exception::installHandler(); try { notepad_plus_plus.init(hInstance, NULL, quotFileName.c_str(), &cmdLineParams); + + // 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(pNppParameters->getWinVersion() >= WV_VISTA) + { + 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(pNppParameters->getWinVersion() == WV_VISTA) + { + typedef BOOL (WINAPI *MESSAGEFILTERFUNC)(UINT message,DWORD dwFlag); + const DWORD MSGFLT_ADD = 1; + + MESSAGEFILTERFUNC func = (MESSAGEFILTERFUNC)::GetProcAddress( hDll, "ChangeWindowMessageFilter" ); + + if (func) + { + func(WM_COPYDATA, MSGFLT_ADD); + } + } + else + { + typedef BOOL (WINAPI *MESSAGEFILTERFUNCEX)(HWND hWnd,UINT message,DWORD action,VOID* pChangeFilterStruct); + const DWORD MSGFLT_ALLOW = 1; + + MESSAGEFILTERFUNCEX func = (MESSAGEFILTERFUNCEX)::GetProcAddress( hDll, "ChangeWindowMessageFilterEx" ); + + if (func) + { + func(notepad_plus_plus.getHSelf(), WM_COPYDATA, MSGFLT_ALLOW, NULL ); + } + } + } + } + bool unicodeSupported = pNppParameters->getWinVersion() >= WV_NT; bool going = true; while (going)