views:

270

answers:

2

I have a window that has scroll bar styles so it has its own scrollbars. I want something to happen when the mouse hovers over the scroll bars, but handling the window's mouse move doesn't do the trick. How can I handle the scrollbars' mousemove event?

Thanks

+1  A: 

In the Win32 API, scrollbars have no 'mousemove event'. The only message you get from a vertical scrollbar is WM_VSCROLL.

If you want your scrollbars to have special behavior, you have to subclass them and override the handling of Mouse Messages. As it says in MSDN (Scroll Bar Controls in Win32):

If, however, you wish to alter the standard look or function of the scroll bar, you can either subclass the scroll bars on your window or create a stand-alone control.

You can find examples of code which does this by by searching for 'subclass scrollbar'.

Edit

What I'm trying to do is use the edge of the scrollbar to make my sub window resizable, is this possible?

The scrollbar is not the way to do it. Instead, define a window, a few pixels wide, just to the right of the scrollbar (and as tall). Set the cursor for that window to be a "resize" cursor (so the user will know to click and drag):

resize cursors

When that window gets a WM_LBUTTONDOWN message, it should start tracking the mouse, resizing and redrawing your control whenever the mouse moves. When the window gets WM_LBUTTONUP, it should stop tracking and leave your control at its new size.

Here's some code that will get you started on the mouse-tracking functions. It's for drawing lines, but the process is similar.

egrunin
What i'm trying to do is use the edge of the scrollbar to make my sub window resizable, is this possible?
Milo
A: 

Check if intercepting WM_NCMOUSEMOVE helps.

The WM_NCMOUSEMOVE message is posted to a window when the cursor is moved within the nonclient area of the window. This message is posted to the window that contains the cursor. If a window has captured the mouse, this message is not posted.

SDX2000