Jump to content

Detecting state change of toolbar button


maf
 Share

Recommended Posts

Hi,

In my (first) AutoIt script, I have to wait until a scan result is displayed in an application. The only reliable visible hint in the application's interface is the state of a toolbar button. This button is displayed in a "pressed" state while the application is busy, and in "normal" state afterwards.

How can I detect this button state change in AutoIt? What are the AutoIt best practices to wait for an clandestine application to finish some task? Currently I use Sleep(). There must be a better way :-).

Thanks in advance,

Malte

Link to comment
Share on other sites

Hi,

In my (first) AutoIt script, I have to wait until a scan result is displayed in an application. The only reliable visible hint in the application's interface is the state of a toolbar button. This button is displayed in a "pressed" state while the application is busy, and in "normal" state afterwards.

How can I detect this button state change in AutoIt? What are the AutoIt best practices to wait for an clandestine application to finish some task? Currently I use Sleep(). There must be a better way :-).

Thanks in advance,

Malte

i know on a browser you can do this easily. perhaps you can use the autoit window info tool to help with this.

here is how you would do it on a browser

while 1

$x = StatusbarGetText("window name")

If $x <> "Done" Then
;do something and exitloop
Else
sleep(100)
endif
Wend

EDIT: you can also pixelsearch the button and compare it when its pressed.

i am sure the color variates slightly.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

  • Moderators

maf,

Welcome to the AutoIt forum. :mellow:

Detecting the change in the toolbar button can be done a number of ways - a lot depends on the type of control you are looking at.

Have you used the Au3 Window Info tool to see if the toolbar is standard? If so you will probably be able to use the GUICtrlToolBar UDF to detect what is going on. If you have not yet used this tool, you will find it at "C:\Program Files\AutoIt3\Au3Info.exe" on a standard install. It is pretty self-explanatory to use - post the results here so we can see what type of control we are dealing with.

If it is a non-standard toolbar (as is often the case) you may have to fall back on looking at any changes in colour within the button - assuming there are any! :( Are you sure there is nothing else which changes? Window title, status bar, etc?

See you soon.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

thanks for the friendly welcome and your help! It took me a while to read up on your suggestions and write some test scripts - I didn't want to bother you with questions that I could answer myself. But unfortenately I couldn't come up with a solution...

The application I'm trying to control in the following examples is HP PrecisionScan Pro, a scanner utility. In the final script, I'm controlling Adobe Acrobat which in turn is using HP PrecisionScan Pro.

First, I re-checked whether the status bar might provide a clue. But it always holds the same text. I'm curious, though. Why does

$winPrecScan = WinActivate("HP PrecisionScan Pro")
$statusText = StatusbarGetText($winPrecScan, 0)
give the correct result "Bereit" while
$winPrecScan = WinActivate("HP PrecisionScan Pro")
$statusText = _GUICtrlStatusBar_GetText($winPrecScan, 0)
returns an empty string?

Then, I tried the toolbar. Its first (leftmost) button is pressed during the operation my script has to wait for. Using the AutoIt Window Info tool, I got:

>>>> Window <<<<
Title:  HP PrecisionScan Pro
Class:  Afx:400000:0:0:0:2feb05b1
Position:   562, 111
Size:   456, 590
Style:  0x14CF0000
ExStyle:    0x00000100
Handle: 0x004807DA

>>>> Control <<<<
Class:  ToolbarWindow32
Instance:   2
ClassnameNN:    ToolbarWindow322
Name:   
Advanced (Class):   [CLASS:ToolbarWindow32; INSTANCE:2]
ID: 59392
Text:   
Position:   -2, 0
Size:   340, 27
ControlClick Coords:    28, 17
Style:  0x5400084E
ExStyle:    0x00000000
Handle: 0x004507B0

>>>> Mouse <<<<
Position:   592, 170
Cursor ID:  0
Color:  0xD6D3CE

>>>> StatusBar <<<<
1:  Bereit
2:  
3:  Bildgröße: 1,3 MB

>>>> ToolsBar <<<<
1:  32810   
2:  32806   

>>>> Visible Text <<<<
GTF
hppspview
Bereit
Auflösung ändern
300
300
21,61
35,57
100%
100%


>>>> Hidden Text <<<<
So I wrote the following script:
#Include <GuiToolBar.au3>
$winPrecScan = WinActivate("HP PrecisionScan Pro")
$ctlToolBar = WinGetHandle("[CLASS:ToolbarWindow32; INSTANCE:2]")
$iCount = _GUICtrlToolbar_ButtonCount($ctlToolBar)
For $iIndex = 0 To $iCount
    $iCommand = _GUICtrlToolbar_IndexToCommand($ctlToolBar, $iIndex)
    $btnText = _GUICtrlToolbar_GetButtonText($ctlToolBar, $iCommand)
    ConsoleWrite($iIndex & " " & $btnText & @CRLF)
next
To my surprise, this prints
0 ActivePerl 5.10.0 Build 1004
1 Adobe Acrobat SDK 4.0
2 ArgoUML
3 AutoIt v3
4 Code Browser
5 CSDiff
6 Cygwin
7 Eclipse
8 Git
9 GnuWin32
10 MinGW
11 Notepad++
12 PHP 5
13 Python 2.5
14 StarUML
15 Tiny Hexer
16 TortoiseGit
17 TortoiseSVN
18 Vim 7.2
19 wSciTE 1.67
20 ActivePerl 5.10.0 Build 1004
This is a list of folder names in a submenu of my Windows's start menu. So I'm obviously doing something wrong here.

Finally, I tried

$winPrecScan = WinActivate("HP PrecisionScan Pro")
$ctlToolBar = WinGetHandle("[CLASS:ToolbarWindow32; INSTANCE:2]")
$iCommand = _GUICtrlToolbar_IndexToCommand($ctlToolBar, 0)
$result = _GUICtrlToolbar_PressButton($ctlToolBar, $iCommand)
and
$winPrecScan = WinActivate("HP PrecisionScan Pro")
$ctlToolBar = WinGetHandle("[CLASS:ToolbarWindow32; INSTANCE:2]")
$iCommand = _GUICtrlToolbar_IndexToCommand($ctlToolBar, 0)
$result = _GUICtrlToolbar_SetButtonState($winPrecScan, $iCommand, $TBSTATE_INDETERMINATE)
which probably don't work as hoped because $ctlToolBar is garbage anyway.

So, after all that, what are my mistakes, how do I properly use the Info Tool results, and how do "pixelsearch the button and compare it when its pressed".

Thanks again,

Malte

Link to comment
Share on other sites

  • Moderators

maf,

Where to start? :P

How about in order:

I'm curious, though. Why does....

Because the first command (StatusbarGetText) is built-in and is expecting the handle of a window as the parameter. The second command (_GUICtrlStatusBar_GetText) is from the StatusBar UDF and is expecting the handle of a status bar created with _GUICtrlStatusBar_Create. OK, that got the easy bit out of the way... :mellow:

To my surprise, this prints

That is because you are using the wrong command. You are using:

$ctlToolBar = WinGetHandle("[CLASS:ToolbarWindow32; INSTANCE:2]")

When you should be using:

$ctlToolBar = ControlGetHandle("HP PrecisionScan Pro", "", "[CLASS:ToolbarWindow32; INSTANCE:2]")

At present you are opening a WINDOW with the identity "[CLASS:ToolbarWindow32; INSTANCE:2]", not a CONTROL with that identity. That sort of window is ususally something Explorer-based - in your case it looks like the "Start" button (the other instances on my Vista system are the quick-start menu {3}, the taskbar icons (4) and the systray {1} - I do not have a {2} so I suspect you are running XP).

Still here? :( I hope that the above might solve your problem. If it does not, then please come back and we can discuss other avenues - even the pixel reading option if we have to. :lol:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

thanks again.

Using ControlGetHandle solved my problem. I ended up with

; wait until scan is completely displayed
$hdlToolBar = ControlGetHandle("HP PrecisionScan Pro", "", "[CLASS:ToolbarWindow32; INSTANCE:2]")
$cidNewScan = _GUICtrlToolbar_IndexToCommand($hdlToolBar, 0)
While BitAND(_GUICtrlToolbar_GetButtonState($hdlToolBar, $cidNewScan), $TBSTATE_CHECKED)
    Sleep(100)
WEnd

This code is part of a function named scanOnePage(), which is called by scan(). Initially, I had placed the initialization of $hdlToolBar and $cidNewScan in scan(), after a WinWaitActive("HP PrecisionScan Pro") and before the call to scanOnePage. But sometimes, ControlGetHandle would return an error. And when I added the duplicate call to ControlGetHandle to scanOnePage(), the results of both calls were different even if both were successfull. Could someone please explain why?

BTW, I used a screen capture software named CamStudio to determine when to wait for which window to become active and to determine the name and text of some windows flashing by. How are you guys doing this?

Cheers, Malte

Edited by maf
Link to comment
Share on other sites

  • 1 year later...

maf,

Welcome to the AutoIt forum. :)

Detecting the change in the toolbar button can be done a number of ways - a lot depends on the type of control you are looking at.

Have you used the Au3 Window Info tool to see if the toolbar is standard? If so you will probably be able to use the GUICtrlToolBar UDF to detect what is going on. If you have not yet used this tool, you will find it at "C:\Program Files\AutoIt3\Au3Info.exe" on a standard install. It is pretty self-explanatory to use - post the results here so we can see what type of control we are dealing with.

If it is a non-standard toolbar (as is often the case) you may have to fall back on looking at any changes in colour within the button - assuming there are any! :) Are you sure there is nothing else which changes? Window title, status bar, etc?

See you soon.

M23

if there are changes with status bar then how to deal wiyh it ............?????????

Link to comment
Share on other sites

  • Moderators

jimpatel90,

Welcome to the AutoIt forum. :)

In future please start a new topic rather then resurrecting one more than a year old. :)

if there are changes with status bar then how to deal wiyh it

If you want to deal with the status bar then the GuiStatusBar UDF is your friend - take a look at the many _GUICtrlStatusBar_* functions in the Help file.

If you provide a more specific question, we can perhaps give you more pertinent help. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

jimpatel90,

Welcome to the AutoIt forum. :)

In future please start a new topic rather then resurrecting one more than a year old. :)

If you want to deal with the status bar then the GuiStatusBar UDF is your friend - take a look at the many _GUICtrlStatusBar_* functions in the Help file.

If you provide a more specific question, we can perhaps give you more pertinent help. :P

M23

thank u very much Melba23

i'll be careful to start a new topic as per ur suggestion

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