> http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b315519
> But it only shows the caption where ever my mouse cursor is pointing.
Well, more you'll find using Google ;-)
In the MS sample seek:
' Get IAccessible interface from object under pointer.
AccessibleObjectFromPoint p.x, p.y, objAccessible, v
Now you can get some other informations:
Dim px&, py&, cx&, cy&
Dim sValue$, vState&, sRole&
On Error Resume Next
Call objAccessible.accLocation(px, py, cx, cy, v)
gives position (px&, py&) and size (cy&, cy),
sRole = CLng(objAccessible.accRole(v)) '-> Role
vState = CLng(objAccessible.accState(v)) '-> State
sValue = Trim$(objAccessible.accValue(v)) '-> Value
One possible way for your task would be:
- Get the window rect of the toolbar,
- step from the left to the right in vertical middle (step e.g. 5 pixel),
- check the name of the item at the point,
- when the item (button) is the right,
(- get its location and size for the middle point)
- make a mouse click at this point.
There are other ways, but these require a deeper knowledge about using the
IAccessible Interface from VB, which I don't have, becouse I'm working with
C++ for this part.
Regarding the menu, look at the following APIs:
Declare Function GetMenu& Lib "user32" (ByVal hwnd&)
Declare Function GetSubMenu& Lib "user32" (ByVal hMenu&, ByVal nPos&)
Declare Function GetMenuItemCount& Lib "user32" (ByVal hMenu&)
Declare Function GetMenuItemID& Lib "user32" (ByVal hMenu&, ByVal nPos&)
Declare Function GetMenuItemRect& Lib "user32" (ByVal hwnd&, ByVal hMenu&,
ByVal uItem&, lprcItem As RECT)
Declare Function GetMenuState& Lib "user32" (ByVal hMenu&, ByVal wID&, ByVal
wFlags&)
Declare Function GetMenuString& Lib "user32" Alias "GetMenuStringA" (ByVal
hMenu&, ByVal wIDItem&, ByVal lpString$, ByVal nMaxCount&, ByVal wFlag&)
etc.
The way to go is (in short description):
- Get the menu handle using GetMenu/GetSubMenu,
- get the number of items using GetMenuItemCount,
- iterate over all items, get the text using GetMenuString,
- when it is ok, get the ItemID using GetMenuItemID,
- "click" the item e.g. using
Call SendNotifyMessage(Hwnd, WM_COMMAND, ItemID, 0)
But keep in mind: this is only possible for *real* menus, which are rarely
used (e.g. in Notepad). Most of the current "menus" are toolbars or
msocommandbars or other controls, and then you should look at the
Accessibility :-)
Juergen.
Juergen Thuemmler - 23 Jul 2008 11:35 GMT
Just as a supplement:
All of these possibilities for operating foreign apps or components of
windows in any way are implemented in WinRobots (www.winrobots.de), which is
available in version 7.5. as freeware (without accessibility, but in a short
time as version 8.0 including accessibility and much more new features). But
at the moment, the Website and the documentation are in german only :(.
Juergen.