Jump to content

Find control by size - possible or not?


 Share

Recommended Posts

Dear ALL,

Do you have a really working example of code who searches for controls by their SIZE ?

This line works well:

ControlGetHandle($hwndMain, "[CLASS:TWINDOW1; INSTANCE:28]", 0)

but it stops to work when I add dimensions!

ControlGetHandle($hwndMain, "[CLASS:TWINDOW1; INSTANCE:28; W:123]", 0)

Control width I use is correct, I see it in Au3Info and some other similar tools too.
I need to control a very old software with dummy classes and without standard text on controls, so dimensions would be very helpfull for me.

Are there some tricks to make work the search by control size?

Thank you very much in advance!

 

PS: Of course I can get the entire list of objects and check their dimensions with ControlGetPos, but I wonder if there is a standard internal solution which works?

Link to comment
Share on other sites

  • 2 weeks later...

Hello!

I've just discovered that sometimes ControlGetPos gives fully wrong result. Maybe it takes some info from previous calls of the same function?!

I've compared results of ControlGetPos and _WinAPI_GetClientRect.
Maybe there are some differences because of borders or shadows, but the difference can't be so big!

Below you will find my code and screenshot with strange results.
I use version 3,3,14,5 and the last beta 3,3,15,3 - the result is the same.

Sometimes it begins to work well after PC reboot!
But there is no Autoit in memory so I don't understand how it affect the situation.

Help please!

Maybe I could give you some more info for analysis?

So for today I think the best way to find a control is to get the entire list and search myself instead of using ControlGetHandle.
I didn't imagine that it is so hard to find a control... :(

Func GetControls($hWnd)

Local $Data, $DataPos, $tRECT
$Data = _WinAPI_EnumChildWindows($hWnd)
If IsArray($Data) Then
    ReDim $Data[$Data[0][0]+1][14]

    For $i=1 To $Data[0][0] ; useless cleaning - it doesn''t help
        $Data[$i][4]=0
        $Data[$i][5]=0
        $Data[$i][6]=0
        $Data[$i][7]=0
        $Data[$i][8]=0
        $Data[$i][9]=0
        $Data[$i][10]=0
        $Data[$i][11]=0
        $Data[$i][12]=0
        $Data[$i][13]=0
    Next


    For $i=1 To $Data[0][0]
        If IsHWnd($Data[$i][0])=1 Then
            $Data[$i][2] = ControlGetText($Data[$i][0], "", 0)
            $Data[$i][3] = WinGetTitle($Data[$i][0])

            $DataPos=ControlGetPos($Data[$i][0], "", 0)
            If IsArray($DataPos) Then
                $Data[$i][4]=$DataPos[0] ; X
                $Data[$i][5]=$DataPos[1] ; Y
                $Data[$i][6]=$DataPos[2] ; Length from ControlGetPos !!!
                $Data[$i][7]=$DataPos[3] ; Width from ControlGetPos !!!
            Else
                $Data[$i][4]="?" ; X
                $Data[$i][5]="?" ; Y
                $Data[$i][6]="?" ; L
                $Data[$i][7]="?" ; W
            EndIf

            $tRECT = _WinAPI_GetClientRect($Data[$i][0])
            $Data[$i][8]=DllStructGetData($tRECT, "Left")
            $Data[$i][9]=DllStructGetData($tRECT, "Right")
            $Data[$i][10]=DllStructGetData($tRECT, "Top")
            $Data[$i][11]=DllStructGetData($tRECT, "Bottom")
            $Data[$i][12]=$Data[$i][9]-$Data[$i][8] ; Length from _WinAPI_GetClientRect !!!
            $Data[$i][13]=$Data[$i][11]-$Data[$i][10] ; Width from _WinAPI_GetClientRect !!!
        EndIf

    Next

    _ArrayDisplay($Data, "Controls")
    Return $Data
Else
    Return 0
EndIf

EndFunc

 

Untitled.png

Edited by VladV
Link to comment
Share on other sites

2 minutes ago, VladV said:

I've just discovered that sometimes ControlGetPos gives fully wrong result.

From the help for ControlGetPos()

Quote

Return Value

Success: an array containing the size and the control's position relative to its client window:
    $aArray[0] = X position
    $aArray[1] = Y position
    $aArray[2] = Width
    $aArray[3] = Height
Failure: sets the @error flag to 1.

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

5 hours ago, JockoDundee said:

From the help for ControlGetPos()

 

Yes, I agree, so I take dimensions as 2nd and 3rd elements:

$Data[$i][6]=$DataPos[2] ; Length from ControlGetPos !!!
$Data[$i][7]=$DataPos[3] ; Width from ControlGetPos !!!

There was no errors because my HWND exists.
And sometimes this code works well after PC reboot!
Do you have some other ideas what I must check please?

By the way, I check if the result is array. Do you think it may happen that function returns array but sets the @error flag?
I'd like a lot to look in the source code of ControlGetPos and some other functions...

Edited by VladV
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...