-
Jun 29th, 2022, 08:49 AM
#1
Thread Starter
Fanatic Member
Mouse wheel scrolling on VB6 compiled app (not the IDE)
I would like to add mouse wheel scrolling to an old VB6 app. I am not bothered about adding it the IDE, just the compiled app. I have tried a few of the hundreds of examples on "the internet" but haven't yet found a reliable one that works on all forms. I did try one that worked only on Flexgrids and it wasn't bad but I had one or two unexplained crashes. The software I would like to add the scrolling to runs on Windows 10 and Windows 11 PCs - all 64-bit.
So, has anyone found a reliable, consistent method of adding mouse wheel scrolling to VB6 apps?
-
Jun 29th, 2022, 08:55 AM
#2
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
did u try subclassing?
thats what most people are using.
very easy.
create a project, add this in Form_Load
StartClassing Me.hWnd
add a module:
Code:
Private Const WM_NCDESTROY = &H82
Private Const WM_MOUSEWHEEL = &H20A
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 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
Dim OldWindowProc&
Sub StartClassing(ByVal hWnd&)
OldWindowProc = SetWindowLong(hWnd, -4, AddressOf SubClassingProc)
End Sub
Function SubClassingProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_NCDESTROY: SetWindowLong hWnd, -4, OldWindowProc
Case WM_MOUSEWHEEL: Form1.Caption = CStr(wParam)
Case Else
SubClassingProc = CallWindowProc(OldWindowProc, hWnd, Msg, wParam, lParam)
End Select
End Function
Last edited by baka; Jun 29th, 2022 at 09:13 AM.
-
Jun 29th, 2022, 09:21 AM
#3
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
Yeah, I use subclassing too. Because this is an unraised event in VB6 about the only two ways I could think of to do this would be:
1) Subclassing, to raise the mouse wheel events.
2) Possibly a very fast timer to see if the mouse wheel as changed.
I've never done #2, but I certainly wouldn't recommend it, as fast timers are just going to chew up your computer's resources. Subclassing is really the only way.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 29th, 2022, 09:32 AM
#4
Thread Starter
Fanatic Member
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
Thanks for your help. I assume this is just partial code to demonstrate the principle? The form caption alternates between 7864320 on scroll up and -7864320 on scroll down. I guess I could use that as a flag to increment or decrement the scroll position of my (in this case) MSHFlexgrid.
-
Jun 29th, 2022, 09:44 AM
#5
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
yeah exactly. this is just the basics. u need to implement what u want to react with the wheel.
remember that subclassing can crash your application.
so ALWAYS save your project before u run it.
-
Jun 29th, 2022, 10:01 AM
#6
Thread Starter
Fanatic Member
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
Originally Posted by baka
yeah exactly. this is just the basics. u need to implement what u want to react with the wheel.
remember that subclassing can crash your application.
so ALWAYS save your project before u run it.
Many thanks. I'll see what I can come up with. My users have been running the software for 15 years without mouse wheel scrolling but it bugs me that it doesn't work!
-
Jun 29th, 2022, 10:03 AM
#7
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
The two windows messages I monitor for in the subclassing procedure are:
Code:
Const WM_MOUSEWHEEL As Long = &H20A&
Const WM_MOUSEHWHEEL As Long = &H20E&
And then I just look for wParam being greater or less than zero to determine up or down (or left or right for WM_MOUSEHWHEEL).
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 29th, 2022, 10:04 AM
#8
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
Originally Posted by paulg4ije
My users have been running the software for 15 years without mouse wheel scrolling but it bugs me that it doesn't work!
VB6 came out before mouse wheels were popular.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 29th, 2022, 02:55 PM
#9
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
If it’s about scrolling the MSFlexGrid then check this thread
https://www.vbforums.com/showthread....th-Mouse-Wheel
-
Jun 30th, 2022, 12:45 AM
#10
Thread Starter
Fanatic Member
Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|