Sign in to follow this  
Followers 0
bi0hazrd

Controlgetpos()

24 posts in this topic

Can anyone tell me why this isn't working? The first msgbox letting me know the control is visible appears, but the second message box and the mouse click calls fail with Subscript used with non-Array variable. $pos is first declared in this if statement, so I know it's not a problem with the variable not actually being an array.

If ControlCommand("", "", 1969446, "IsVisible", "") Then
    MsgBox(0, "Cross-section", "Visisble")
    $result = 1 And $result
    $pos = ControlGetPos("", "", 1969446)
;This line fails
    MsgBox(0, "Cross-section pos", "x: " & $pos[0] & "y: " & $pos[1] & "w: " & $pos[2] & "h: " & $pos[3])
;This line also fails
    MouseClick("left", $pos[2] - 6, $pos[3] - 6)
EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If ControlCommand("", "", 1969446, "IsVisible", "") Then
    MsgBox(0, "Cross-section", "Visisble")
    $result = $result & 1
    $pos = ControlGetPos("", "", 1969446)
    If IsArray($pos) Then
        MsgBox(0, "Cross-section pos", "x: " & $pos[0] & "y: " & $pos[1] & "w: " & $pos[2] & "h: " & $pos[3])
        MouseClick("left", $pos[2] - 6, $pos[3] - 6)
    EndIf
EndIf
If it's not an array, you may have to give a title... to the Control ID

Edit:

For some reason, I get the feeling your trying to do this with $result:

If ControlCommand("", "", 1969446, "IsVisible", "") Then
    MsgBox(0, "Cross-section", "Visisble")
    $result = $result + 1
    $pos = ControlGetPos("", "", 1969446)
    If IsArray($pos) Then
        MsgBox(0, "Cross-section pos", "x: " & $pos[0] & "y: " & $pos[1] & "w: " & $pos[2] & "h: " & $pos[3])
        MouseClick("left", $pos[2] - 6, $pos[3] - 6)
    EndIf
EndIf
Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

If ControlCommand("", "", 1969446, "IsVisible", "") Then
    MsgBox(0, "Cross-section", "Visisble")
    $result = $result & 1
    $pos = ControlGetPos("", "", 1969446)
    If IsArray($pos) Then
        MsgBox(0, "Cross-section pos", "x: " & $pos[0] & "y: " & $pos[1] & "w: " & $pos[2] & "h: " & $pos[3])
        MouseClick("left", $pos[2] - 6, $pos[3] - 6)
    EndIf
EndIf
If it's not an array, you may have to give a title... to the Control ID
$pos isn't coming up as an array which I figured was the problem anyway. Unfortunately, the control doesn't have a name, just an ID. It's generated by a 3rd party. Regardless, I would expect that passing the controlID would work fine (as it does for ControlCommand("", "", 1969446, "IsVisible", "")). The Help doesn't say anything about what is returned if there is an error, only that @error is set to 1.

Edit:

For some reason, I get the feeling your trying to do this with $result:

If ControlCommand("", "", 1969446, "IsVisible", "") Then
    MsgBox(0, "Cross-section", "Visisble")
    $result = $result + 1
    $pos = ControlGetPos("", "", 1969446)
    If IsArray($pos) Then
        MsgBox(0, "Cross-section pos", "x: " & $pos[0] & "y: " & $pos[1] & "w: " & $pos[2] & "h: " & $pos[3])
        MouseClick("left", $pos[2] - 6, $pos[3] - 6)
    EndIf
EndIf
$result is used to keep track of my test status. I And it with the $result value from previous tests. If any single test fails, $result will be 0 at the end, otherwise it will be 1.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well, I'm quite sure you can't use $result = $result And 1

As far as the title, does it have a class under the empty title name in the AutoInfo tool?

Edit:

What I should say... is that $result will always return false with "And" I believe... I could be wrong.

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

Well, I'm quite sure you can't use $result = $result And 1

As far as the title, does it have a class under the empty title name in the AutoInfo tool?

$result = $result And 1 works fine. I use it in plenty of other places. That's not the issue here.

Yes, there is a value for class, but unfortunately, it's the same for every control in the application, so it's useless to me.

Share this post


Link to post
Share on other sites

$result = $result And 1 works fine. I use it in plenty of other places. That's not the issue here.

Yes, there is a value for class, but unfortunately, it's the same for every control in the application, so it's useless to me.

I don't think you know/understand what I'm talking about with the Class... I'm not speaking of the ClassNameNN.

But Good Luck...


[center]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.[/center]

Share this post


Link to post
Share on other sites

I don't think you know/understand what I'm talking about with the Class... I'm not speaking of the ClassNameNN.

But Good Luck...

I know/understand exactly what you're talking about. I wasn't looking at ClassNameNN, I was looking at Class. As I mentioned before, the UI elements for our application are developed by a 3rd party who decided not to give controls meaningful names/IDs.

The control I'm checking is in a non-modal window, i.e. I can still access the application's controls, even with the palette, for lack of a better term, visible

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I know/understand exactly what you're talking about. I wasn't looking at ClassNameNN, I was looking at Class. As I mentioned before, the UI elements for our application are developed by a 3rd party who decided not to give controls meaningful names/IDs.

The control I'm checking is in a non-modal window, i.e. I can still access the application's controls, even with the palette, for lack of a better term, visible

I'm not talking about the CONTROLS!!

Edit:

Here try this, I'm had an issue with notepad using the actual control id, but not the ClassNameNN...

Opt('MouseCoordMode', 2); since we are using Contolpos
$result = ''
$Cpos = ControlGetPosByEXE('notepad.exe', 'Edit1'); Using the ClassNameNN I get a return, but not the control id - 15
If $Cpos <> 0 Then
    $result = $result And 1
    MsgBox(0, "Cross-section pos", " x: " & $Cpos [0] & @CR & " y: " & $Cpos [1] & @CR & " w: " & $Cpos [2] & @CR & " h: " & $Cpos [3])
    MouseClick("left", $Cpos [2] - 6, $Cpos [3] - 6)
EndIf

Func ControlGetPosByEXE($s_EXE, $v_ControlID_ClassNameNN, $v_ControlID_ClassNameNN_Text = '')
    Local $i_EXEPID = ProcessExists($s_EXE)
    Local $a_WinList = WinList()
    For $i_Count = 1 To $a_WinList[0][0]
        If WinGetProcess($a_WinList[$i_Count][1]) = $i_EXEPID Then
            If ControlCommand($a_WinList[$i_Count][0], $v_ControlID_ClassNameNN_Text, $v_ControlID_ClassNameNN, 'IsVisible', '') Then
                Local $Cpos = ControlGetPos($a_WinList[$i_Count][0], $v_ControlID_ClassNameNN_Text, $v_ControlID_ClassNameNN)
                If IsArray($Cpos) Then
                    Return $Cpos
                Else
                    Return 0
                EndIf
            EndIf
        EndIf
    Next
    Return 0
EndFunc
Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

I'm not talking about the CONTROLS!!

Well that's what I'm working with here. The window Class is irrelevant to the ControlGetPos() function and, as I mentioned previously, the Title is blank.

Edit:

Here try this, I'm had an issue with notepad using the actual control id, but not the ClassNameNN...

Opt('MouseCoordMode', 2); since we are using Contolpos
$result = ''
$Cpos = ControlGetPosByEXE('notepad.exe', 'Edit1'); Using the ClassNameNN I get a return, but not the control id - 15
If $Cpos <> 0 Then
    $result = $result And 1
    MsgBox(0, "Cross-section pos", " x: " & $Cpos [0] & @CR & " y: " & $Cpos [1] & @CR & " w: " & $Cpos [2] & @CR & " h: " & $Cpos [3])
    MouseClick("left", $Cpos [2] - 6, $Cpos [3] - 6)
EndIf

Func ControlGetPosByEXE($s_EXE, $v_ControlID_ClassNameNN, $v_ControlID_ClassNameNN_Text = '')
    Local $i_EXEPID = ProcessExists($s_EXE)
    Local $a_WinList = WinList()
    For $i_Count = 1 To $a_WinList[0][0]
        If WinGetProcess($a_WinList[$i_Count][1]) = $i_EXEPID Then
            If ControlCommand($a_WinList[$i_Count][0], $v_ControlID_ClassNameNN_Text, $v_ControlID_ClassNameNN, 'IsVisible', '') Then
                Local $Cpos = ControlGetPos($a_WinList[$i_Count][0], $v_ControlID_ClassNameNN_Text, $v_ControlID_ClassNameNN)
                If IsArray($Cpos) Then
                    Return $Cpos
                Else
                    Return 0
                EndIf
            EndIf
        EndIf
    Next
    Return 0
EndFunc
Using the ClassNameNN value works as far as returning the array correctly. However, this won't work for me, because there are at least two other controls that have this ClassNameNN value. This means that if more than one control is open, I can't guarentee that I would be getting the correct coords. However, the control ID is unique, which is what I need to use. But as we've discovered, it doesn't work.

Share this post


Link to post
Share on other sites

Does the Control have text that is unique to that control id? And the Class was relevant... (but you never even bothered to ask why, just dismissed it).


[center]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.[/center]

Share this post


Link to post
Share on other sites

Does the Control have text that is unique to that control id? And the Class was relevant... (but you never even bothered to ask why, just dismissed it).

Yes, there is unique text. I never said that Class wasn't relevant. I said it was irrelevant to the ControlGetPos() function.

So how is Class relevant to what I'm trying to do?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Wouldn't need the function I wrote for one:

Opt('WinTitleMatchMode', 4)
ControlGetPos('classname=Class', 'Text of Control', 'ClassNameNN')
See the relevance even with ControlGetPos()?

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

Wouldn't need the function I wrote for one:

Opt('WinTitleMatchMode', 4)
ControlGetPos('classname=Class', 'Text of Control', 'ClassNameNN')
See the relevance even with ControlGetPos()?
I wouldn't need your function anyway, as I don't need to check if the process exists or iterate through the list of active windows, nor do I have any problem with ControlCommand() the way I have it written.

Using ControlGetPos("classname=Class", "Text of Control, controlID) wouldn't work any more than ControlGetPos("", "Text of Control", controlID).

So no, I don't see the relevance, when the problem is with using controlID instead of ClassNameNN.

This is a problem with the help file, as it says to use controlID.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

There's no problem with the help file... It's correct, but I agree that it should say that ClassNameNN can be an option... Practice your own bad coding habits I guess... just hope you never have a application with the same control id...

Edit:

Removed a negative response

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

There's no problem with the help file... It's correct, but I agree that it should say that ClassNameNN can be an option... Practice your own bad coding habits I guess... just hope you never have a application with the same control id...

Leaving my personal feeling aside here on what I'd really like to say in this post, I'll say it like this... If your going to ask a question... then TRY EVERYTHING before you respond with less than par knowledge of the options.

How is the help file correct? It says to use controlID, which doesn't work period. Looking at the help on controls, it says you can substitute ClassNameNN for controlID (in my case this only works along with using unique text), but that this is usually only required if the controlID is the same for multiple controls (which can happen, but doesn't in my case). I would expect then that using controlID would work as it does for ControlCommand().

Share this post


Link to post
Share on other sites

How is the help file correct? It says to use controlID, which doesn't work period. Looking at the help on controls, it says you can substitute ClassNameNN for controlID (in my case this only works along with using unique text), but that this is usually only required if the controlID is the same for multiple controls (which can happen, but doesn't in my case). I would expect then that using controlID would work as it does for ControlCommand().

i use control id's whenever i have an app that doesn't change them on every execution, and doesn't duplicate them. it sounds like you're using non standard controls, so any success you have with them should not be taken for granted. i also think that 'assume' is more appropriate than 'expect'.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

i use control id's whenever i have an app that doesn't change them on every execution, and doesn't duplicate them. it sounds like you're using non standard controls, so any success you have with them should not be taken for granted. i also think that 'assume' is more appropriate than 'expect'.

You're right, they are non-standard controls. However, the ids don't change on every execution and aren't duplicated.

Share this post


Link to post
Share on other sites

You're right, they are non-standard controls. However, the ids don't change on every execution and aren't duplicated.

can you attach the screenshots i asked for before to see if anyone else has some ideas when they're given more information, or do you want to continue expecting, assuming, and complaining to no avail?

Note: AutoIt only works with standard Microsoft controls - some applications write their own custom controls which may look like a standard MS control but may resist automation. Experiment!


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

can you attach the screenshots i asked for before to see if anyone else has some ideas when they're given more information, or do you want to continue expecting, assuming, and complaining to no avail?

What screenshots?

Share this post


Link to post
Share on other sites

What screenshots?

haha, my bad, that was a different guy. mixed up my threads. you should post a screenshot of the autoit window info for a couple of these controls, and the app you're interacting with

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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
Sign in to follow this  
Followers 0