Page 1 of 2 12 LastLast
Results 1 to 40 of 47

Thread: VB6-MouseWheel With Any Control

  1. #1

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    VB6-MouseWheel With Any Control

    Note: The most up-to-date version of the code is in post #1. WheelHookAllControls.zip includes MSFlexGrid example


    It was brought to my attention that controls that already responded to the MouseWheel (combobox, textbox, etc.), would prevent MouseWheel events passing to form, so even if you were over a grid, it would be the combobox that scrolled, and you would have to remove focus from the control before it would work

    I have fixed this so that you can Hook the controls, and if a WM_MOUSEWHEEL event occurs and the mouse is not over the control, it triggers the MouseWheel sub on the form.

    The code for scrolling the grid if it's the activecontrol will work fine regardless of other controls responding to scroll events.



    EDIT: This was recovered from the original post. The original two attachments are the links WheelHook-NestedControls and WheelHook-AllControls:

    These example projects demonstrate enabling the MouseWheel for any control (multiple controls / multiple forms).

    Examples

    Enabling MouseWheel Support with any control - attached to post #1
    14/03/06: Slight correction to code
    20/04/06: Minor modification to code (more info: post #9)
    12/01/07: Nested Controls example created allowing the mousewheel to work with controls nested to any depth - incorporates fixes from other posts (1, 2) - attached to post #1

    Scrolling the MSFlexGrid that the mouse is over - attached to post #2
    21/02/06: Small bug fix

    Scrolling if the MSFlexGrid is the active control - attached in post #13 of original thread


    The hooking code was modified from here.
    Original thread, with suggestions from other members.

    Note:
    These codes use subclassing which can cause your IDE to crash if your code is incorrectly ended (e.g. via the stop button).
    See here for adding in code to detect if your program is running in the IDEWheelHook-NestedControls.zipWheelHook-AllControls.zip
    Attached Files Attached Files

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: VB6 - MouseWheel Scrolling in MSFlexGrids

    Excellent work - thanks!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: VB6 - MouseWheel Scrolling in MSFlexGrids

    Very good!!

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 - MouseWheel Scrolling in MSFlexGrids

    Nice job!

  5. #5

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    New example to demonstrate enabling the MouseWheel for any control (multiple controls / multiple forms) - see post #1

  6. #6

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Slight error in my Select Case code - corrected. See Post #1

  7. #7
    New Member
    Join Date
    Apr 2006
    Posts
    3

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Hi, nice code and one correction:

    VB Code:
    1. Public Sub MouseWheel(ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
    2.  
    3. bOver = (ctl.Visible And IsOver(ctl.HWnd, Xpos, Ypos) [B]And ctl.Enabled = True[/B])
    Last edited by darki; Apr 20th, 2006 at 04:51 AM.

  8. #8

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Thanks for pointing that out. Rather than checking there I would recommend checking within the Select Case clause, that way it allows the program to deal with it on a per-control basis. For example, you may want to scroll the grid even though it is disabled.

    I would therefore make the below change instead, and indeed have done so to the code in post #1
    VB Code:
    1. Case TypeOf ctl Is ListBox, TypeOf ctl Is TextBox, TypeOf ctl Is ComboBox
    2.           ' These controls already handle the mousewheel themselves, so allow them to:
    3.           [B]If ctl.Enabled Then[/B] ctl.SetFocus

  9. #9
    New Member
    Join Date
    Apr 2006
    Posts
    3

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Your solution is better!

    I wrote one universal MouseWheel function for all forms. Sometimes controls are disabled like Textbox and .setFocus crashed.

    VB Code:
    1. 'added frm, just different solution
    2. Public Sub MouseWheel(frm As Form, ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
    3.  
    4. For Each ctl In frm.Controls
    5. '...

  10. #10
    New Member
    Join Date
    Apr 2006
    Posts
    1

    Wink Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Great work but...

    I do not like individually testing for min and max for each control, so I extracted those lines into a function in the module:
    Public Function MouseWheelChange(CurrentValue As Variant, DeltaValue As Variant, MinValue As Variant, MaxValue As Variant) As Variant
    Dim newvalue As Variant
    newvalue = CurrentValue + DeltaValue
    If newvalue < MinValue Then
    newvalue = MinValue
    ElseIf newvalue > MaxValue Then
    newvalue = MaxValue
    End If
    MouseWheelChange = newvalue
    End Function

    The MouseWheel() sub now looks like:
    Public Sub MouseWheel(ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
    On Error Resume Next
    If TypeOf Me.ActiveControl Is VScrollBar Then
    With VScroll1
    .Value = MouseWheelChange(.Value, Sgn(Rotation) * .LargeChange, .Min, .Max)
    End With
    ElseIf TypeOf Me.ActiveControl Is TextBox Then
    Text1.Text = MouseWheelChange(Text1.Text, Rotation, -1000, 1000)
    End If
    End Sub

    Just my 2 cents.

  11. #11
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Great code, bushmobile, but is there any way to add support for a tilt wheel (Microsoft IntelliMouse Explorer 5.0). Thanx!
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  12. #12

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    I don't know.

    In Vista there's going to be a WM_MOUSEHWHEEL message - but i think it might be interpreted as a WM_HSCROLL message pre-vista.

    Try adding the constant in the declarations:
    VB Code:
    1. Private Const WM_HSCROLL = &H114
    then in the WindowProc sub add another case:
    VB Code:
    1. Case WM_HSCROLL
    2.         Debug.Print "HSCROLL Message to " & Lwnd
    and see what happens.

  13. #13
    New Member
    Join Date
    Jun 2006
    Posts
    4

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Hi, this is great piece of code.(exactly what I have been looking for) That being said I’m having some trouble implementing it into one of my projects. I have a form with a Sstab. On the tab I have a combo box and an MsFlexgrid.

    I’m getting an error in the module when ever I use Hook Controls to be ignored: Call WheelHook(Combo1.hWnd) ( if I don’t hook the Combo1 then I don’t get the error. But then the msflexgrid has to have focus for the mouse scroll to work)

    I get an Object Variable or with block variable not set Error. And VB highlights this line in the module: GetForm(GetParent(Lwnd)).MouseWheel MouseKeys, Rotation, Xpos, Ypos (I’m not familiar at all with API calls so I’m at a loss)

    I get this error when I have used the mouse scroll 1st over the combo box and then use the mouse scroll over the form or over the flexgrid.

    Any help would be greatly appreciated.( Just being able to mouse scroll all the controls is great, but you spoiled me with sample using the mouse over)

  14. #14

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    in the module, replace the GetParent API declaration with this one:
    VB Code:
    1. Private Declare Function GetAncestor Lib "user32.dll" ( _
    2.                 ByVal hwnd As Long, _
    3.                 ByVal gaFlags As Long) As Long
    add a constant
    VB Code:
    1. Private Const GA_ROOT = 2
    and then change the line that errors with this one:
    VB Code:
    1. GetForm(GetAncestor(Lwnd, GA_ROOT)).MouseWheel MouseKeys, Rotation, Xpos, Ypos
    should work.

  15. #15
    New Member
    Join Date
    Jun 2006
    Posts
    4

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    I tried your solution and it crashed, so I went back and looked at the module
    And saw there was still a reference to GetParent:

    ' it's not a form
    If Not IsOver(Lwnd, Xpos, Ypos) And IsOver(GetParent(Lwnd), Xpos, Ypos) Then
    ' it's not over the control and is over the form,

    So instead of of Replacing the GetParent API declaration with the GetAncestor API declaration you must keep the GetParent API and
    Add the GetAncestor API

    Anyway you put me on the right path and it works like a charm. Thanks
    so much

  16. #16

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    i forgot about that GetParent. you could also replace that one with GetAncestor if you want.

  17. #17
    New Member
    Join Date
    Jun 2006
    Posts
    4

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    I tested it, and it seems you are correct again. Thanks

  18. #18
    Addicted Member adamm83's Avatar
    Join Date
    Oct 2005
    Location
    Toronto, ON, Canada
    Posts
    180

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Ok so here's the situation. I have a mdi container with a child form inside of it. The child forms is longer than the mdi container which creates a vertical scroll bar.

    Is there any way to scroll the mdi container with the mouse wheel. Can this code accomplish what I want to do??

    Thanks! Any help would be appreciated!
    adamm
    ACM Designs

    Codebank:
    RegOpen - Open registry keys in Regedit quick & easily


    "A man who tries to catch two rabbits at the same time will catch neither."

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Use the same idea, but use the mousewheel movement to change the value of the scrollbar.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  20. #20
    Addicted Member adamm83's Avatar
    Join Date
    Oct 2005
    Location
    Toronto, ON, Canada
    Posts
    180

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    REMOVED: nvm, my topic is being helped here
    Last edited by adamm83; Jul 6th, 2006 at 03:38 PM.
    adamm
    ACM Designs

    Codebank:
    RegOpen - Open registry keys in Regedit quick & easily


    "A man who tries to catch two rabbits at the same time will catch neither."

  21. #21
    Junior Member
    Join Date
    Aug 2006
    Posts
    18

    Question Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    This code is great but I need a small help:
    How can I use the wheel when the control is (or controls are) contained in a picturebox?

    Thanks

  22. #22

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Does what is mentioned in posts #14, #15, #16, #17 solve your problem?

  23. #23
    Junior Member
    Join Date
    Aug 2006
    Posts
    18

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    I've already follow those suggests without any result.
    I uploaded your example with all the controls included in a picturebox.
    As you can see, that picturebox is always onfocus.

    Truely I'm not an API expert

    What should I do?
    Attached Files Attached Files

  24. #24

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    hmmm, i've had a look at the brief look at the code but couldn't see anything glaringly wrong.

    Unfortunately I don't think i'll have access to VB until Sunday, so you'll probably have to wait until then before i can give you a proper answer.

  25. #25
    Junior Member
    Join Date
    Aug 2006
    Posts
    18

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    It means I'm not compleately a newbie
    oki, I'll work around something else.
    Thank you alot

  26. #26

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    ok, was fairly simple when managed to get my hands on VB

    Don't call the PictureBox 'Picture' - it's a reserved word - i renamed it picMain and then changed this part of the Select Case:
    VB Code:
    1. Case TypeOf ctl Is PictureBox
    2.             If Not ctl Is picMain Then
    3.                 PictureBoxZoom ctl, MouseKeys, Rotation, Xpos, Ypos
    4.             Else
    5.                 bHandled = False
    6.             End If

  27. #27
    Junior Member
    Join Date
    Aug 2006
    Posts
    18

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    GREAT
    I think I have still to study and practise alot

    Thank you very much Bushmobile!

  28. #28
    New Member
    Join Date
    Aug 2006
    Posts
    2

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Hi bushmobile,

    I used your mousewheel code in an existing VB6 app and it worked fine. I altered it slightly because I'm using an MSHFlexgrid instead of an MSFlexgrid. I'm running into another problem though. In my MSHFlexgrid I list rows of invoices, some billed and some unbilled. The user has options to list all invoices, only billed invoices or only unbilled invoices. When the user takes the option to list only billed invoices, the program loops through the grid row by row and sets the .rowheight = 0 for those rows that are unbilled and and sets the .rowheight = -1 for rows that are billed. This code works great for hiding rows but for whatever reason, once the routine completes, the mousewheel no longer works on the grid. I tried all kinds of things to figure out where the problem is and everything seems to point to setting the rowheight to 0. I tried setting the rowheight to like 50 and that worked but it looked ugly. Any thoughts?

    Thanks.

  29. #29
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Great Job

  30. #30
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Quote Originally Posted by qvqnytowl
    everything seems to point to setting the rowheight to 0. I tried setting the rowheight to like 50 and that worked but it looked ugly. Any thoughts?
    How about not loading the grid with the records you don't want displayed? Are you loading it from a database? If so, the solution is simple - a Where clause in your select statement.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  31. #31

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    @qvqnytowl:

    whoops, sorry - i completely forgot about your question. This version should work fine for you:
    VB Code:
    1. Public Sub FlexGridScroll(ByRef FG As MSFlexGrid, ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
    2.     Dim lNewVal As Long, lStep As Long
    3.    
    4.     With FG
    5.         lStep = .Height \ .RowHeight(0)
    6.         If .Rows < lStep Then Exit Sub
    7.        
    8.         If Rotation > 0 Then
    9.             lNewVal = .TopRow - lStep
    10.             If lNewVal < .FixedRows Then lNewVal = .FixedRows
    11.             Do While .RowHeight(lNewVal) = 0 And lNewVal > .FixedRows
    12.                 lNewVal = lNewVal - 1
    13.             Loop
    14.         Else
    15.            
    16.             lNewVal = .TopRow + lStep
    17.             If lNewVal > .Rows - 1 Then lNewVal = .Rows - 1
    18.             Do While .RowHeight(lNewVal) = 0 And lNewVal < .Rows - 1
    19.                 lNewVal = lNewVal + 1
    20.             Loop
    21.         End If
    22.         .TopRow = lNewVal
    23.     End With
    24. End Sub

  32. #32
    Junior Member
    Join Date
    Dec 2006
    Location
    Toronto, Canada
    Posts
    19

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Worked great - thanks!

  33. #33
    Junior Member
    Join Date
    Dec 2006
    Location
    Toronto, Canada
    Posts
    19

    VB6 Closes unexpectedly - MouseWheel with MSFlexGrid Scrolling

    Unexpected problem:

    Running WinHook2 example (project1):
    Stick a dummy event on form1
    Click Run Tool Button - all okay
    Click Stop Tool Button - all okay
    Put a breakpoint on the dummy event
    Run - VB6 freezes when it hits the breakpoint
    ctlBreak has no effect - must be ended with
    Task Manager

    In my own project:
    When WheelHook has been called, and a breakpoint (anywhere
    in the project) has been hit, VB6 proceeds normally but
    clicking the Stop tool button causes VB6 to close immediately.

    Commenting out the WheelHook call results in normal behavior.

    Any thoughts?

    Thanks,
    John

  34. #34
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    You cannot have subclassing when in the IDE - it causes the IDE to blow up (like you just discovered!).

    Look at posts 36 and 37 in this thread of a way around this problem:

    http://www.vbforums.com/showthread.php?t=388077

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  35. #35

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Quote Originally Posted by Me in post #1
    These codes use subclassing which can cause your IDE to crash if your code is incorrectly ended (e.g. via the stop button).
    subclassing works fine in the IDE (and the exe) unless the normal program flow is interrupted - for example, by pressing the stop button or attempting any runtime debugging.

  36. #36
    Junior Member
    Join Date
    Dec 2006
    Location
    Toronto, Canada
    Posts
    19

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Thanks guys!
    I've learned sooo much these last few days.
    Lucky to have found this site!!

  37. #37

    Thread Starter
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Added an example that works with nested controls - see post #1 for details

  38. #38
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    There appears to be an error with the code that works by hovering over a flexgrid.
    You can end up with an invalid row value.
    Isn't it easier to just do something like this?
    vb Code:
    1. Public Sub FlexGridScroll(ByRef FG As MSFlexGrid, ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
    2.   Dim NewValue As Long
    3.   Dim Lstep As Single
    4.  
    5.   On Error Resume Next
    6.   With FG
    7. '    Lstep = .Height / .RowHeight(0)
    8. '    Lstep = Int(Lstep)
    9. '    If .Rows < Lstep Then Exit Sub
    10. '    Do While Not (.RowIsVisible(.TopRow + Lstep))
    11. '      Lstep = Lstep - 1
    12. '    Loop
    13. '    If Rotation > 0 Then
    14. '        NewValue = .TopRow - Lstep
    15. '        If NewValue < 1 Then
    16. '            NewValue = 1
    17. '        End If
    18. '    Else
    19. '        NewValue = .TopRow + Lstep
    20. '        If NewValue > .Rows - 1 Then
    21. '            NewValue = .Rows - 1
    22. '        End If
    23. '    End If
    24.  
    25.     If Rotation > 0 Then
    26.         NewValue = .TopRow - 5
    27.         If NewValue < 1 Then
    28.             NewValue = 1
    29.         End If
    30.     Else
    31.         NewValue = .TopRow + 5
    32.         If NewValue > .Rows - 1 Then
    33.             NewValue = .Rows - 1
    34.         End If
    35.     End If
    36.     .TopRow = NewValue
    37.   End With
    38. End Sub
    This also doesn't scroll so much either.
    I put in 5 as it is my preferred number of rows to scroll.
    There is a setting in the control panel which lets you specify number of lines to scroll at a time
    It would good if the code could pick this up and insert it.

  39. #39
    New Member
    Join Date
    Aug 2006
    Posts
    2

    Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Hello everyone,

    For the last couple of years, I used the code listed in the above posts to do my mouse scrolling and it worked fairly well. One thing I didn't like was that if I was debugging my program and the program hit a break point, VB would close with the dreaded "VB must shutdown now..." message. If I had made a couple of changes but forgotten to hit the save button prior, oh well. Small inconvenience I suppose.

    The other day I found this zip file in one of my folders and wondered why I had never tried it. Maybe it's been mentioned on this board before and if so, I apologize. I unzipped it and loaded it and I swear, it couldn't work more perfectly for me. The only setting I changed that wasn't a default was on the Settings tab where I checked the "Scroll the window underneath the mouse pointer" option. I had concerns that it might not work for Vista but I loaded it on a Vista machine and it worked perfectly. It even overrides the MouseWheel code if you leave it in your application. (I commented out all my code so I wouldn't have the debug problem anymore.)

    Oh, did I mention it's free?

    http://www.geocities.com/SiliconVall...freewheel.html

    Anyway, I hope this is helpful to someone.

  40. #40
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,319

    Thumbs down Re: VB6 - MouseWheel with Any Control (originally just MSFlexGrid Scrolling)

    Quote Originally Posted by Elroy View Post
    I'll stand by both of those quotes until I'm shown some specific code that contradicts them. I subclass all kinds of stuff in my primary project (with 100s of module and 100s of forms), and I don't have any problems at all with crashing the IDE.
    If you really want to experience the crash yourself, it's very easy to replicate. Slap a "Microsoft InkEdit Control" on a form, subclass it with your favorite method, don't even need to write any additional code, press F5 to run the project, close the form, the IDE will crash. To avoid the crash, unsubclass it explicitly.

    Just because unsubclassing on "WM_DESTROY" works for most controls doesn't mean it's a good practice but to each his own I guess...
    Last edited by Shaggy Hiker; Feb 5th, 2023 at 10:47 PM. Reason: Removed sniping.

Page 1 of 2 12 LastLast

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