Requested feature - Get HWND of Window/Control

The ability to determine the handle (hwnd) of a window or control is central to automation in AutoHotkey and AutoIt. It allows the script writer to “grab” windows by that hwnd (in addition to other methods using PID, title, or class), even if hidden provided certain other criteria are met, such as in this AutoHotkey statement which is self-explanatory:

DetectHiddenWindows, On

This also allows “grabbing” windows and controls when multiple instances of the same are present.

I may well be wrong, but in the statement

UIAutomation.GetWindow Control: BringWindowToFront:False WindowInstance=> WindowInstance

I believe the WindowInstance may refer to, or perhaps depend on, the process ID, or the title, or the class, rather than the hwnd.

The ability to save both the hwnd and PID to variables would really come in handy. Perhaps this would be useful, for example, in a new version of “UiAutomation.GetWindow”, which I believe can also be used to get a control as it is.


Hello @burque505,

Excuse me for the delayed response on this thread.

You can get the .handle property directly from instances.
For example:

Unfortunately you can’t use it for now in order to close its window instance.

Regarding the PID, we don’t have an action supporting that for the moment but we will definitely consider it for a future release.

Many thanks for the suggestion!

Best regards,

James Papadimitriou
Technical Evangelist

1 Like

@jpap, that’s very helpful, thank you. I’m happy to report that it works for Excel instances also.


EDIT: Regarding termination by PID, here is my workaround:

Best regards,

1 Like