This will return the class name and number of a control if provided the control's id or the text/var. I updated it to make it easier to use. Now there are only two arguments: ID/Text/Var and gui number (which defaults to 1.)
Call with:
Code:
ret := getClassNN(butOk) ;use the ID
ret1 := getClassNN("Radio1") ;use the Caption
ret2 := getClassNN(Check1) ;use the text/var
Here's the function:
Code:
getClassNN(c, g=1) ;c = text/var,Hwnd ;g = gui number (default=1)
{
Gui,%g%:+LastFound
guiID := WinExist() ;get the id for the gui
WinGet, List_controls, ControlList
StringReplace, List_controls, List_controls, `n, `,, All
;if id supplied do nothing special
IfNotInString, c, %List_controls% ;must be the text/var - get the ID
{ mm := A_TitleMatchMode
SetTitleMatchMode, 3 ;exact match only
ControlGet, o, hWnd,, %c% ;get the id
SetTitleMatchMode, %mm% ;restore previous setting
If(o) ;found match
{ c := o ;set sought-after id
}
}
Loop, Parse, List_controls, CSV
{ ControlGet, o, hWnd,, %A_LoopField% ;get the id of current classnn
If(o = c) ;if it is the one we want
{ Return A_Loopfield ;return the classnn
}
}
}
Example:
Code:
gui,add,Checkbox, vCheck1, Checkbox
gui,add,Radio, xp y+5,Radio1
gui,add,Radio, x+ yp,Radio2
gui,add,button,HwndbutOk xm+10 y+5 section,Ok ;add first button
gui,add,button,HwndbutCancel x+ yp,cancel ;add second button
gui,show
ret := getClassNN(butOk) ;use the ID
ret1 := getClassNN("Radio1") ;use the Caption
ret2 := getClassNN(Check1) ;use the text/var
MsgBox, Ok Button:`t%ret%`nRadio Button1:`t%ret1%`nCheckbox:`t%ret2%
Return
guiClose:
ExitApp
Return
getClassNN(c, g=1) ;c = text/var,Hwnd ;g = gui number (default=1)
{
Gui,%g%:+LastFound
guiID := WinExist() ;get the id for the gui
WinGet, List_controls, ControlList
StringReplace, List_controls, List_controls, `n, `,, All
;if id supplied do nothing special
IfNotInString, c, %List_controls% ;must be the text/var - get the ID
{ mm := A_TitleMatchMode
SetTitleMatchMode, 3 ;exact match only
ControlGet, o, hWnd,, %c% ;get the id
SetTitleMatchMode, %mm% ;restore previous setting
If(o) ;found match
{ c := o ;set sought-after id
}
}
Loop, Parse, List_controls, CSV
{ ControlGet, o, hWnd,, %A_LoopField% ;get the id of current classnn
If(o = c) ;if it is the one we want
{ Return A_Loopfield ;return the classnn
}
}
}