Browse Source

handle mouse wheel messages for the window the mouse is over not the the focused window

sabrogden 8 years ago
parent
commit
f1722fdee5
5 changed files with 63 additions and 30 deletions
  1. 8 6
      MainFrm.cpp
  2. 0 6
      QListCtrl.cpp
  3. 0 1
      QListCtrl.h
  4. 54 17
      ToolTipEx.cpp
  5. 1 0
      ToolTipEx.h

+ 8 - 6
MainFrm.cpp

@@ -817,18 +817,20 @@ LRESULT CMainFrame::OnClipboardCopied(WPARAM wParam, LPARAM lParam)
 		m_thread.AddClipToSave(pClip);
 	} 
     
-    Log(_T("End of function OnClipboardCopied"));
+    Log(_T("End of function OnClipboardCopied"));	
     return TRUE;
 }
 
 BOOL CMainFrame::PreTranslateMessage(MSG *pMsg)
 {
-	
-    // target before mouse messages change the focus
-	/*if(theApp.m_bShowingQuickPaste && WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST)
+	//forward the mouse wheel onto the window under the cursor
+	//normally windows only sends it to the window with focus, bypass this
+	if (pMsg->message == WM_MOUSEWHEEL)
 	{
-	theApp.m_activeWnd.TrackActiveWnd(true);
-	}*/
+		POINT mouse;
+		GetCursorPos(&mouse);
+		pMsg->hwnd = ::WindowFromPoint(mouse);
+	}
 
     return CFrameWnd::PreTranslateMessage(pMsg);
 }

+ 0 - 6
QListCtrl.cpp

@@ -149,7 +149,6 @@ BEGIN_MESSAGE_MAP(CQListCtrl, CListCtrl)
 	ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnSelectionChange)
 	ON_WM_VSCROLL()
 	ON_WM_WINDOWPOSCHANGED()
-	ON_WM_MOUSEWHEEL()
 	//}}AFX_MSG_MAP
 	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
 	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
@@ -1481,11 +1480,6 @@ void CQListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
 	CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
 }
 
-BOOL CQListCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
-{
-	return CListCtrl::OnMouseWheel(nFlags, zDelta, pt);
-}
-
 BOOL CQListCtrl::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) 
 {
 	NMLVCACHEHINT* pcachehint = NULL;

+ 0 - 1
QListCtrl.h

@@ -205,7 +205,6 @@ protected:
 	afx_msg void OnTimer(UINT_PTR nIDEvent);
 	afx_msg void OnSelectionChange(NMHDR* pNMHDR, LRESULT* pResult);
 	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
-	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
 	//}}AFX_MSG
 	afx_msg BOOL OnToolTipText(UINT id, NMHDR * pNMHDR, LRESULT * pResult);
 	afx_msg void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);

+ 54 - 17
ToolTipEx.cpp

@@ -60,6 +60,7 @@ ON_COMMAND(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, &CToolTipEx::OnFirstHidedescriptio
 ON_COMMAND(ID_FIRST_WRAPTEXT, &CToolTipEx::OnFirstWraptext)
 ON_WM_WINDOWPOSCHANGING()
 ON_COMMAND(ID_FIRST_ALWAYSONTOP, &CToolTipEx::OnFirstAlwaysontop)
+ON_NOTIFY(EN_MSGFILTER, 1, &CToolTipEx::OnEnMsgfilterRichedit21)
 END_MESSAGE_MAP()
 
 
@@ -99,6 +100,7 @@ BOOL CToolTipEx::Create(CWnd *pParentWnd)
 
     m_RichEdit.SetReadOnly();
     m_RichEdit.SetBackgroundColor(FALSE, g_Opt.m_Theme.DescriptionWindowBG());
+	m_RichEdit.SetEventMask(ENM_MOUSEEVENTS | ENM_SCROLLEVENTS);
 
 	ApplyWordWrap();
 
@@ -225,7 +227,7 @@ BOOL CToolTipEx::Show(CPoint point)
 		}
 	}
 
-	m_clipDataStatic.SetWindowText(m_clipData);	
+	m_clipDataStatic.SetWindowText(m_clipData);
 
 	if (m_DittoWindow.m_bMinimized)
 	{
@@ -234,14 +236,14 @@ BOOL CToolTipEx::Show(CPoint point)
 	}
 
 	m_saveWindowLockout = true;
-	MoveWindow(rect);	
-	ShowWindow(SW_SHOWNA);	
+	MoveWindow(rect);
+	ShowWindow(SW_SHOWNA);
 	this->Invalidate();
 	this->UpdateWindow();
-	
+
 	m_saveWindowLockout = false;
 
-    return TRUE;
+	return TRUE;
 }
 
 void CToolTipEx::GetWindowRectEx(LPRECT lpRect)
@@ -262,16 +264,16 @@ BOOL CToolTipEx::Hide()
 
 	SaveWindowSize();
 
-    ShowWindow(SW_HIDE);
+	ShowWindow(SW_HIDE);
 
-    m_csRTF = "";
-    m_csText = "";
+	m_csRTF = "";
+	m_csText = "";
 	m_clipId = 0;
 	m_clipRow = -1;
-	m_searchText = _T("");	
+	m_searchText = _T("");
 	m_showPersistant = false;
 
-    return TRUE;
+	return TRUE;
 }
 
 void CToolTipEx::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
@@ -279,7 +281,7 @@ void CToolTipEx::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
 	// toggle ShowPersistent when we double click the caption
 	if (nHitTest == HTCAPTION)
 	{
-		OnFirstAlwaysontop();		
+		OnFirstAlwaysontop();
 	}
 
 	CWnd::OnNcLButtonDblClk(nHitTest, point);
@@ -298,8 +300,8 @@ void CToolTipEx::SaveWindowSize()
 		else
 		{
 			this->GetWindowRect(&rect);
-		}		
-		
+		}
+
 		CGetSetOptions::SetDescWndSize(rect.Size());
 		CGetSetOptions::SetDescWndPoint(rect.TopLeft());
 
@@ -309,17 +311,17 @@ void CToolTipEx::SaveWindowSize()
 
 void CToolTipEx::PostNcDestroy()
 {
-    CWnd::PostNcDestroy();
+	CWnd::PostNcDestroy();
 
-    delete this;
+	delete this;
 }
 
 BOOL CToolTipEx::PreTranslateMessage(MSG *pMsg)
 {
 	m_DittoWindow.DoPreTranslateMessage(pMsg);
 
-    switch(pMsg->message)
-    {
+	switch (pMsg->message)
+	{		
         case WM_KEYDOWN:
 
             switch(pMsg->wParam)
@@ -1115,3 +1117,38 @@ void CToolTipEx::OnFirstAlwaysontop()
 
 	::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);	
 }
+
+void CToolTipEx::OnEnMsgfilterRichedit21(NMHDR *pNMHDR, LRESULT *pResult)
+{
+	MSGFILTER *pMsgFilter = reinterpret_cast<MSGFILTER *>(pNMHDR);
+	if (pMsgFilter != NULL)
+	{
+		switch (pMsgFilter->msg)
+		{
+		case WM_VSCROLL:
+
+			//forward the mouse wheel onto the window under the cursor
+			//normally windows only sends it to the window with focus, bypass this
+			POINT mouse;
+			GetCursorPos(&mouse);
+			HWND windowUnderCursor = ::WindowFromPoint(mouse);
+
+			if (windowUnderCursor != m_RichEdit)
+			{
+				::PostMessage(windowUnderCursor, WM_MOUSEWHEEL, pMsgFilter->lParam, pMsgFilter->wParam);
+				*pResult = TRUE;
+				return;
+			}
+
+			break;
+		}
+	}
+	// TODO:  The control will not send this notification unless you override the
+	// CDialogEx::OnInitDialog() function to send the EM_SETEVENTMASK message
+	// to the control with either the ENM_KEYEVENTS or ENM_MOUSEEVENTS flag 
+	// ORed into the lParam mask.
+
+	// TODO:  Add your control notification handler code here
+
+	*pResult = 0;
+}

+ 1 - 0
ToolTipEx.h

@@ -127,4 +127,5 @@ public:
 	afx_msg void OnFirstWraptext();
 	afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
 	afx_msg void OnFirstAlwaysontop();
+	afx_msg void OnEnMsgfilterRichedit21(NMHDR *pNMHDR, LRESULT *pResult);
 };