PRB: CDialog Class Doesn't Receive the WM_MOUSEWHEEL Message on Windows 95 Computers
ID: Q237998
|
The information in this article applies to:
-
The Microsoft Foundation Classes (MFC), included with:
-
Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0
on the following platforms: Win95
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.
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.
RESOLUTION
You can work around the problem by following the steps described below:
- 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;
- Add this line to your dialog class' message map after the AFX_MSG_MAP section:
ON_REGISTERED_MESSAGE(_afxMsgMouseWheel, OnRegisteredMouseWheel)
- 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;
}
Now your application's dialog class should be able to receive the WM_MOUSEWHEEL message.
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.
REFERENCES
For additional information on WM_MOUSEWHEEL message please refer to the following resources:
- Documentation of WM_MOUSEWHEEL message in MSDN library.
- Winfrm.cpp file in mfc/src directory for the way CMainFrame handles this message.
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Sreedhar Pelluru, Microsoft Corporation
Additional query words:
Keywords : kbMFC kbMouse kbVC500 kbVC600 kbWinOS95 kbDSupport kbGrpMFCATL
Version : winnt:5.0,6.0
Platform : winnt
Issue type : kbprb