From f82ad78db96307c4cfc89b5ef1bb4795e68fbfbe Mon Sep 17 00:00:00 2001 From: Brian Ferguson Date: Fri, 23 Nov 2012 12:08:40 -0700 Subject: [PATCH] Added mouse scrolling for meter windows without focus. --- Library/MeterWindow.cpp | 51 +++++++++++++++++++++++++++++++++++++++++ Library/MeterWindow.h | 3 +++ 2 files changed, 54 insertions(+) diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index c51b2a83..1b4e7e3c 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -272,6 +272,16 @@ void CMeterWindow::Initialize() FadeWindow(0, m_AlphaValue); } } + + RAWINPUTDEVICE raw[1]; + raw[0].usUsagePage = 0x01; + raw[0].usUsage = 0x02; + raw[0].dwFlags = RIDEV_INPUTSINK; + raw[0].hwndTarget = m_Window; + if (!RegisterRawInputDevices(raw, 1, sizeof(raw[0]))) + { + Log(LOG_WARNING, L"Error registering raw input mouse device."); + } } /* @@ -4415,6 +4425,46 @@ bool CMeterWindow::DoMoveAction(int x, int y, MOUSEACTION action) return false; } +/* +** Sends mouse wheel messages to the window if the window does not have focus. +** +*/ +LRESULT CMeterWindow::OnMouseInput(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + POINT pos; + GetCursorPos(&pos); + HWND hwnd = WindowFromPoint(pos); + + // Only process RAW data if the mouse is over a meter window that does not have focus + if (Rainmeter->GetMeterWindow(hwnd) && hwnd != GetForegroundWindow()) + { + UINT dwSize; + LPBYTE lpb = new BYTE[48]; + + GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)); + + RAWINPUT* raw = (RAWINPUT*)lpb; + if (raw->header.dwType == RIM_TYPEMOUSE) + { + WPARAM wparam = MAKEWPARAM(0, HIWORD((short)raw->data.mouse.usButtonData)); + LPARAM lparam = MAKELPARAM(pos.x, pos.y); + + if (raw->data.mouse.usButtonFlags == RI_MOUSE_WHEEL) + { + PostMessage(hwnd, WM_MOUSEWHEEL, wparam, lparam); + } + else if (raw->data.mouse.usButtonFlags == RI_MOUSE_HORIZONTAL_WHEEL) + { + PostMessage(hwnd, WM_MOUSEHWHEEL, wparam, lparam); + } + } + + delete[] lpb; + } + + return 0; +} + /* ** Stores the new place of the window, in screen coordinates. ** @@ -4447,6 +4497,7 @@ LRESULT CALLBACK CMeterWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR CMeterWindow* window = (CMeterWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); BEGIN_MESSAGEPROC + MESSAGE(OnMouseInput, WM_INPUT) MESSAGE(OnMove, WM_MOVE) MESSAGE(OnTimer, WM_TIMER) MESSAGE(OnCommand, WM_COMMAND) diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index 90e783b2..417907e8 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -38,6 +38,8 @@ #define METERWINDOW_CLASS_NAME L"RainmeterMeterWindow" +#define RI_MOUSE_HORIZONTAL_WHEEL 0x0800 + typedef HRESULT (WINAPI * FPDWMENABLEBLURBEHINDWINDOW)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind); typedef HRESULT (WINAPI * FPDWMGETCOLORIZATIONCOLOR)(DWORD* pcrColorization, BOOL* pfOpaqueBlend); typedef HRESULT (WINAPI * FPDWMSETWINDOWATTRIBUTE)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute); @@ -249,6 +251,7 @@ protected: static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK InitialWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT OnMouseInput(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnMove(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam);