Sign in to follow this  
Followers 0
jack71

ControlGetText, ControlID doesn't work, yet dynamic ClassnameNN works

12 posts in this topic

I find it interesting that ControlClick can find the Control I want and click it, but ControlGetText can't use the ControlID to get the text that I need for my script...argh...

What are my options besides going through 30 machines to see what other variances of ClassnameNN there are?

Share this post


Link to post
Share on other sites



The other option is showing us the code, so we can try to spot any error that might be.

Best regards


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

The other option is showing us the code, so we can try to spot any error that might be.

Best regards

 

Here's the part that pertains to my problem:

Global $recordstatus

Global $mWindow = WinGetTitle("[REGEXPCLASS:Afx:00400000:b:00010003:00000006:.]") ; get dynamic window title

$recordstatus = ControlGetText($mWindow, "", 11301) ; find out if the program is running or if it is stopped.  There's a gui button that reads either "Start" or "Stop" depending on if it is actively recording or not.  The control ID for the button is 11301.

If $recordstatus = "stop", this means that the program is actively recording and it is OK to continue stopping/restarting the recording.  If $recordstatus = "start" that means the program is not actively recording and we don't need to stop anything, just exit.

Later on in the script where I have it stop/start the recording:

WinActivate($mWindow)
ControlFocus($mWindow, "Stop", 11301)
ControlClick($mWindow, "Stop", 11301)

 

The above works fine, it clicks on the stop button.  Then latter I have it start it back up with the same ControlID which is not dynamic.  It stays the same no matter what.

Here's my code prior to me finding out that the ClassnameNN isn't always the same on all 30 machines:

$RecordStatus = ControlGetText($mWindow, "", "Button61").  This will get me the text "Start" or "Stop" depending on what's going on with the recording, if the ClassnameNN is Button61.  

Share this post


Link to post
Share on other sites

I probably missed something, so the code works, and the controlid is static, but if you use the id, you don't get the text? How can i reproduce?


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

The code works, meaning controlgettext returns the values I need ONLY if I use the ClassnameNN of the button, and not the ControlID of the button!  This would be fine if the classnameNN was static, but it isn't it is dynamic across the 30 machines this code would be used.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Understood, sorry, i can't help you, can't think of any solution..

maybe, as a last resort.. pixelsearch, search for a specific shade of the button in the two states, or in a specific coordinate,

for example, search for black in a small rectangle, where the start word covers, but not the stop, or the other way around, know what i mean?

Edit: typo

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

Is there anyway to search for the text "Start" or "Stop" which is the only two options for that button and the only place "Start" or "stop" would show up on the window and somehow grab the control handle or get the classnamenn?

Share this post


Link to post
Share on other sites

Ok so maybe I can loop through an array of numbers, 0-100 until controlgettext gives a result of "stop" or "start" otherwise next.  I'm just not sure how to code a standalone array.

ex:

While 1

For $i = 0 to 100

$ButtonArray[x] = 0 - 100 (How do I assign an array the values 0-100?)

$recstatusresult = ControlGetText($mWindow, "", $ButtonArray[x])

If $recstatresult = Start or If $recstatresult = Stop then

  $recordstatus = $recstatresult[$i]

Else

Next

Endif

Need a little help here...

Thanks

Share this post


Link to post
Share on other sites

Good idea, from what i understood, you want to go through a range of id's?

Local $mWindow, $Buttons, $recstatresult

While 1
For $Buttons = 40 to 300 ;Or whatever the ID range you want to search for
    ConsoleWrite('$Buttons '& $Buttons &@CRLF)
$recstatusresult = ControlGetText($mWindow, "", $Buttons)
If $recstatresult = 'Start' or $recstatresult = 'Stop' then
$recordstatus = $Buttons
Endif
If $Buttons = 300 Then Exit
Next
WEnd

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

 

Good idea, from what i understood, you want to go through a range of id's?

Local $mWindow, $Buttons, $recstatresult

While 1
For $Buttons = 40 to 300 ;Or whatever the ID range you want to search for
    ConsoleWrite('$Buttons '& $Buttons &@CRLF)
$recstatusresult = ControlGetText($mWindow, "", $Buttons)
If $recstatresult = 'Start' or $recstatresult = 'Stop' then
$recordstatus = $Buttons
Endif
If $Buttons = 300 Then Exit
Next
WEnd

Yes a simple for loop.  Durr....man I'm dumb sometimes hah.  I changed yours up a little bit, going to try it later tonight:

Func FindClassNN()
Local $x, $recstatresult

While 1
For $x = 0 to 300
    $recstatusresult = ControlGetText($mWindow, "", "Button" & $x) ; ClassnameNN is always "ButtonXX"
If $recstatresult = "Start" or $recstatresult = "Stop" Then
    $recordstatus = "Button" & $x
    ExitLoop
ElseIf $x = 300 Then
    msgbox(0, "Ooops", "Button ClassnameNN is outside of range!") ; For debugging purposes
    ExitLoop
Endif
Next
WEnd
EndFunc
Edited by jack71

Share this post


Link to post
Share on other sites

We're here if you need help. :)


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

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