Microsoft KB Archive/237998

= The CDialog class does not receive the WM_MOUSEWHEEL message on a Windows 95-based computer =

Article ID: 237998

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 5.0 Standard Edition

 Microsoft Visual C++ 6.0 Service Pack 5

 Microsoft Visual C++ .NET 2002 Standard Edition

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

 Microsoft Visual C++ 2005 Express Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q237998

<div class="notice_section">

Note Microsoft Visual C++ NET (2002) supported both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies to unmanaged Visual C++ code only.

Note Microsoft Visual C++ 2005 supports both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model.

<div class="symptoms_section">

SYMPTOMS
When the mouse wheel is rotated on a dialog box, the handler for the WM_MOUSEWHEEL message in the dialog class is not called on a computer running Windows 95.

<div class="cause_section">

CAUSE
The CDialog class in MFC does not register the MSH_MOUSEWHEEL message, which is required in order to receive WM_MOUSEWHEEL messages on a computer running Windows 95.

<div class="resolution_section">

RESOLUTION
You can work around the problem by following the steps described below: <ol>  Register the MSH_MOUSEWHEEL message. Copy the following line to your Dialog.cpp file: AFX_STATIC UINT _afxMsgMouseWheel = (((::GetVersion & 0x80000000) && LOBYTE(LOWORD(::GetVersion) == 4)) || (!(::GetVersion & 0x80000000) && LOBYTE(LOWORD(::GetVersion) == 3))) ? ::RegisterWindowMessage(MSH_MOUSEWHEEL) : 0; </li>  Add this line to your dialog class' message map after the AFX_MSG_MAP section: ON_REGISTERED_MESSAGE(_afxMsgMouseWheel, OnRegisteredMouseWheel) </li>  Add a member function called OnRegisteredMouseWheel passing a WPARAM and LPARAM and returning LRESULT to your Dialog class. Add the following code in the function definition (code taken from Winfrm.cpp): LRESULT CMyDialog::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 { lResult = ::SendMessage(hwFocus, WM_MOUSEWHEEL,                           (wParam << 16) | keyState, lParam); hwFocus = ::GetParent(hwFocus); }     while (lResult == 0 && hwFocus != NULL && hwFocus != hwDesktop); }  return lResult; }                       </li></ol>

Now your application's dialog class should be able to receive the WM_MOUSEWHEEL message.

<div class="moreinformation_section">

MORE INFORMATION
There is an inherent difference between Windows NT 4.0 and Windows 95 regarding Intellimouse messages. On Windows NT 4.0, some messages are already registered by the system, or the support of the mouse wheel is already built into the operating system (OS) and the OS sends WM_MOUSEWHEEL message to any window.

is provided by a separate module, mswheel, which generates the MSH_MOUSEWHEEL message. This module, which consists of Mswheel.exe and Mswheel.dll, is installed with the Intellipoint software that is shipped with the Intellimouse pointing device. Windows 95 sends the WM_MOUSEWHEEL message only to the window that has registered the MSH_MOUSEWHEEL window message.

The CMainFrame class of MFC registers the MSH_MOUSEWHEEL message if the application is running on a Windows 95 computer, and sends a WM_MOUSEWHEEL message in the handler of this message. Hence, a view for SDI/MDI application receives the notification for this message. Dialog classes in MFC do not receive the WM_MOUSEWHEEL message because the CDialog class does not register the MSH_MOUSEWHEEL message.

<div class="references_section">