Jump to content



Photo

_WinGetCtrlInfo()


  • Please log in to reply
11 replies to this topic

#1 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 15 September 2006 - 11:16 AM

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:
AutoIt         
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))ƒo݊÷ Ù@ÅjëhŠ×6Func _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 by SmOke_N, 22 February 2007 - 06:01 PM.

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.






#2 Dethredic

Dethredic

    http://gunnewiek.com/

  • Active Members
  • PipPipPipPipPipPip
  • 2,029 posts

Posted 15 September 2006 - 09:52 PM

ok...

ide use this for...
Posted Image"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

#3 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 16 September 2006 - 12:18 PM

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.


#4 MHz

MHz

    Just simple

  • MVPs
  • 5,400 posts

Posted 16 September 2006 - 12:54 PM

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 :P

Edited by MHz, 16 September 2006 - 12:56 PM.


#5 ivan

ivan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 398 posts

Posted 28 November 2006 - 01:34 AM

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

#6 eliboy

eliboy

    Seeker

  • New Members
  • 4 posts

Posted 22 February 2007 - 05:42 PM

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.

AutoIt         
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 by eliboy, 22 February 2007 - 05:43 PM.


#7 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 22 February 2007 - 06:01 PM

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.

AutoIt         
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

Nice 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.


#8 Hasher

Hasher

    Prodigy

  • Active Members
  • PipPipPip
  • 154 posts

Posted 23 February 2007 - 07:42 AM

Sweet code Smoke_N , you answered my question in round about way in this post
http://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!

#9 Proph

Proph

    Prodigy

  • Active Members
  • PipPipPip
  • 182 posts

Posted 31 October 2008 - 08:56 PM

Thanks a lot Smoke_N! I was looking for something like this. :mellow:

#10 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 31 October 2008 - 10:55 PM

Totally forgot about this one. 2 years man :mellow:
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#11 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,078 posts

Posted 31 October 2008 - 11:16 PM

Thanks a lot Smoke_N! I was looking for something like this. :mellow:


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"

lol

8)

Edited by Valuater, 31 October 2008 - 11:17 PM.

Posted Image

Clic The Pic!!!


#12 Proph

Proph

    Prodigy

  • Active Members
  • PipPipPip
  • 182 posts

Posted 31 October 2008 - 11:36 PM

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"

lol

8)

Yeah Smoke_N and you both have helped me with a few things. :mellow:

I haven't ever tried the Autoit Wrappers. i'm gonna check it out too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users