Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a treeview control that I must subclass.

One of the things I must do is to handle WM_MOUSEWHEEL, WM_HSCROLL and WM_VSCROLL properly, by discarding these messages if the user scrolls beyond the scrollbar range.

I have tried using GetScrollInfo like this:
C++
case WM_MOUSEWHEEL:
    {
        // determine if treeview control has visible vertical scrollbar
        LONG_PTR WindowStyle = GetWindowLongPtr( hwnd, GWL_STYLE );

        if( WindowStyle & WS_VSCROLL )
        {
            SCROLLINFO si;

            ZeroMemory(&si, sizeof(si));
            si.cbSize = sizeof(SCROLLINFO);
            si.fMask = SIF_ALL;

            GetScrollInfo( hwnd, SB_VERT, &si );

            // here is the problem: I do not know how to formulate the condition
            if( /* currentPosition > Min or currentPosition < Max value */ )
                return 0L;   // handle it by doing nothing

            // otherwise do our stuff
        }
    }
    return 0L; // if scrollbar is not visible handle it by doing nothing

The principle is the same for all 3 messages, so I will limit this post to WM_MOUSEWHEEL only so this post can be brief.

My question is following:

How can I determine if the user scrolled beyond the maximal/minimal value ?

Thank you.

Best regards.
Posted

1 solution

I cannot imagine that a user can possibly scroll beyond its range. This control is designed to keep the scroll position inside some range. It is set by the call to the function SetScrollRange:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb787599%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/acw1066f.aspx[^].

Please see this article: http://msdn.microsoft.com/en-us/library/ms997557.aspx[^].

—SA
 
Share this answer
 
Comments
AlwaysLearningNewStuff 5-Apr-14 4:31am    
After taking into consideration your answer I think that I asked the wrong question.

You see, I use InvalidateRect() when user scrolls the treeview, and when I spin the mouse wheel my tree gets invalidated although scrollbox is at the top/bottom.

This means that probably the default scroll range is greater than tree's client rectangle so it seems that I just have to set the proper scroll range.

If you can verify my conclusion as correct, I would ask you to instruct me on how to set scroll range to that of tree's client area.

Thank you for answering ( 5ed ), I love the article!

Best regards.
Sergey Alexandrovich Kryukov 5-Apr-14 18:04pm    
You are welcome. You see, I don't know what do you want to achieve by invalidation and what region do you use for invalidation. This is related to the control you want to scroll, not the scroll bar. Scroll bar is already fully rendered, controllable and does not need invalidation...
—SA
AlwaysLearningNewStuff 8-Apr-14 8:22am    
I am working on a transparent treeview control. I have managed to make a "workable solution" but now I need to handle scrolling. I have managed to "handle" that as well, but now I face the following problem:

When scroll box is all the way up or down, and when I spin the mouse wheel, my tree gets invalidated which causes flicker.

I just want to check if scroll box has reached the top/bottom limit and if it is, not to invalidate the treeview.

I guess my question is badly phrased.

Best regards.
Sergey Alexandrovich Kryukov 8-Apr-14 11:35am    
Well, also you need to use double buffering, to avoid flicker.
You can always read the position of a scroll bar.
—SA
AlwaysLearningNewStuff 8-Apr-14 12:00pm    
I did use double buffering. The problem seems more complex.

All I have to do is detect when user tries to scroll beyond upper/lower limit and then discard the message.

I would post my subclass procedure in a new post and seek for help but I doubt anyone would try to help me. Things got much harder for me since the C++ section of Quick Answers has been removed...

Thank you for trying to help, but I doubt you can do more without seeing the actual code.

Best regards.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900