PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel-VBForums
Page 1 of 2 12 LastLast
Results 1 to 40 of 41

Thread: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

  1. #1

    Thread Starter
    Member orozcore's Avatar
    Join Date
    Aug 2005
    Posts
    36

    Resolved [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    I'm using a flexgrid to show some data from my database.

    So there's a problem i can't scroll down my flexgrid with the mouse i have to click on the scroll down bar. there's another way to do this using the mouse to scroll down to the last item contained in my flexgrid a not use the scroll down bar.
    Last edited by orozcore; Feb 17th, 2006 at 09:19 PM.

    I'm an Angel Walking in Darkness

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

    Re: Scroll a MSFlexGrid

    i think you have to hook the mouse: http://www.andreavb.com/tip060008.html



    20/02/2005 Note: There is now a CodeBank example demonstrating how to do this: http://www.vbforums.com/showthread.php?t=388222
    Last edited by bushmobile; Feb 19th, 2006 at 07:40 PM.

  3. #3

    Thread Starter
    Member orozcore's Avatar
    Join Date
    Aug 2005
    Posts
    36

    Re: Scroll a MSFlexGrid

    I have a problem when i call the Hook procedure

    i do it in the Form_Load event

    like this
    VB Code:
    1. Hook myflexgrid.hWnd


    and when i compile my programm an error appears on AddrOf("WindowProc"))

    Sub or Function not defined


    VB Code:
    1. Public Sub Hook(ByVal hControl_ As Long)
    2.     hControl = hControl_
    3.     lPrevWndProc = SetWindowLong(hControl, GWL_WNDPROC, AddrOf("WindowProc"))
    4. End Sub


    so i don't know if i have to declare another API or i'm missing another procedure

    I'm an Angel Walking in Darkness

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

    Re: Scroll a MSFlexGrid

    try changing that to AddressOf

    here's another example: http://www.adit.co.uk/html/mousewheelsupport.html

  5. #5

    Thread Starter
    Member orozcore's Avatar
    Join Date
    Aug 2005
    Posts
    36

    Re: Scroll down a MSFlexGrid with Mouse Wheel

    when i change the AddrOf to AddressOf vb says Expected: identifier

    Maybe i can test the other example to check if that works

    and if a get any results i will post them here to let you know how well i'm doing that change on the code

    i notice that in this code i hook the Form

    VB Code:
    1. Public Sub WheelHook(PassedForm As Form)
    2.  
    3.     On Error Resume Next
    4.  
    5.     Set MyForm = PassedForm
    6.     LocalHwnd = PassedForm.hWnd
    7.     LocalPrevWndProc = SetWindowLong(LocalHwnd, GWL_WNDPROC, AddressOf WindowProc)
    8. End Sub

    I'm an Angel Walking in Darkness

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

    Re: Scroll down a MSFlexGrid with Mouse Wheel

    i think that second example looks better, go with that.

  7. #7

    Thread Starter
    Member orozcore's Avatar
    Join Date
    Aug 2005
    Posts
    36

    Re: Scroll down a MSFlexGrid with Mouse Wheel

    i made this change
    VB Code:
    1. AddrOf ("WindowProc")
    2.  
    3. 'for this
    4.  
    5. AddressOf WindowProc

    but there's no change in my flexgrid

    maybe when a call Hook i have to Hook the Form

    I'm an Angel Walking in Darkness

  8. #8

    Thread Starter
    Member orozcore's Avatar
    Join Date
    Aug 2005
    Posts
    36

    Re: Scroll down a MSFlexGrid with Mouse Wheel

    when i Hook Me.hWnd

    says Objects doesn't support this property or method 438

    maybe i have to check better the lines of the code


    and test the other code and see any change to post and RESOLVE this thread

    THX

    I'm an Angel Walking in Darkness

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

    Re: Scroll down a MSFlexGrid with Mouse Wheel

    I've attached a example project of the second link.
    Attached Files Attached Files

  10. #10

    Thread Starter
    Member orozcore's Avatar
    Join Date
    Aug 2005
    Posts
    36

    Re: Scroll down a MSFlexGrid with Mouse Wheel

    I have tested the code in my programm and works fine.

    but there's something i see

    I have to copy and paste the procedure MouseWheel in each Form i have, because i have at least 15 forms with a flexgrid so maybe i can put that in my module

    I'm an Angel Walking in Darkness

  11. #11

    Thread Starter
    Member orozcore's Avatar
    Join Date
    Aug 2005
    Posts
    36

    Cool Re: Scroll down a MSFlexGrid with Mouse Wheel

    I have made some changes to the example code you sent me bushmobile

    The problem is that in some forms I have two MSFlexGrid's and the hook only worked with one, because the flexgrid is only in the Form and the MouseWheel uses MSlexGrid1 but in this case i have more than one FlexGrid, and not exactly named MSFlexGrid1

    So i did this changes to improve your code:

    - Put the MouseWheel in the Module bas including another variable as parameter MyGrid as MSFlexGrid, to change the control to make the mousewheel changes

    - Create a variable in my module, MyGrid as MSFlexGrid

    - Add a parameter in the WheelHook of my PassedFlexGrid and set my variable MyGrid to this control passed

    - Modify the WindowProc procedure to call mousewheel from my module and set the variable MyGrid in MouseWheel procedure.

    -To call WheelHook i do it when in the Events MSFlexGrid_Click and MSFlexGrid_GotFocus like this

    VB Code:
    1. Private Sub MSFlexGrid1_Click()
    2.     WheelUnHook
    3.     WheelHook Me, MSFlexGrid1
    4. End Sub
    5.  
    6. Private Sub MSFlexGrid1_GotFocus()
    7.     WheelUnHook
    8.     WheelHook Me, MSFlexGrid1
    9. End Sub

    and Unhook when the Control LostFocus

    VB Code:
    1. Private Sub MSFlexGrid1_LostFocus()
    2.     WheelUnHook
    3. End Sub

    you can check the changes in the uploaded zip file
    Attached Files Attached Files

    I'm an Angel Walking in Darkness

  12. #12
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    I thought this problem was all related to the driver associated with the particular mouse. Did you attempt to fix it without using this API concept?

    Did you also consider change the hook based on what grid the mouse was hovered over - instead of actual focus?

    *** 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

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    I have attached the code to have it working with multiple flexgrids & forms.

    szlamany: you can't always guarantee that your user will have mouse drivers that support it - mine certainly doesn't!
    Attached Files Attached Files

  14. #14
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Thanks so much. I've had complaints from some of my clients about this very problem - I've always downplayed them and told them to find better drivers.

    This is a much nicer solution - I will try to implement it!

    Thanks again!

    *** 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

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    This is a great solution, I only have two 'bad' comments.

    The first is that the step is a bit too large - as it doesn't take into account Fixed rows, partially-visible rows, or scrollbars. That is easy to fix using the .RowIsVisible method in the FlexGridScroll sub like this:
    VB Code:
    1. Lstep = Int(Lstep)
    2.     Do While Not (.RowIsVisible(.TopRow + Lstep))
    3.       Lstep = Lstep - 1
    4.     Loop
    (admittely I personally prefer smaller steps, say Lstep = 3)


    The second issue is that the grid doesn't scroll the grid that the mouse is over (which is how it normally works), only the active one. To 'correct' this I guess that the MouseWheel sub would need to check the mouse co-ordinates, and see if a grid is underneath.

  16. #16
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    si - having not really reviewed the code yet - could't the hook change from grid to grid based on the grid's MOUSEMOVE event? Or do you think that is too expensive?

    *** 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

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    yeah, i was aware of both of those. i was just showing that that code could be used with multiple things (and was feeling a bit too lazy to add the checking which one it's over stuff )

  18. #18
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Fair enough, good work tho - I'll be using a modified version of it
    Quote Originally Posted by szlamany
    si - having not really reviewed the code yet - could't the hook change from grid to grid based on the grid's MOUSEMOVE event? Or do you think that is too expensive?
    That would be possible, but you'd need to use the mousemove events of all controls (and the form) to ensure that the appropriate control is used. Without having tested yet, I personally think an API check of the mouse position (when a scroll event takes place) would be more apt.

  19. #19
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Quote Originally Posted by szlamany
    si - having not really reviewed the code yet - could't the hook change from grid to grid based on the grid's MOUSEMOVE event? Or do you think that is too expensive?
    Oh - I see the difference you mean...

    Wheel should only scroll a grid if it's over a grid.

    If the mouse moves off the grid the wheel should do nothing...

    Or I could also see the argument for saying that the last "grid" hovered over can retain wheel scroll power - regardless of if the mouse leaves the grid...

    *** 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

  20. #20
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Quote Originally Posted by si_the_geek
    Fair enough, good work tho - I'll be using a modified version of it
    That would be possible, but you'd need to use the mousemove events of all controls (and the form) to ensure that the appropriate control is used. Without having tested yet, I personally think an API check of the mouse position (when a scroll event takes place) would be more apt.
    That's right...

    I can see that the mouse wheel works right now if a combo box on my form has focus - so I'd be stealing the "mouse moves" from that combo box if the mouse is over the grid...

    I guess I'll have to start testing this and see where it gets me.

    *** 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

  21. #21
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Actually I've just done a quick test with a combo and list, it seems that they also have the same behaviour - it is the active control that scrolls, no matter where the mouse is.

    It's strange considering that Outlook etc don't work that way, but it means that the code above (with adjustments for the scroll amount) is spot on.

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    wow, getting it right through laziness, that's a first for me

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    ok, i've added in your adjustment from post #15, si, and I've added an IsOver function so it scrolls the grid it's over rather than the one with focus.

    Edit: Better version now available in the CodeBank
    Last edited by bushmobile; Feb 23rd, 2006 at 10:21 PM.

  24. #24

    Thread Starter
    Member orozcore's Avatar
    Join Date
    Aug 2005
    Posts
    36

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    I said that i had resolved my problem, buy maybe it wasn't true because when i use MouseWheel sub worked for all of my FlesGrids only one didn't work so I check again and download WheelHook3.zip from bushmobile where i can scroll the flexgrid when the mouse pointer is over so this resolved my problem.

    So now i can scroll all the flexgrids of my programm and there's no problem

    THX guys who responded to this post

    I'm an Angel Walking in Darkness

  25. #25
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Quote Originally Posted by bushmobile
    ok, i've added in your adjustment from post #15, si, and I've added an IsOver function so it scrolls the grid it's over rather than the one with focus.
    Bushmobile - I tried the version the the codebank - wheelhook3.zip.

    I added to your test project a combobox. As long as the combobox does not have focus, the wheel scrolls whatever flexgrid you are over.

    If the combobox gets focus, then the wheel on scrolls the combobox - regardless of what you hover over.

    Do you think this can easily be overcome? Or am I stuck using the "click" to focus on flexgrid version?

    *** 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

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    I have managed to sort this

    See the CodeBank thread

  27. #27
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    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

  28. #28
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    I've not done much API work or subclassing...

    So I'm curious what this does:
    VB Code:
    1. WindowProc = CallWindowProc(LocalPrevWndProc.Item("#" & Lwnd), Lwnd, Lmsg, Wparam, Lparam)
    I'm already doing this in my app:

    VB Code:
    1. Public Function WndProc(ByVal hwnd As Long, _
    2.         ByVal wMsg As Long, ByVal wParam As Long, _
    3.         ByVal lParam As Long) As Long
    4.        
    5.   'Let the window process messages as well
    6.   WndProc = CallWindowProc(m_lPrevProc, hwnd, wMsg, wParam, lParam)
    7.  
    8.   'See what message has been sent to the window
    9.   If wMsg = WM_ACTIVATEAPP Then
    10.     'It's the activateapp message so call the sub on the form
    11.     Call m_frmHooked.AppFocus(CBool(wParam))
    12.   End If
    13.  
    14.   If wMsg = WM_MOUSEWHEEL Then
    15.     Call MsgBox("test")
    16.   End If
    17. End Function
    So I need to add your MOUSEWHEEL message check to this existing routine - and it's already working to call the MSGBOX when I use the wheel...

    *** 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

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    i've also not done much subclassing, so i'm probably on the same learning curve

    VB Code:
    1. WindowProc = CallWindowProc(LocalPrevWndProc.Item("#" & Lwnd), Lwnd, Lmsg, Wparam, Lparam)

    does the same as :
    VB Code:
    1. WndProc = CallWindowProc(m_lPrevProc, hwnd, wMsg, wParam, lParam)

    just things are named differently and i've used a collection to store the lPrevProc values.

    before we integrate your code into mine (or visa versa), why are you subclassing the WM_ACTIVATEAPP message, and not just using the Form_Activate event?

  30. #30
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Quote Originally Posted by bushmobile
    before we integrate your code into mine (or visa versa), why are you subclassing the WM_ACTIVATEAPP message, and not just using the Form_Activate event?
    Form_Activate does not fire when your app is left and/or returned to.

    WM_ACTIVATEAPP message does fire.

    We do it to make sure the "control" we desire the focus to be on still has the focus.

    I think the snippet I posted:

    Code:
    'Let the window process messages as well
      WndProc = CallWindowProc(m_lPrevProc, hwnd, wMsg, wParam, lParam)
    indicates that this CallWindowProc passes the message back along to the windows processes.

    Maybe not calling this function can suppress the drop-down type controls from grabbing the mouse wheel without have to hook and unhook it in all those places.

    *** 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

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    ok, i've got rid of the need for those fiddly _DropDown, _LostFocus things by using CB_DROPDOWNSTATE, to check if it's dropdown. I've updated the zip in the codebank.

    you should be able to just add a case in like the below so you can implement your WM_ACTIVATEAPP code.

    VB Code:
    1. Case WM_ACTIVATEAPP
    2.       Set fFrm = GetForm(Lwnd)
    3.       If Not fFrm Is Nothing Then Call fFrm.AppFocus(CBool(wParam))

    regarding the CallWindowProc stuff in the WheelHook4.zip, the

    VB Code:
    1. WindowProc = CallWindowProc(LocalPrevWndProc.Item("#" & Lwnd), Lwnd, Lmsg, Wparam, Lparam)

    line (or whatever equivalent you wish to use) needs to be after the monitoring of the messages, because sometimes we don't want to process the message, just discard it (in the case of the combobox being selected, but the mouse not on it.)

    There are of course alternative ways to do what I've done. I'm using the vbAccelerator SSubTmr to manage subclassing in my current project.
    Last edited by bushmobile; Feb 19th, 2006 at 04:05 PM.

  32. #32
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    I've actually got a bit of testing and modification to go through here...

    That WM_ACTIVATEAPP is being listened to by the MDI-parent form of my app.

    I really want this WM_MOUSEWHEEL to be caught by whatever childform has focus.

    So I'm off to experimenting with having two WINDOWPROC functions in my app - one for the parent-window and another for this child window/mouse wheel stuff.

    But thanks again for this - it's really going to make many of my more sophisticated users happy.

    *** 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

  33. #33
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    It is working for me now. I'm still hooking the parent form so I can listen for WM_ACTIVATEAPP.

    And I am changing the mousewheel hook based on what child form has focus. If I alt-tab back and forth from child to child the mousewheel action is perfect.

    I haven't yet decided how to make it pick the grid to scroll. I do a lot of "hiding" grids by putting them behind other grids - got radio-buttons that make grids full-size or restore-to-original. On forms with several grids I'm starting to think that whenever the user mouses-over a grid that becomes the "wheel grid" - even if they do not stay on the grid (like move slightly off the grid so as to see the data, you know how the mouse and tool-tip can get in the way sometimes).

    I'm so excited I'm going to have to add a "new feature" pop-up window to my app so my customers know this one got enhanced.

    edit: btw - why are you not simply scrolling it one row up or down in your samples?

    *** 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

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    So I'm off to experimenting with having two WINDOWPROC functions in my app - one for the parent-window and another for this child window/mouse wheel stuff.
    Messing around with it is the best way to learn

    btw - why are you not simply scrolling it one row up or down in your samples?
    cos that's just how it was on the website i got the original code from.

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Just a modification by me..

    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. [B]    If .Rows < Lstep Then Exit Sub[/B]
    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.     .TopRow = NewValue
    25.   End With
    26. End Sub

    The bolded line, because it would erase all the lines except one if the msflex was less than LStep..

    Hope it works for you guys also

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Another thing, to prevent my IDE from getting messed up, and killing my ability to pause..

    In the form_load, put this instead of just straight up hooking:

    VB Code:
    1. If App.LogMode = 1 Then Call WheelHook(Me)

  37. #37
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Didn't know about that...

    We always use:

    Code:
    On Error Resume Next
    
        Debug.Print 1 / 0
        gDebugMode = (Err.Number <> 0)
    btw - your change about .Rows makes sense...

    but in the long run this is a perfect time to ignore all errors in the routine - we simply don't want to stop with any error that might pop-up when using the wheel.

    *** 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

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

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Hey |2eM!x,

    good spot , I've added your change about the rows to the codebank example.

    I've also added a little note mentioning that the code uses subclassing, and directed them to the thread on detecting if you're running in the IDE.
    Last edited by bushmobile; Feb 19th, 2006 at 07:13 PM.

  39. #39
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,859

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    We already had tons of events already tracking grid selection and even grid hover (we set the tooltip text to the full "cell value" - if it's not fully displayed - when you hover over a cell).

    So I ended up setting a form-level variable with the "grid" to be "mouse-wheel" associated.

    Clicking into a grid sets that grid as the mouse-wheel grid. Hovering into it does the same. But hovering out does not change the setting.

    And this was the simple function we used to move up/down

    VB Code:
    1. Public Function ScrollGrid(f As Form, lngMouseKeys As Long, lngXP As Long, lngYP As Long, lngRotation As Long) As Boolean
    2.  
    3. Dim booSkipScroll As Boolean
    4.  
    5. Debug.Print "   ScrollGrid"
    6. On Error GoTo Error_Handler
    7.  
    8. Begin:
    9.    
    10.     'Call StatusMessage(f, f.Caption & " " & CStr(lngXP) & " " & CStr(lngYP) & " " & CStr(lngRotation), False)
    11.     With f.flxInput(f.mlngGridScroll)
    12.         If .RowIsVisible(.FixedRows) And .RowIsVisible(.Rows - 1) Then
    13.             booSkipScroll = True
    14.         Else
    15.             booSkipScroll = False
    16.         End If
    17.         If Not booSkipScroll Then
    18.             If lngRotation < 0 Then ' scroll down
    19.                 .TopRow = .TopRow + 1
    20.             Else                    ' scroll up
    21.                 .TopRow = .TopRow - 1
    22.             End If
    23.         End If
    24.     End With
    25.  
    26. Rtn_Caller:
    27.     Exit Function
    28.  
    29. Error_Handler:
    30. '    Call Fatal_Error(Err.Number, Err.Source, Err.Description, "ScrollGrid")
    31.     Resume Rtn_Caller
    32.  
    33. End Function

    Also @ !2M - thanks for the heads up - made a quick adjustment to not scroll a grid if all the rows are already displayed

    *** 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

  40. #40
    Member
    Join Date
    May 2009
    Posts
    56

    Re: [RESOLVED] Scroll down a MSFlexGrid with Mouse Wheel

    Can I use it with DataGrid control ?

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
  •  



Featured


Click Here to Expand Forum to Full Width