Skip to content

Commit

Permalink
Add One-Hand mice wheel scroll diff and merge (#2435) (6). Use WH_MOU…
Browse files Browse the repository at this point in the history
…SE instead of WM_MOUSE_LL
  • Loading branch information
sdottaka committed Oct 12, 2024
1 parent 6202143 commit 28c99cc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Src/DirView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ void CDirView::Redisplay()
*/
void CDirView::OnContextMenu(CWnd*, CPoint point)
{
if (CLowLevelMouseHook::IsRightWheelScrolling())
if (CMouseHook::IsRightWheelScrolling())
return;
if (GetListCtrl().GetItemCount() == 0)
return;
Expand Down
28 changes: 13 additions & 15 deletions Src/LowLevelMouseHook.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <StdAfx.h>
#include "LowLevelMouseHook.h"

void CALLBACK CLowLevelMouseHook::TimerProc(HWND unnamedParam1, UINT unnamedParam2, UINT_PTR id, DWORD unnamedParam4HWND)
void CALLBACK CMouseHook::TimerProc(HWND unnamedParam1, UINT unnamedParam2, UINT_PTR id, DWORD unnamedParam4HWND)
{
KillTimer(nullptr, id);
EndMenu();
m_bIgnoreRBUp = false;
}

LRESULT CALLBACK CLowLevelMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK CMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(m_hMouseHook, nCode, wParam, lParam);
Expand All @@ -29,9 +29,8 @@ LRESULT CALLBACK CLowLevelMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam,
}
else if (wParam == WM_MOUSEWHEEL)
{
MSLLHOOKSTRUCT* pMouseStruct = (MSLLHOOKSTRUCT*)lParam;
int zDelta = GET_WHEEL_DELTA_WPARAM(pMouseStruct->mouseData);
int nFlags = pMouseStruct->flags;
MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
short zDelta = HIWORD(pMouseStruct->mouseData);

if (GetKeyState(VK_MENU) & 0x8000)
{
Expand All @@ -55,7 +54,7 @@ LRESULT CALLBACK CLowLevelMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam,
PostMessage(hwndTarget, WM_COMMAND, ID_R2L, 0);
return 1;
}
else if (nFlags == 0)
else if (!m_bRButtonDown)
{
// Alt+ScrollUp as Alt+Up
PostMessage(hwndTarget, WM_COMMAND, ID_PREVDIFF, 0);
Expand All @@ -77,7 +76,7 @@ LRESULT CALLBACK CLowLevelMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam,
PostMessage(hwndTarget, WM_COMMAND, ID_L2R, 0);
return 1;
}
else if (nFlags == 0)
else if (!m_bRButtonDown)
{
// Alt+ScrollDown as Alt+Down
PostMessage(hwndTarget, WM_COMMAND, ID_NEXTDIFF, 0);
Expand Down Expand Up @@ -108,9 +107,8 @@ LRESULT CALLBACK CLowLevelMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam,
}
else if (wParam == WM_MOUSEHWHEEL)
{
MSLLHOOKSTRUCT* pMouseStruct = (MSLLHOOKSTRUCT*)lParam;
int zDelta = GET_WHEEL_DELTA_WPARAM(pMouseStruct->mouseData);
int nFlags = pMouseStruct->flags;
MOUSEHOOKSTRUCTEX* pMouseStruct = (MOUSEHOOKSTRUCTEX*)lParam;
short zDelta = HIWORD(pMouseStruct->mouseData);

if (GetKeyState(VK_MENU) & 0x8000)
{
Expand All @@ -125,7 +123,7 @@ LRESULT CALLBACK CLowLevelMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam,
PostMessage(hwndTarget, WM_COMMAND, ID_L2RNEXT, 0);
return 1;
}
else if (nFlags == 0)
else if (!m_bRButtonDown)
{
// Alt+HScrollRight as Alt+Right
PostMessage(hwndTarget, WM_COMMAND, ID_L2R, 0);
Expand All @@ -140,7 +138,7 @@ LRESULT CALLBACK CLowLevelMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam,
PostMessage(hwndTarget, WM_COMMAND, ID_R2LNEXT, 0);
return 1;
}
else if (nFlags == 0)
else if (!m_bRButtonDown)
{
// Alt+HScrollLeft as Alt+Left
PostMessage(hwndTarget, WM_COMMAND, ID_R2L, 0);
Expand Down Expand Up @@ -172,12 +170,12 @@ LRESULT CALLBACK CLowLevelMouseHook::LowLevelMouseProc(int nCode, WPARAM wParam,
return CallNextHookEx(m_hMouseHook, nCode, wParam, lParam);
}

void CLowLevelMouseHook::SetMouseHook()
void CMouseHook::SetMouseHook()
{
m_hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, nullptr, 0);
m_hMouseHook = SetWindowsHookEx(WH_MOUSE, LowLevelMouseProc, GetModuleHandle(nullptr), GetCurrentThreadId());
}

void CLowLevelMouseHook::UnhookMouseHook()
void CMouseHook::UnhookMouseHook()
{
if (m_hMouseHook)
{
Expand Down
2 changes: 1 addition & 1 deletion Src/LowLevelMouseHook.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CLowLevelMouseHook
class CMouseHook
{
public:
static void SetMouseHook();
Expand Down
4 changes: 2 additions & 2 deletions Src/Merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ BOOL CMergeApp::InitInstance()
return FALSE;
}

CLowLevelMouseHook::SetMouseHook();
CMouseHook::SetMouseHook();

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
Expand Down Expand Up @@ -564,7 +564,7 @@ void CMergeApp::OnAppAbout()
*/
int CMergeApp::ExitInstance()
{
CLowLevelMouseHook::UnhookMouseHook();
CMouseHook::UnhookMouseHook();

charsets_cleanup();

Expand Down
2 changes: 1 addition & 1 deletion Src/MergeEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2869,7 +2869,7 @@ void CMergeEditView::OnUpdateEditReplace(CCmdUI* pCmdUI)
*/
void CMergeEditView::OnContextMenu(CWnd* pWnd, CPoint point)
{
if (CLowLevelMouseHook::IsRightWheelScrolling())
if (CMouseHook::IsRightWheelScrolling())
return;

CRect rect;
Expand Down

2 comments on commit 28c99cc

@lededev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still the same problem, when start two instance of WinMerge, the 2nd can not block popup menu of right button when RB+Scroll Up/Down.
I remove the timer proc, and change IsRightWheelScrolling() to

bool CMouseHook::CheckRightWheelScrolling()
{
	if (m_bIgnoreRBUp)
	{
		m_bIgnoreRBUp = false;
		return true;
	}
	return false;
}

It seems work on both EmergeEditView and DirView. What is the reason for adding that TimerProc?

@sdottaka
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing that out.
I was unable to reproduce the problem, but I think it's probably a timing issue with TimerProc running before OnContextMenu.
TimerProc was used to close the context menu that appears for a moment after right-clicking Up on the Image compare window, Binary compare window, and Webpage compare window.

This TimerProc has been deleted.

Please sign in to comment.