ControlGetHWND(WindowHWND, CtrlClass, CtrlInstance) { ; Retrieves the handle of a control ; WindowHWND - Handle to the parent window (window that contains the control) ; CtrlClass - ClassName of the control ; CtrlInstance - Instance number of the control Loop, %CtrlInstance% { tempHWND := DllCall("FindWindowExA", "Uint", WindowHWND, "Uint", tempHWND, "str", CtrlClass, "str", NULL, "Uint") If tempHWND = 0 Break } Return tempHWND }
Example:
NULL= Run, Notepad,,, notepid WinWait, ahk_pid %notepid% WinWaitActive, ahk_pid %notepid% WinHandle := WinExist("Untitled - Notepad") CtrlHandle := ControlGetHWND(WinHandle, "Edit", "1") ; Test the handle retrieved if CtrlHandle { EM_REPLACESEL := 0xC2 teststr := "If you can see this message it means that the ControlGetHWND() function" teststr := teststr " was able to retrieve the handle of Notepad's Edit control." DllCall("SendMessageA", "Uint", CtrlHandle, "int", EM_REPLACESEL, "str", NULL, "str", teststr) } else MsgBox, "Error: Could not retrieve the control's handle" ControlGetHWND(WindowHWND, CtrlClass, CtrlInstance) { ; Retrieves the handle of a control ; WindowHWND - Handle to the parent window (window that contains the control) ; CtrlClass - ClassName of the control ; CtrlInstance - Instance number of the control Loop, %CtrlInstance% { tempHWND := DllCall("FindWindowExA", "Uint", WindowHWND, "Uint", tempHWND, "str", CtrlClass, "str", NULL, "Uint") If tempHWND = 0 Break } Return tempHWND }