Horizontal scroll with OnMouseWheel ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Horizontal scroll with OnMouseWheel ?

  1. #1
    Join Date
    Jul 2001
    Posts
    293

    Horizontal scroll with OnMouseWheel ?

    Hello,

    some special mouses have the ability to scroll also horizontal.
    What message is sent in this case?
    Can I use OnMouseWheel to handle this?
    (I have noch such a mouse)

    thx.

    Ralf

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: Horizontal scroll with OnMouseWheel ?

    An horizontal scroll can already be realized with an ordinary mouse. You simply use the wheel and press the shift key at the same time.

    You can test that behaviour with a modern internet browser, e.g. Chrome, and http://codeguru/forum/ . Resize the window in order to see the horizontal scrollbar. Then, press the shilft key and roll the wheel of your mouse. You can see an horizontal scroll.

    I don't have a mouse with a special wheel for an horizontal scrolling, but I am pretty sure it works by simulating a pressure on the shift key and a motion of the wheel. In your program you would watch the WM_MOUSEWHEEL message (or onMouseWheel if you program with MFC) and watch the state of the shift key with GetKeyState(VK_SHIFT).

  3. #3
    Join Date
    Jul 2001
    Posts
    293

    Re: Horizontal scroll with OnMouseWheel ?

    Hello,

    I know about the behaviour with the shift key.
    It works in my app.
    But a user with a special mouse for horizontal scrolling says, that it do not.

    He can do it with shift and vert. scroll. But not with his horizontal scroll buttons.

    thx.
    Ralf

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,059

    Re: Horizontal scroll with OnMouseWheel ?

    Handle WM_MOUSEHWHEEL message as well.
    Note that requires at least Windows Vista and Windows Server 2008 (_WIN32_WINNT >= 0x0600).
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Horizontal scroll with OnMouseWheel ?

    Quote Originally Posted by Ralf Schneider View Post
    Hello,

    I know about the behaviour with the shift key.
    It works in my app.
    But a user with a special mouse for horizontal scrolling says, that it do not.

    He can do it with shift and vert. scroll. But not with his horizontal scroll buttons.

    thx.
    Ralf
    In XP he needs a special mouse driver for that device which should generate the needed messages, i. e. WM_MOUSEWHEEL, WM_KEYDOWN (of shift key) and setting the keyboard state (shift was pressed).

  6. #6
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Horizontal scroll with OnMouseWheel ?

    Quote Originally Posted by ovidiucucu View Post
    Handle WM_MOUSEHWHEEL message as well.
    Note that requires at least Windows Vista and Windows Server 2008 (_WIN32_WINNT >= 0x0600).
    You can try to setting _WIN32_WINNT=0x0600 in your preprocessor settings. If the mouse driver sends the WM_MOUSEWHEEL message you probably can handle the message even if not officially supported by the OS version.

  7. #7
    Join Date
    Jul 2001
    Posts
    293

    Re: Horizontal scroll with OnMouseWheel ?

    Hello,

    my customer uses Windows 7.
    My app has an implementation for horizontal scrolling with shift+mouse wheel.

    Then I implemented the horizontal wheel with this:

    Code:
    BOOL CTrackView::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt) 
    {
    	return OnMouseWheel(nFlags | MK_SHIFT,zDelta,pt);
    }
    But the app crashes.
    Has someone an idea why?

    Ralf

  8. #8
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Horizontal scroll with OnMouseWheel ?

    Quote Originally Posted by Ralf Schneider View Post
    Hello,

    my customer uses Windows 7.
    My app has an implementation for horizontal scrolling with shift+mouse wheel.

    Then I implemented the horizontal wheel with this:

    Code:
    BOOL CTrackView::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt) 
    {
    	return OnMouseWheel(nFlags | MK_SHIFT,zDelta,pt);
    }
    But the app crashes.
    Has someone an idea why?

    Ralf
    Does it crash when you simply return 0 as well?

    To call a handler from a handler normally isn't so good an idea cause each handler function available might return 0 (== not handled) what causes the dispatcher to search for another handler in the chain of windows. When you call CTrackView::OnMouseWheel you actually break that kind of logic. So, you better send a WM_MOUSEWHEEL message and before set the 'Shift Key' to be pressed by calling SetKeyboardState. Probably you also have to send a WM_KEYDOWN message before. After that you can return with 1 (== handled) cause now the normal handling of the vertical mouse wheel handling should happen and if you were lucky it should recognize the SHIFT key is being pressed.

  9. #9
    Join Date
    Jul 2001
    Posts
    293

    Re: Horizontal scroll with OnMouseWheel ?

    yes, it will also crash if I return 0.

    But I will try your other suggestion as well.

    thx.
    Ralf

  10. #10
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Horizontal scroll with OnMouseWheel ?

    Quote Originally Posted by Ralf Schneider View Post
    But the app crashes. Has someone an idea why?
    Did you change (or set) the _WIN32_WINNT macro to 0x0600 ? If yes, did you make a full rebuild after that? And didn't you use dlls where the _WIN32_WINNT macro was set differently?

    The problem is that by setting the macro WINAPI header files and some structures would change in size. If you have mixed code or even use old precompiled headers the crash can be because of that.

  11. #11
    Join Date
    Jul 2001
    Posts
    293

    Re: Horizontal scroll with OnMouseWheel ?

    I have not used this macro.

  12. #12
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Horizontal scroll with OnMouseWheel ?

    Quote Originally Posted by Ralf Schneider View Post
    I have not used this macro.

    And what compiler are you using? Is the WM_MOUSEHWHEEL defined in your headers?

  13. #13
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Horizontal scroll with OnMouseWheel ?

    Quote Originally Posted by Ralf Schneider View Post
    yes, it will also crash if I return 0.

    But I will try your other suggestion as well.

    thx.
    Ralf
    That probably means that you need to set the _WIN32_WINNT macro to 0x0600 (or higher) cause Windows couldn't handle the message (you might find an entry in the eventvwr).

    Simply set it in the preprocessor definitions of your project by

    _WIN32_WINNT=0x0600

    separated by comma , from rthe other macros. Then rebuild all.

  14. #14
    Join Date
    Jul 2001
    Posts
    293

    Re: Horizontal scroll with OnMouseWheel ?

    Quote Originally Posted by itsmeandnobodyelse View Post
    That probably means that you need to set the _WIN32_WINNT macro to 0x0600 (or higher) cause Windows couldn't handle the message (you might find an entry in the eventvwr).

    Simply set it in the preprocessor definitions of your project by

    _WIN32_WINNT=0x0600

    separated by comma , from rthe other macros. Then rebuild all.
    the mouse driver sends the WM_MOUSEHWHEEL message.
    The according function will also be called.
    I thought, in this case I do not need to set the macro?

    Ralf

  15. #15
    Join Date
    Jul 2001
    Posts
    293

    Re: Horizontal scroll with OnMouseWheel ?

    Hello,

    again a question about setting
    _WIN32_WINNT macro to 0x0600

    What do that really mean?
    Do that mean that my app can only run on Windows vista and higher?

    Ralf

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center