Microsoft KB Archive/231465: Difference between revisions
m (Text replacement - "&" to "&") |
m (Text replacement - """ to """) |
||
Line 102: | Line 102: | ||
Private Const GWL_WNDPROC = (-4) | Private Const GWL_WNDPROC = (-4) | ||
Private Declare Function CallWindowProc Lib | Private Declare Function CallWindowProc Lib "user32" Alias _ | ||
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _ | |||
ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long | ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long | ||
Private Declare Function SetWindowLong Lib | Private Declare Function SetWindowLong Lib "user32" Alias _ | ||
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _ | |||
ByVal dwNewLong As Long) As Long | ByVal dwNewLong As Long) As Long | ||
Private Declare Function RegisterWindowMessage Lib | Private Declare Function RegisterWindowMessage Lib "user32" _ | ||
Alias | Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long | ||
Public Sub SubClassHookForm() | Public Sub SubClassHookForm() | ||
MSWHEEL_ROLLMSG = RegisterWindowMessage( | MSWHEEL_ROLLMSG = RegisterWindowMessage("MSWHEEL_ROLLMSG") | ||
' On Windows NT 4.0, Windows 98, and Windows Me, change the above line to | ' On Windows NT 4.0, Windows 98, and Windows Me, change the above line to | ||
' MSWHEEL_ROLLMSG = &H20A | ' MSWHEEL_ROLLMSG = &H20A | ||
Line 126: | Line 126: | ||
If msg = MSWHEEL_ROLLMSG Then | If msg = MSWHEEL_ROLLMSG Then | ||
Debug.Print | Debug.Print "Receive MSWHEEL_ROLLMSG" | ||
End If | End If | ||
WindowProc = CallWindowProc(m_PrevWndProc, hwnd, msg, wParam, lParam) | WindowProc = CallWindowProc(m_PrevWndProc, hwnd, msg, wParam, lParam) | ||
Line 132: | Line 132: | ||
</pre></li> | </pre></li> | ||
<li>Press the '''F5''' key to run the program and roll the wheel button while the mouse pointer is positioned over Form1.</li> | <li>Press the '''F5''' key to run the program and roll the wheel button while the mouse pointer is positioned over Form1.</li> | ||
<li>You will see | <li>You will see "'''Receive MSWHEEL_ROLLMSG'''" displayed in the '''Immediate Window'''.</li> | ||
<li>Stop the program. Do '''NOT''' use the '''END''' button on the toolbar per the warning note at the beginning of this section.</li> | <li>Stop the program. Do '''NOT''' use the '''END''' button on the toolbar per the warning note at the beginning of this section.</li> | ||
<li>On the '''File''' menu, click '''Add Project... Select ActiveX Control''' in the '''Add Project''' dialog and click '''OK'''. UserControl1 is created by default.</li> | <li>On the '''File''' menu, click '''Add Project... Select ActiveX Control''' in the '''Add Project''' dialog and click '''OK'''. UserControl1 is created by default.</li> | ||
<li>Close the '''Project2''' window and add a '''UserControl1''' to Form1.</li> | <li>Close the '''Project2''' window and add a '''UserControl1''' to Form1.</li> | ||
<li>Press the '''F5''' key to start the program and roll the wheel button while pointing the mouse on Form1.</li> | <li>Press the '''F5''' key to start the program and roll the wheel button while pointing the mouse on Form1.</li> | ||
<li>The string | <li>The string "Receive MSWHEEL_ROLLMSG" no longer occurs in the Immediate Window. If you use Spy++ to detect all the Windows messages received by Form1, you will see that WM_MOUSEMOVE is received instead of WM_MOUSEWHEEL when you roll the wheel of the mouse after the UserControl is added.</li></ol> | ||
Latest revision as of 13:44, 21 July 2020
Article ID: 231465
Article Last Modified on 1/16/2004
APPLIES TO
- Microsoft Visual Basic 5.0 Learning Edition
- Microsoft Visual Basic 6.0 Learning Edition
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
This article was previously published under Q231465
SYMPTOMS
After adding a User control to a Form, the Visual Basic design environment (IDE) ignores the WM_MOUSEWHEEL message when you roll the wheel of the mouse. This problem does not occur on Windows NT or Windows 2000.
CAUSE
The Visual Basic Design Environment (IDE) is not compatible with early versions of the Microsoft Intellimouse driver.
RESOLUTION
To resolve this bug, install version 4.11 or version 4.2 of the IntelliPoint driver.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
MORE INFORMATION
Steps to Reproduce Behavior
WARNING: Failure to unhook a window before its imminent destruction may result in application errors, Invalid Page Faults, and data loss. This is due the fact that the new WindowProc function being pointed to no longer exists, but the window has not been notified of the change. Always unhook the sub-classed window upon unloading the sub-classed form or exiting the application. This is especially important while debugging an application that uses this technique within the Microsoft Visual Basic Development Environment (IDE). Pressing the End button or selecting End from the Run menu without unhooking may cause an Invalid Page Fault and close Microsoft Visual Basic. Changes to the active project will be lost.
- Start a new Visual Basic Standard EXE project. Form1 is created by default.
Add the following code to the General Declaration section of Form1:
Option Explicit Private Sub Form_Load() Me.Show Call SubClassHookForm End Sub Private Sub Form_Unload(Cancel As Integer) Call SubClassUnHookForm End Sub
- On the Project menu, select the Add Module menu option.
Add the following code to the General Declaration section of Module1:
Option Explicit Private MSWHEEL_ROLLMSG As Long Private m_PrevWndProc As Long Private Const GWL_WNDPROC = (-4) Private Declare Function CallWindowProc Lib "user32" Alias _ "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, _ ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias _ "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Private Declare Function RegisterWindowMessage Lib "user32" _ Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long Public Sub SubClassHookForm() MSWHEEL_ROLLMSG = RegisterWindowMessage("MSWHEEL_ROLLMSG") ' On Windows NT 4.0, Windows 98, and Windows Me, change the above line to ' MSWHEEL_ROLLMSG = &H20A m_PrevWndProc = SetWindowLong(Form1.hwnd, GWL_WNDPROC, _ AddressOf WindowProc) End Sub Public Sub SubClassUnHookForm() Call SetWindowLong(Form1.hwnd, GWL_WNDPROC, m_PrevWndProc) End Sub Public Function WindowProc(ByVal hwnd As Long, ByVal msg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long If msg = MSWHEEL_ROLLMSG Then Debug.Print "Receive MSWHEEL_ROLLMSG" End If WindowProc = CallWindowProc(m_PrevWndProc, hwnd, msg, wParam, lParam) End Function
- Press the F5 key to run the program and roll the wheel button while the mouse pointer is positioned over Form1.
- You will see "Receive MSWHEEL_ROLLMSG" displayed in the Immediate Window.
- Stop the program. Do NOT use the END button on the toolbar per the warning note at the beginning of this section.
- On the File menu, click Add Project... Select ActiveX Control in the Add Project dialog and click OK. UserControl1 is created by default.
- Close the Project2 window and add a UserControl1 to Form1.
- Press the F5 key to start the program and roll the wheel button while pointing the mouse on Form1.
- The string "Receive MSWHEEL_ROLLMSG" no longer occurs in the Immediate Window. If you use Spy++ to detect all the Windows messages received by Form1, you will see that WM_MOUSEMOVE is received instead of WM_MOUSEWHEEL when you roll the wheel of the mouse after the UserControl is added.
REFERENCES
For additional information, please click the article number below to view the article in the Microsoft Knowledge Base:
168795 HOWTO: Hook Into a Window's Messages using AddressOf
Additional query words: wm_mousewheel user control hook
Keywords: kbbug kbpending KB231465