[Closed] Get the hWND of an utility panel
As in the title, I would like to press a specific button in the Utility Panel (of a 3rd party plugin). The button is captioned “Export” so my code is :
UIAccessor.PressButtonByName handle "Export"
The problem is I can’t find a way to get the window handle of this panel.
to press a button from currently open panel you don’t need hwnd of this panel, the parent’s one is enough. so you just need the “Command Panel”. it’s easy:
windows.getchildhwnd #max "Command Panel"
I once wrote a tool that is ideal for this sort of task:
http://www.monotoneminimal.com/free-tools
Very nice tool, but It seems that it only gives the Handle at the time the window is opened. If I close the window and open it again, it will change… Or am I missing something ?
Yes, that is the nature of window handles. they are created at random. Your code can not use a constant integral value, it must search for the correct handle using children, children of children, etc.
What Windowshopper helps you with is quickly understanding the hierarchy of controls to your destination window.
I see, but then, how do I start ? How do I even find the parent if the handles always change ? By comparing the captions ?
You will be using the various methods in the UIAccessor interface and Windows struct.
first you will probably want to get the HWND of 3dsmax or the desktop:
windows.GetMaxHwnd()
windows.GetDesktopHwnd()
you can get the children of a window using windows.GetChildrenHwnd
For comparing, it depends of the window
If it has a unique type amongst it’s siblings, you can use the type string.
If it’s a constant and unique caption, you can use the caption string.
If you can locate one of its siblings, you might be able to get your desired window by using UIAccessor.GetNextWindow
etc.
If I remember correctly, the command panel is parented to the 3dsmax hWnd if it’s docked and to the desktop hWnd if it’s not.
Oh I see, it’s totally heavy and not elegant at all, but it will eventually work. Thanks very much !