tags:

views:

42

answers:

2

I'm working on a little macro record/replay tool which can automate a few very old Visual Basic 6 GUIs we have. To do so, I'm identifying the controls by their name (the value of the name property of a control, that is).

One part of this tool needs to determine the name of a control given its HWND. For newer Visual Basic applications which were done using VB.NET, I can use the WM_GETCONTROLNAME window message. This works nicely.

However, this message is not understood by older windows. Is there any way to do this for controls of Visual Basic 6 applications? A solution which does not require being in the process of the GUI would be preferrable, but if I had a solution which only works inside the GUI process then that would be acceptable as well (since I can do the injection myself).

UPDATE: One thing I just tried, this moderate success: I used the AccessibleObjectFromWindow to check for implementations of the IAccessible interface of the object which shows the given HWND. In case I get an implementation (it seems that many [all?] Visual Basic controls implement this interface), I use the accName property to read out the "accessible name". Sometimes this does yield a useful string, but usually it doesn't.

+1  A: 

I believe the only way would be getting inside the process and obtaining a pointer to the Form object, yet I have no idea how to do it from outside.

Is it possible you add support for the WM_GETCONTROLNAME to those older applications?

Or maybe, you could identify the controls by some other, natively-available properties?

Other that that, as Raymond is saying, there isn't much you can do.

GSerg
Those are all godd suggestions, thanks! Right now it really seems that I need to hook into the process (I can do that) and then access the Form object directly. I'm not sure how to do that, but have done something similar a few months ago already, so it might work out.
Frerich Raabe
+1  A: 

Can you modify the vb6 apps? if so in each form load event you could iterate me.controls and use the SetProp(ctrl.hwnd, "MYNAME:" & ctrl.name, 0) api to add the name to the window's own property list, then in your other app you can EnumProps(ctrl_HWND) looking for the one that begins with MYNAME: and parse out the value.

Alex K.
Pretty creative idea! However - no, I can't modify the applications. I believe I don't even have the source code for them accessible. Somebody told me that there's a tool which can be used to read out the Visual Basic names for a given GUI and apparently some GUI testing tools can do this, too - so it must be possible, somehow.
Frerich Raabe