corrupt
Joined: 29 Dec 2004 Posts: 2421
|
Posted: Sun May 29, 2005 12:36 am Post subject: Get Control Handle |
|
|
Function to retrieve a control's handle. Tweaks welcome...
| Code: | 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:
| Code: | 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
}
|
|
|