Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 851
  • Last Modified:

Using the mouse wheel

I would like to use the mouse wheel in an Windows 95 application. I'm unable to intercept the WM_MOUSEWHEEL message (because it's unsupported under Windows 95). How can I do?
0
bonduel
Asked:
bonduel
  • 2
  • 2
1 Solution
 
Blondie050798Commented:
You have to use OnRegisteredMouseWheel()
0
 
bonduelAuthor Commented:
I know that, but what is the way to use OnRegisteredMouseWheel (there is no message WM_REGISTEREDMOUSEWHEEL).
0
 
Blondie050798Commented:
The document does explain (although not very well!)

The framework calls this member function as a user rotates the mouse wheel and encounters the wheel's next notch. Unless overridden, OnRegisteredMouseWheel registers the Windows message, routes the message to the appropriate window, and calls the WM_MOUSEWHEEL handler for that window.

It is far easier to understand what is going on by looking at the source used by mfc, and simply 'do your own thing' as required!

So looking at the mfc source:

// register for Windows 95 or Windows NT 3.51
static UINT nMsgMouseWheel =
   (((::GetVersion() & 0x80000000) && LOBYTE(LOWORD(::GetVersion()) == 4)) ||
       (!(::GetVersion() & 0x80000000) && LOBYTE(LOWORD(::GetVersion()) == 3)))
       ? ::RegisterWindowMessage(MSH_MOUSEWHEEL) : 0;

and then in the message map:
ON_REGISTERED_MESSAGE(nMsgMouseWheel, OnRegisteredMouseWheel)

and then the actual source:
LRESULT CFrameWnd::OnRegisteredMouseWheel(WPARAM wParam, LPARAM lParam)
{
      // convert from MSH_MOUSEWHEEL to WM_MOUSEWHEEL

      WORD keyState = 0;
      keyState |= (::GetKeyState(VK_CONTROL) < 0) ? MK_CONTROL : 0;
      keyState |= (::GetKeyState(VK_SHIFT) < 0) ? MK_SHIFT : 0;

      LRESULT lResult;
      HWND hwFocus = ::GetFocus();
      const HWND hwDesktop = ::GetDesktopWindow();

      if (hwFocus == NULL)
            lResult = SendMessage(WM_MOUSEWHEEL, (wParam << 16) | keyState, lParam);
      else
      {
            do {
                  lParam = ::SendMessage(hwFocus, WM_MOUSEWHEEL,
                        (wParam << 16) | keyState, lParam);
                  hwFocus = ::GetParent(hwFocus);
            }
            while (lParam == 0 && hwFocus != NULL && hwFocus != hwDesktop);
      }
      return lResult;
}
0
 
bonduelAuthor Commented:
Thank U
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now