Moderators SmOke_N Posted September 15, 2006 Moderators Share Posted September 15, 2006 (edited) On a request from a user, and others I've seen lately, if you want to get the ClassNameNN or the Control ID of all the controls from a window... This should return them all in a 2 dimensional Array. Return: [N][0] = ClassNameNN [N][1] = Control ID of the same control Example: Global $Array = _WinGetCtrlInfo(WinGetTitle('')) Global $sOne = '[0][0] = ' & $Array[0][0] & @CR, $sTwo For $iCC = 1 To $Array[0][0] $sOne &= '[' & $iCC & '][0] = ' & $Array[$iCC][0] & @CR $sTwo &= '[' & $iCC & '][1] = ' & $Array[$iCC][1] & @CR Next MsgBox(64, 'WinInfo', StringTrimRight($sOne, 1) & @CR & StringTrimRight($sTwo, 1)) Func _WinGetCtrlInfo($hWin) If IsString($hWin) Then $hWin = WinGetHandle($hWin) Local $sClassList = WinGetClassList($hWin), $iAdd = 1, $aDLL, $sHold Local $aSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2] For $iCount = $aSplitClass[0] To 1 Step - 1 Local $nCount = 0 While 1 $nCount += 1 If ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount) = '' Then ExitLoop If Not StringInStr(Chr(1) & $sHold, Chr(1) & $aSplitClass[$iCount] & $nCount & Chr(1)) Then $sHold &= $aSplitClass[$iCount] & $nCount & Chr(1) $iAdd += 1 ReDim $aReturn[$iAdd][2] $aReturn[$iAdd - 1][0] = $aSplitClass[$iCount] & $nCount $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _ ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount)) If @error = 0 Then $aReturn[$iAdd - 1][1] = $aDLL[0] Else $aReturn[$iAdd - 1][1] = '' EndIf EndIf WEnd Next $aReturn[0][0] = $iAdd - 1 Return $aReturn EndFunc Edited January 7, 2015 by SmOke_N removed script garbble caused by code box issues, pointed out by Exit mLipok 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 16, 2006 Author Moderators Share Posted September 16, 2006 ok...ide use this for...You know... You responded in my other thread (EnCodeIt) asking the same silly question.. You'd use it for whatever you finally figure out you need it for. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MHz Posted September 16, 2006 Share Posted September 16, 2006 (edited) ok...ide use this for...Simple, if you do not know or have a need, then you do not need it or have enough knowledge to use it. If you need help then state what help you need, otherwise read the helpfile with healthy interest and then use the support forum if you have problems with basic AutoIt use. But please do not post dribble as it can be mistaken as an insult. Edit:Nice code as always SmOke Edited September 16, 2006 by MHz Link to comment Share on other sites More sharing options...
ivan Posted November 28, 2006 Share Posted November 28, 2006 ok...ide use this for...@Dethredic:You might be inclined to look at an app that uses a more precise class list than that reported by wingetclasslist. Take a look at grabber in my sig.@SmOke_N:Do you mind if I used this neat func in grabber? I've been meaning to update it as I had an ugly bug, but could never find the time.I wanted to add a couple of buttons to enable grabbing controls, which was no prob as I already had the coordinates for those.Your solution enables me to check for control text, but there's a few controls which I still need to check further for a general solution (mainly lists (boxes, view, combos, and the likes)).IVAN Think out of the boxGrabber: Yet another WinInfo tool_CSVLib (still alpha)Dynamic html in au3 Link to comment Share on other sites More sharing options...
eliboy Posted February 22, 2007 Share Posted February 22, 2007 (edited) I really like this function, but when I used it the first control wasn't showing up in the array. I found that it was being overwritten at the end of the function when $aReturn[0][0] is being set to the number of controls. To fix this $iAdd should be initialized to 1, so you get the number of controls plus 1 (for the first element of the array which is the count). Therefore, if you have 17 controls then your array is 18 long, the first element (0) is the count, and each control is an element that follows. I have posted the updated function below. Func _WinGetCtrlInfo($hWin) If IsString($hWin) Then $hWin = WinGetHandle($hWin) $iAdd = 1 Local $sClassList = WinGetClassList($hWin), $iAdd, $aDLL, $sHold Local $aSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2] For $iCount = $aSplitClass[0] To 1 Step - 1 Local $nCount = 0 While 1 $nCount += 1 If ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount) = '' Then ExitLoop If Not StringInStr(Chr(1) & $sHold, Chr(1) & $aSplitClass[$iCount] & $nCount & Chr(1)) Then $sHold &= $aSplitClass[$iCount] & $nCount & Chr(1) $iAdd += 1 ReDim $aReturn[$iAdd][2] $aReturn[$iAdd - 1][0] = $aSplitClass[$iCount] & $nCount $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _ ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount)) If @error = 0 Then $aReturn[$iAdd - 1][1] = $aDLL[0] Else $aReturn[$iAdd - 1][1] = '' EndIf EndIf WEnd Next $aReturn[0][0] = $iAdd - 1 Return $aReturn EndFunc Edited February 22, 2007 by eliboy Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 22, 2007 Author Moderators Share Posted February 22, 2007 I really like this function, but when I used it the first control wasn't showing up in the array. I found that it was being overwritten at the end of the function when $aReturn[0][0] is being set to the number of controls. To fix this $iAdd should be initialized to 1, so you get the number of controls plus 1 (for the first element of the array which is the count). Therefore, if you have 17 controls then your array is 18 long, the first element (0) is the count, and each control is an element that follows. I have posted the updated function below. Func _WinGetCtrlInfo($hWin) If IsString($hWin) Then $hWin = WinGetHandle($hWin) $iAdd = 1 Local $sClassList = WinGetClassList($hWin), $iAdd, $aDLL, $sHold Local $aSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2] For $iCount = $aSplitClass[0] To 1 Step - 1 Local $nCount = 0 While 1 $nCount += 1 If ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount) = '' Then ExitLoop If Not StringInStr(Chr(1) & $sHold, Chr(1) & $aSplitClass[$iCount] & $nCount & Chr(1)) Then $sHold &= $aSplitClass[$iCount] & $nCount & Chr(1) $iAdd += 1 ReDim $aReturn[$iAdd][2] $aReturn[$iAdd - 1][0] = $aSplitClass[$iCount] & $nCount $aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _ ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount)) If @error = 0 Then $aReturn[$iAdd - 1][1] = $aDLL[0] Else $aReturn[$iAdd - 1][1] = '' EndIf EndIf WEnd Next $aReturn[0][0] = $iAdd - 1 Return $aReturn EndFuncNice catch.... I'll update the first post... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Hasher Posted February 23, 2007 Share Posted February 23, 2007 Sweet code Smoke_N , you answered my question in round about way in this posthttp://www.autoitscript.com/forum/index.ph...c=41523&hl=Thanks ;-) Firefox's secret is the same as Jessica Simpson's: its effortless, glamorous style is the result of — shhh — extensions! Link to comment Share on other sites More sharing options...
Proph Posted October 31, 2008 Share Posted October 31, 2008 Thanks a lot Smoke_N! I was looking for something like this. Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted October 31, 2008 Share Posted October 31, 2008 Totally forgot about this one. 2 years man Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Valuater Posted October 31, 2008 Share Posted October 31, 2008 (edited) Thanks a lot Smoke_N! I was looking for something like this. This and a lot of other great hits from Smoke are in "Autoit Wrappers"... Think I will change the name to "SmOke_N's Wrappers"lol8) Edited October 31, 2008 by Valuater Link to comment Share on other sites More sharing options...
Proph Posted October 31, 2008 Share Posted October 31, 2008 This and a lot of other great hits from Smoke are in "Autoit Wrappers"... Think I will change the name to "SmOke_N's Wrappers"lol8)Yeah Smoke_N and you both have helped me with a few things. I haven't ever tried the Autoit Wrappers. i'm gonna check it out too. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now