Re: Detect mouse pointer over scrollbar

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thorsten, thanks a bundle for responding.

- I don't have a vb compiler per se. I am not a professional. I only use the
buit-in VBA compiler that comes with Excel. So I don't have Spy++.
- However, as I mentioned in my response to mr_unreliable, I can get the
window handles for the scrollbars using PeekMessage which passes a hWnd
parameter to its MSG structure.
- Since I get different handles when the mouse pointer is over the
scrollbars, I assume this implies that Excel uses scrollbar type b as you
suspected.
- PeekMessage also passes the mouse pointer position to the MSG structure.
- I discovered GetWindowRect which obtains the scrollbar dimensions (passes
to a RECT structure). I can thus easily approximate the relative location on
the scrollbar that was clicked.
- However, the results so far are less than elegant. I may be able to
improve this in time.
- I will investigate your suggestion with GetSystemMetrics. I am
unfiamiliar with this function. Hopefully it will assist in improving the
situation or at least simplifying the code.

Thanks again !!!

Kind regards,
Greg Wilson
(Vancouver, Canada)

"Thorsten Albers" wrote:

Greg Wilson <GregWilson@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb im Beitrag
<09C186CE-EA52-4C4E-9967-455FD3F226C0@xxxxxxxxxxxxx>...
I am able to detect the left mouse button click with PeekMessage and
thought
I could check which window the mouse pointer is over when this occurs and

programmatically induce the scrolling. My understanding is that the
scrollbars are child windows to Excel's main window "XLMAIN" and the
scrollbar arrows are either sibling or child windows to the scrollbar.
Thus
their handles could be obtained. I thought, say, GetWindowFromPoint or
ChildWindowFromPoint would do it. Apparently not. I thought I had read
this
somewhere.

There are two types of scrollbars available in Windows:
a) The window class 'SCROLLBAR', i.e. the 'Scroll Bar Control'
b) The windowless scroll bar called 'Standard Scroll Bar'

Neither of this scroll bar types uses separate child windows for the scroll
bar elements! a) has only one window in which it draws the scroll bar
elements, b) has no window at all and draws the scroll bar elemenets as
mentioned in the non-client area of the window to which it belongs.

b) is the scroll bar type most often used since it has the advantage that
no additional window handle is needed. But MS Office products (at least the
ones which I have checked, and which are MS Access 2.0 and MS Word 97) seem
to use the scroll bar Type a).
To telll what kind of scroll bar type your Excel version is using start MS
Spy++ (to be found on one of your VB CDs) and try to locate the scroll bar
window with Spy's mouse pointer (cross wires).

With scroll bar type b) it is difficult to retrieve the scroll bar element
under the mouse pointer. With scroll bar type a) this shouldn't be too
difficult: Just
- detect whether it is an horizontal or a vertical scroll bar,
- get the client rectangle of the scroll bar window,
- calculate the scroll bar elements by using system metrics
(GetSystemMetrics()) like SM_CXHSCROLL, SM_CYHSCROLL, SM_CXVSCROLL,
SM_CYVSCROLL.

--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------


.


Quantcast