views:

176

answers:

1

In my (PowerBuilder) application, I'd like to be able to determine the graphicobject object which corresponds to a given window handle.

Simply iterating over the Control[] array and comparing the value returned by the Handle() function for each of the child controls doesn't work, since not all objects in my application are children of the main window (consider of login dialogs).

Any PowerScript or C/C++ solution would be acceptable.

Is there maybe some window message I could send to window handles, and this message is only understood by PowerBuilder windows, which would the respond with their internal object name, or the like?

+1  A: 

Is it a requirement to determine the object from the handle, or do you just want to identify an object, for example to know where the code you need to modify is? I made a tool that does the latter, but it uses object focus, rather than window handles.


(added 2010-06-21) For windows that aren't children of the main window you could explicitly check each of these window class names with isValid(). Then for each valid window, dig through looking for the handle. This should work as long as you only open one instance of the window class at a time. If you open multiple instances, I think you'll need to add a registration mechanism to the open of those windows so the application has a way to access them.

Hugh Brackett
Unfortunately, the former is the case for me. I need to get the graphicobject (if any) of my PowerBuilder application which corresponds to a given window handle.
Frerich Raabe
Are you inheriting all of your windows from ancestor classes?
Hugh Brackett
@Hugh: No, I'm not; I did consider that alternative (and then maintaining a HWND->graphicobject mapping in the 'open' event handler) but unfortunately I cannot use it in my case.
Frerich Raabe
Is this functionality required in normal use, or is it for testing? Also, what is the constraint against the mapping that Terry suggested? Is maintaining the mapping a problem or is the need to modify all windows unacceptable?
Hugh Brackett
@Hugh: Oops, sorry for not replying earlier. I don't need this functionality in normal use, I'd like to use it for GUI testing. The tool we use allows to exhibit additional functionality (read: properties or functions) for a given HWND by writing a little plugin which queries for the additional information via toolkit-specific API. In my case, I'm using PBNI to implement such a plugin - I solved most things already, but I lack a good way to identify the PowerBuilder control for a given HWND handle.
Frerich Raabe