Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / July 2008



Tip: Looking for answers? Try searching our database.

ToolbarWindow32 Button information

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ferio - 18 Jul 2008 20:08 GMT
I need help in getting the button information on a ToolbarWindow32. Under
WinSpy++ all I can see is that the button I'm trying to send a click command
is in the toolbarwindow32. There is no information on the button.

Can someone guide me to the right direction to first get the information of
the button and to send a command to press a button?

Thank you !
Karl E. Peterson - 21 Jul 2008 22:34 GMT
> I need help in getting the button information on a ToolbarWindow32. Under
> WinSpy++ all I can see is that the button I'm trying to send a click command
> is in the toolbarwindow32. There is no information on the button.

Please define "the button information"?
Signature

.NET: It's About Trust!
http://vfred.mvps.org

Ferio - 22 Jul 2008 02:16 GMT
>> I need help in getting the button information on a ToolbarWindow32. Under
>> WinSpy++ all I can see is that the button I'm trying to send a click command
>> is in the toolbarwindow32. There is no information on the button.
>
>Please define "the button information"?

What I mean by "the button information" is any information I can get from the
Toolbar. So that I can send command to click the button.  From WinSpy++ it's
not consider a window but It has 11 buttons on it. So it shows no information
on the buttons, no handle, no class. The only thing I know is the handle and
class of the toolbar.

Another option would be is to send a command to click on the menus. For
example like the File, Edit view etc. Is there an command that can control
the menu using API? the command I'm trying to use does not have a shortcut
setup(alt+Something) so i'm stuck.
Juergen Thuemmler - 22 Jul 2008 12:20 GMT
> What I mean by "the button information" is any information I can get from
> the
[quoted text clipped - 5 lines]
> and
> class of the toolbar.

Getting informations from common controls like Toolbar, Listview or Treeview
in foreign apps is not a trivial task. You can easy get a text from an edit
window, but not the caption of a toolbar button (an Item of the Toolbar).
Informations about Items of common controls are usually stored in a
structure (TBBUTTON, LVITEM, TVITEM ...) which must be passed to the foreign
app bo be filled with informations. The problem ist, that a structure
defined in your app has an address which is not valid in the foreign app.
To solve this problem, you must either create a valid and usable memory or
operate in the memory in the foreign app. Brad Martinez has demonstrated it
on a Listview sample (it's very similar to a toolbar) for two different ways
in
http://www.mvps.org/btmtz/listview/remotelistview.zip
Another way which I preferre is to hook into the foreign app and operate
inside to get infos or do something, but this requires a special standard
Dll with exported functions.
Last not least you can use the Active Accessibility to solve your problem
(some keywords: OleAcc.Dll, AccessibleObjectFromPoint(),
AccessibleObjectFromWindow()).

Juergen.
Ferio - 22 Jul 2008 22:50 GMT
This seem a bit complicated after looking through the examples, since I'm a
beginner at VB. How about accessing the menu and activate the command from
the menu? What do I need to get control of that part?

I did found find some information on Active Accessibility but I'm not sure
how this will help me click the button I want on my program. I found this
example

http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b315519

But it only shows the caption where ever my mouse cursor is pointing.

>> What I mean by "the button information" is any information I can get from
>> the
[quoted text clipped - 22 lines]
>
>Juergen.
Juergen Thuemmler - 23 Jul 2008 11:13 GMT
> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.