Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Though an ancient programmer, I'm still fairly inexperienced in MFC and Windows programming in general. I'm trying to add automatic scrolling during dragging. CScrollView windows have this feature, but I want to be able to add it to any old window with built-in scrollbars (using WS_VSCROLL style). The easy way appears to be to send a WM_VSCROLL message when the cursor is over an area near the top or bottom of the window. I naively assumed that something like
C++
SendMessage(WM_VSCROLL, SB_LINEDOWN);

might work, but it does not seemed to be passed on to the right window, presumably a child window that is the scroll bar. Then I thought that I could find a handle for the child window, and send the message to that. Tried various approaches, like
C++
GetDescendantWindow(SB_VERT)
GetWindow(GW_CHILD)

but nothing seems to give me access to the scroll bar. The only way I have found to make it work is to use
C++
SendMessageToDescendants(WM_VSCROLL, SB_LINEUP);

which seems inelegant, in that all child windows will have to process the message that is only aimed at one of them.

So what I would love to know is: can you get a handle to the built-in scroll bars? If so how; if not, why not? And can anyone suggest any better ways to add automatic scrolling to an arbitrary window type?
Posted
Updated 22-Jun-10 21:24pm
v2

Could you add an OnMouseOver event to the window you drag into? You would set a property to indicate that dragging into the window has started in the OnDragEnter and reset this property in the OnDragDrop and OnDragAbort.

In the mouse over event you could now check the property that indicates if a dragdrop operation is going on is and if the cursor is near the top or bottom of the window, the window could take action to scroll in the desired direction.

Well, hopfully this gives you some idea and can help you implement it.

Good luck!
 
Share this answer
 
Comments
old_hacker 26-Jul-10 16:19pm    
Thanks for answering. My question was really how to access the built-in scroll bars, not how to decide when to scroll. I had already implemented more or less what you suggest, and when the window needs to scroll, I send a WM_VSCROLL message to all the descendant windows. What I wanted to know was, is there a way to send the message only to the child window that wants to see it (the built-in scroll bar), not to the other (maybe hundreds) that don't want it.
E.F. Nijboer 30-Jul-10 5:49am    
Added it as an answer so it's more readable.
The GetScrollBarInfo api will get you information about a scrollbar, you can just pass it the handle of the window control that holds the scrollbar:

http://msdn.microsoft.com/en-us/library/bb787581%28VS.85%29.aspx[^]
It returns this struct:
http://msdn.microsoft.com/en-us/library/bb787535%28VS.85%29.aspx[^]
There are also the Get/SetScrollInfo, GetSetScrollPos and GetSetScrollRange functions:
GetScrollInfo: http://msdn.microsoft.com/en-us/library/bb787583%28VS.85%29.aspx[^]
GetScrollPos: http://msdn.microsoft.com/en-us/library/bb787585%28VS.85%29.aspx[^]
GetScrollRange: http://msdn.microsoft.com/en-us/library/bb787587%28VS.85%29.aspx[^]
SetScrollInfo: http://msdn.microsoft.com/en-us/library/bb787595%28VS.85%29.aspx[^]
SetScrollPos: http://msdn.microsoft.com/en-us/library/bb787597%28VS.85%29.aspx[^]
SetScrollRange: http://msdn.microsoft.com/en-us/library/bb787597%28VS.85%29.aspx[^]
and the ScrollWindow api should allow you to just scroll:
http://msdn.microsoft.com/en-us/library/bb787591%28VS.85%29.aspx[^]


Hopefully these links all help you to handle the scrolling the way you like it :)
 
Share this answer
 

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