Results 1 to 10 of 10

Thread: Mouse wheel scrolling on VB6 compiled app (not the IDE)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    713

    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?

  2. #2
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,936

    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.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,930

    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    713

    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.

  5. #5
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,936

    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.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    713

    Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)

    Quote Originally Posted by baka View Post
    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!

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,930

    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,930

    Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)

    Quote Originally Posted by paulg4ije View Post
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,250

    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

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    713

    Re: Mouse wheel scrolling on VB6 compiled app (not the IDE)

    Thanks everyone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width