Mercury048
March 15th, 2008, 11:35 AM
Hi, all.
I'm writing a small program which will scroll the currently active window in response to certain keypresses. (The arrow keys do not do the job I want as they move the selection/text cursor instead of simply scrolling.)
I already figured out (http://www.codeguru.com/forum/showthread.php?t=446352) that I can get a window to scroll by sending/posting WM_HSCROLL or WM_VSCROLL messages.
However, I found that there are two main ways that scrollbars are implemented:
1. As part of the window style. I can determine this by testing the window's dwStyle against WS_VSCROLL or WS_HSCROLL. In this case I send the message directly to the window I want to scroll and pass 0 as the last parameter (which is supposed to be the HWND of the scrollbar).//ScrollMessage is WM_VSCROLL or WM_HSCROLL
//ScrollDirection is one of is one of SB_LINEUP, SB_LINEDOWN, SB_LINELEFT, SB_LINERIGHT
PostMessage(WindowToScroll, ScrollMessage, ScrollDirection, 0);2. As a separate window. This is what's giving me a headache. The scrollbar has its own window with its own window handle. In this case I must send the message to the scrollbar's parent window and pass the scrollbar's window handle in the last parameter of the message.//ScrollMessage is WM_VSCROLL or WM_HSCROLL
//ScrollDirection is one of is one of SB_LINEUP, SB_LINEDOWN, SB_LINELEFT, SB_LINERIGHT
//OriginatingScrollBar is the HWND of the scrollbar
PostMessage(GetParent(OriginatingScrollBar), ScrollMessage, ScrollDirection, (LPARAM)OriginatingScrollBar);
The issue here is I have to find the scrollbar first. But the scrollbar is not logically related to the window I'm trying to scroll in any predicatble way; sometimes it's a child window, sometimes a sibling window, sometimes a second cousin thrice removed... you get the picture.
So I've resorted to picking up the borders of the window I want to scroll, and looking for the scrollbar by using WindowFromPoint() (http://msdn2.microsoft.com/en-us/library/ms633558.aspx) at a few points near the border.
This is a very inelegant solution, IMO. It also fails if the scrolllbar is so far away from the border that I can't find it. Is there any better way to find the scrollbar?
I'm writing a small program which will scroll the currently active window in response to certain keypresses. (The arrow keys do not do the job I want as they move the selection/text cursor instead of simply scrolling.)
I already figured out (http://www.codeguru.com/forum/showthread.php?t=446352) that I can get a window to scroll by sending/posting WM_HSCROLL or WM_VSCROLL messages.
However, I found that there are two main ways that scrollbars are implemented:
1. As part of the window style. I can determine this by testing the window's dwStyle against WS_VSCROLL or WS_HSCROLL. In this case I send the message directly to the window I want to scroll and pass 0 as the last parameter (which is supposed to be the HWND of the scrollbar).//ScrollMessage is WM_VSCROLL or WM_HSCROLL
//ScrollDirection is one of is one of SB_LINEUP, SB_LINEDOWN, SB_LINELEFT, SB_LINERIGHT
PostMessage(WindowToScroll, ScrollMessage, ScrollDirection, 0);2. As a separate window. This is what's giving me a headache. The scrollbar has its own window with its own window handle. In this case I must send the message to the scrollbar's parent window and pass the scrollbar's window handle in the last parameter of the message.//ScrollMessage is WM_VSCROLL or WM_HSCROLL
//ScrollDirection is one of is one of SB_LINEUP, SB_LINEDOWN, SB_LINELEFT, SB_LINERIGHT
//OriginatingScrollBar is the HWND of the scrollbar
PostMessage(GetParent(OriginatingScrollBar), ScrollMessage, ScrollDirection, (LPARAM)OriginatingScrollBar);
The issue here is I have to find the scrollbar first. But the scrollbar is not logically related to the window I'm trying to scroll in any predicatble way; sometimes it's a child window, sometimes a sibling window, sometimes a second cousin thrice removed... you get the picture.
So I've resorted to picking up the borders of the window I want to scroll, and looking for the scrollbar by using WindowFromPoint() (http://msdn2.microsoft.com/en-us/library/ms633558.aspx) at a few points near the border.
This is a very inelegant solution, IMO. It also fails if the scrolllbar is so far away from the border that I can't find it. Is there any better way to find the scrollbar?