[BUG_FIXED] Fix docking error messages displaying due to bad detection of windows version.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1236 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2014-05-10 01:12:44 +00:00
parent 7bfcda086d
commit e3208e4ce2
14 changed files with 30 additions and 38 deletions

View File

@ -40,7 +40,7 @@ enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\
L_COFFEESCRIPT,\ L_COFFEESCRIPT,\
// The end of enumated language type, so it should be always at the end // The end of enumated language type, so it should be always at the end
L_EXTERNAL}; L_EXTERNAL};
enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8}; enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8, WV_WIN81};

View File

@ -34,11 +34,6 @@
void Process::run() void Process::run()
{ {
TCHAR *opVerb = TEXT("open"); TCHAR *opVerb = TEXT("open");
/*
winVer winVersion = (NppParameters::getInstance())->getWinVersion();
if (winVersion == WV_VISTA || winVersion == WV_WIN7)
opVerb = TEXT("runas");
*/
::ShellExecute(NULL, opVerb, _command.c_str(), _args.c_str(), _curDir.c_str(), SW_SHOWNORMAL); ::ShellExecute(NULL, opVerb, _command.c_str(), _args.c_str(), _curDir.c_str(), SW_SHOWNORMAL);
} }

View File

@ -155,7 +155,8 @@ Notepad_plus::Notepad_plus(): _mainWindowStatus(0), _pDocTab(NULL), _pEditView(N
// Determine if user is administrator. // Determine if user is administrator.
BOOL is_admin; BOOL is_admin;
if(NppParameters::getInstance()->getWinVersion() >= WV_VISTA) winVer ver = NppParameters::getInstance()->getWinVersion();
if (ver >= WV_VISTA || ver == WV_UNKNOWN)
{ {
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup; PSID AdministratorsGroup;

View File

@ -232,11 +232,11 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
} }
} }
bool Notepad_plus_Window::isDlgsMsg(MSG *msg, bool unicodeSupported) const bool Notepad_plus_Window::isDlgsMsg(MSG *msg) const
{ {
for (size_t i = 0, len = _notepad_plus_plus_core._hModelessDlgs.size(); i < len; ++i) for (size_t i = 0, len = _notepad_plus_plus_core._hModelessDlgs.size(); i < len; ++i)
{ {
if (unicodeSupported?(::IsDialogMessageW(_notepad_plus_plus_core._hModelessDlgs[i], msg)):(::IsDialogMessageA(_notepad_plus_plus_core._hModelessDlgs[i], msg))) if (::IsDialogMessageW(_notepad_plus_plus_core._hModelessDlgs[i], msg))
return true; return true;
} }
return false; return false;

View File

@ -63,14 +63,13 @@ public:
Notepad_plus_Window() {}; Notepad_plus_Window() {};
void init(HINSTANCE, HWND, const TCHAR *cmdLine, CmdLineParams *cmdLineParams); void init(HINSTANCE, HWND, const TCHAR *cmdLine, CmdLineParams *cmdLineParams);
bool isDlgsMsg(MSG *msg, bool unicodeSupported) const; bool isDlgsMsg(MSG *msg) const;
HACCEL getAccTable() const{ HACCEL getAccTable() const {
return _notepad_plus_plus_core.getAccTable(); return _notepad_plus_plus_core.getAccTable();
}; };
bool emergency(generic_string emergencySavedDir) bool emergency(generic_string emergencySavedDir) {
{
return _notepad_plus_plus_core.emergency(emergencySavedDir); return _notepad_plus_plus_core.emergency(emergencySavedDir);
}; };

View File

@ -1042,7 +1042,7 @@ bool Notepad_plus::fileDelete(BufferID id)
winVer winVersion = (NppParameters::getInstance())->getWinVersion(); winVer winVersion = (NppParameters::getInstance())->getWinVersion();
bool goAhead = true; bool goAhead = true;
if (winVersion >= WV_WIN8) if (winVersion >= WV_WIN8 || winVersion == WV_UNKNOWN)
{ {
// Windows 8 (and version afer?) has no system alert, so we ask user's confirmation // Windows 8 (and version afer?) has no system alert, so we ask user's confirmation
goAhead = (doDeleteOrNot(fileNamePath) == IDYES); goAhead = (doDeleteOrNot(fileNamePath) == IDYES);

View File

@ -567,11 +567,17 @@ winVer getWindowsVersion()
pGNSI(&si); pGNSI(&si);
else else
GetSystemInfo(&si); GetSystemInfo(&si);
//printInt(osvi.dwMajorVersion);
//printInt(osvi.dwMinorVersion);
switch (osvi.dwPlatformId) switch (osvi.dwPlatformId)
{ {
case VER_PLATFORM_WIN32_NT: case VER_PLATFORM_WIN32_NT:
{ {
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 3 )
{
return WV_WIN81;
}
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 ) if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 )
{ {
return WV_WIN8; return WV_WIN8;

View File

@ -293,8 +293,7 @@ LRESULT DockingCont::runProcCaption(HWND hwnd, UINT Message, WPARAM wParam, LPAR
// start hooking // start hooking
hWndServer = _hCaption; hWndServer = _hCaption;
winVer ver = (NppParameters::getInstance())->getWinVersion(); hookMouse = ::SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)hookProcMouse, _hInst, 0);
hookMouse = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProcMouse, _hInst, 0);
if (!hookMouse) if (!hookMouse)
{ {

View File

@ -158,7 +158,7 @@ void DockingManager::init(HINSTANCE hInst, HWND hWnd, Window ** ppWin)
hWndServer = _hSelf; hWndServer = _hSelf;
CoInitialize(NULL); CoInitialize(NULL);
if (!gWinCallHook) //only set if not already done if (!gWinCallHook) //only set if not already done
gWinCallHook = SetWindowsHookEx(WH_CALLWNDPROC, FocusWndProc, hInst, GetCurrentThreadId()); gWinCallHook = ::SetWindowsHookEx(WH_CALLWNDPROC, FocusWndProc, hInst, GetCurrentThreadId());
if (!gWinCallHook) if (!gWinCallHook)
{ {

View File

@ -150,11 +150,7 @@ LRESULT DockingSplitter::runProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
{ {
hWndMouse = hwnd; hWndMouse = hwnd;
hookMouse = ::SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)hookProcMouse, _hInst, 0);
winVer ver = (NppParameters::getInstance())->getWinVersion();
hookMouse = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProcMouse, _hInst, 0);
if (!hookMouse) if (!hookMouse)
{ {
DWORD dwError = ::GetLastError(); DWORD dwError = ::GetLastError();
@ -168,6 +164,7 @@ LRESULT DockingSplitter::runProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
::GetCursorPos(&_ptOldPos); ::GetCursorPos(&_ptOldPos);
_isLeftButtonDown = TRUE; _isLeftButtonDown = TRUE;
} }
break; break;
} }
case WM_LBUTTONUP: case WM_LBUTTONUP:

View File

@ -258,7 +258,7 @@ void Gripper::create()
::SetWindowPos(_pCont->getHSelf(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); ::SetWindowPos(_pCont->getHSelf(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
::SetCapture(_hSelf); ::SetCapture(_hSelf);
winVer ver = (NppParameters::getInstance())->getWinVersion(); winVer ver = (NppParameters::getInstance())->getWinVersion();
hookMouse = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProcMouse, _hInst, 0); hookMouse = ::SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)hookProcMouse, _hInst, 0);
if (!hookMouse) if (!hookMouse)
{ {
@ -268,9 +268,9 @@ void Gripper::create()
::MessageBox(NULL, str, TEXT("SetWindowsHookEx(MOUSE) failed on Gripper::create()"), MB_OK | MB_ICONERROR); ::MessageBox(NULL, str, TEXT("SetWindowsHookEx(MOUSE) failed on Gripper::create()"), MB_OK | MB_ICONERROR);
} }
if (ver < WV_VISTA) if (ver != WV_UNKNOWN && ver < WV_VISTA)
{ {
hookKeyboard = ::SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)hookProcKeyboard, _hInst, ::GetCurrentThreadId()); hookKeyboard = ::SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)hookProcKeyboard, _hInst, 0);
if (!hookKeyboard) if (!hookKeyboard)
{ {
DWORD dwError = ::GetLastError(); DWORD dwError = ::GetLastError();

View File

@ -132,7 +132,7 @@ RECT TaskList::adjustSize()
reSizeTo(_rc); reSizeTo(_rc);
winVer ver = (NppParameters::getInstance())->getWinVersion(); winVer ver = (NppParameters::getInstance())->getWinVersion();
_rc.bottom += ver <= WV_XP?xpBottomMarge:w7BottomMarge; _rc.bottom += (ver <= WV_XP && ver != WV_UNKNOWN)?xpBottomMarge:w7BottomMarge;
return _rc; return _rc;
} }

View File

@ -84,8 +84,7 @@ BOOL CALLBACK TaskListDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
#ifndef WH_MOUSE_LL #ifndef WH_MOUSE_LL
#define WH_MOUSE_LL 14 #define WH_MOUSE_LL 14
#endif #endif
winVer ver = (NppParameters::getInstance())->getWinVersion(); _hHooker = ::SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)hookProc, _hInst, 0);
_hHooker = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProc, _hInst, 0);
hook = _hHooker; hook = _hHooker;
return FALSE; return FALSE;
} }

View File

@ -390,14 +390,14 @@ DEVOMER*/
// 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 messages to this process (or window)
// This allows opening new files to already opened elevated Notepad++ process via explorer context menu. // This allows opening new files to already opened elevated Notepad++ process via explorer context menu.
if(pNppParameters->getWinVersion() >= WV_VISTA) winVer ver = pNppParameters->getWinVersion();
if (ver >= WV_VISTA || ver == 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(pNppParameters->getWinVersion() == WV_VISTA) if(pNppParameters->getWinVersion() == WV_VISTA)
{ {
typedef BOOL (WINAPI *MESSAGEFILTERFUNC)(UINT message,DWORD dwFlag); typedef BOOL (WINAPI *MESSAGEFILTERFUNC)(UINT message,DWORD dwFlag);
@ -425,23 +425,19 @@ DEVOMER*/
} }
} }
bool unicodeSupported = pNppParameters->getWinVersion() >= WV_NT;
bool going = true; bool going = true;
while (going) while (going)
{ {
going = (unicodeSupported?(::GetMessageW(&msg, NULL, 0, 0)):(::GetMessageA(&msg, NULL, 0, 0))) != 0; going = ::GetMessageW(&msg, NULL, 0, 0) != 0;
if (going) if (going)
{ {
// if the message doesn't belong to the notepad_plus_plus's dialog // if the message doesn't belong to the notepad_plus_plus's dialog
if (!notepad_plus_plus.isDlgsMsg(&msg, unicodeSupported)) if (!notepad_plus_plus.isDlgsMsg(&msg))
{ {
if (::TranslateAccelerator(notepad_plus_plus.getHSelf(), notepad_plus_plus.getAccTable(), &msg) == 0) if (::TranslateAccelerator(notepad_plus_plus.getHSelf(), notepad_plus_plus.getAccTable(), &msg) == 0)
{ {
::TranslateMessage(&msg); ::TranslateMessage(&msg);
if (unicodeSupported) ::DispatchMessageW(&msg);
::DispatchMessageW(&msg);
else
::DispatchMessage(&msg);
} }
} }
} }