Sign in to follow this  
Followers 0
LostOneInLine

Another ControlClick problem

5 posts in this topic

Ive been playing around with this program for quite a while (trying to make my own script using the forums and help). Ive hit a block with this ControlClick function. Im using to click into a specific program. For demonstration purposes, Ive converted the script to open a word doc (Office 03 w/ on XP) and click the open icon on the standard toolbar. It is pretty close to what I am trying to accomplish with the other program being that the control is the whole toolbar and the button I want to hit is in an arbitrary location. Im sure it is just me doing something wrong, but Ive tried for days and cannot get it figured out (and yes, Ive been through every forum post, help file, and example I can find).

Thanks in advance (Im sure someone is going to just glance at this and straiten me out.) :)

Opt("WinTitleMatchMode", -2); just so i can be as vauge as possible  :-)
; Run word. 
run ("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE");Is there any way to make this more generic for most/all comps.?
; I plan on having the control window hidden, but i show it here to see if the controlclick works.
WinActivate("Word","")
; I should be able to skip getting the handle, not sure though.
$HANDLE = WinGetHandle("Word","[ClassnameNN:MsoCommandBar7]"); Handle of "standard" toolbar.
; Some thinking time. (I guess?)
SLEEP (3000)
; I read somewhere that the Control may need to be active to be clicked.
WinActivate ($HANDLE)
; The meat of the issue.
$click = ControlClick("Microsoft Access - [Main Switchboard]","Menu Bar (custom)",$HANDLE, "LEFT",3,44,12)
; A message box to show success (1) or failure (0). (Making sure it found the handle.)
MsgBox (0,"",$CLICK); success in finding handle.
; Giving it another try a different way.
$click = ControlClick($HANDLE,"",$HANDLE, "","",44,12)
MsgBox (0,"",$CLICK); success in finding handle.
; ...and again (no variables).
$click = ControlClick("Word","","[ClassnameNN:MsoCommandBar7]", "LEFT",3,44,12)
MsgBox (0,"",$CLICK); failure in finding handle.


; No click with any of them.

Also ~~~~> How do I get my posted script to show up "AutoIt style"?

Share this post


Link to post
Share on other sites



You can use the word.au3 UDF to open the file:

#include <word.au3>

; Run word.
_WordCreate(@ScriptDir & "\Test1.doc")

Create the AutoIt code box by putting {autoit}{/autoit} tags around the code (with square brackets "[]" instead of curly braces).

You have chosen a very complex example because the file open button is on a re-configurable menu bar:

>>>> Window <<<<
Title:  Test1.doc - Microsoft Word
Class:  OpusApp
Position:   -4, -4
Size:   1288, 930
Style:  0x17CF0000
ExStyle:    0x00000110
Handle: 0x01460210

>>>> Control <<<<
Class:  MsoCommandBar
Instance:   3
ClassnameNN:    MsoCommandBar3
ID: 
Text:   Standard
Position:   0, 28
Size:   698, 28
ControlClick Coords:    43, 20
Style:  0x56000000
ExStyle:    0x00000000
Handle: 0x013201E0

That's not a good place to start learning the basics of ControlClick().

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

True...

Thanks for the advise.

It was the only thing I could find at the time that had a control with multiple "clickables" in it. Here is something everyone has that can't be customized.

Opt("WinTitleMatchMode", -2); just so i can be as vauge as possible  :-)
; Run Au3Info.
run ("C:\Program Files\Autoit3\Au3Info.exe")
; See if the controlclick works.
WinActivate("Window Info","")
; I should be able to skip getting the handle, not sure though.
$HANDLE = WinGetHandle("Window Info","[ClassnameNN:systabcontrol321]"); Handle of "tabs" toolbar.
SLEEP (3000)
;activate handle
WinActivate ($HANDLE)
; Click the Control tab (kind of ironic).
$click = ControlClick("Window Info","",$HANDLE, "LEFT",3,75,10)
; A message box to show success (1) or failure (0). (Making sure it found the handle.)
MsgBox (0,"",$CLICK); success in finding handle.
; Giving it another try a different way.
$click = ControlClick($HANDLE,"",$HANDLE, "","",75,10)
MsgBox (0,"",$CLICK); success in finding handle.
; ...and again (no variables).
$click = ControlClick("Window Info","","[ClassnameNN:systabcontrol321]", "LEFT",3,75,10)
MsgBox (0,"",$CLICK); failure in finding handle.


; No click with any of them.

YAY!, AUTOIT SCRIPT!!!

Share this post


Link to post
Share on other sites

True...

Thanks for the advise.

It was the only thing I could find at the time that had a control with multiple "clickables" in it. Here is something everyone has that can't be customized.

YAY!, AUTOIT SCRIPT!!!

Two problems.

First, you can't WinActivate() and WinGetHandle() microseconds after you do Run() and expect the window to be there yet. Use WinWait() to wait for the window to exist before pressing on.

Second, you have chosen a complex control again (systabcontrol321) that is not normally automated with ControlClick to begin with. Still it can be made to work:

Opt("WinTitleMatchMode", 4)

; Provide a way to exit the script
HotKeySet("{ESC}", "_Quit")

; Tab coordinates inside the tab control
Global $Y = 12
Global $avX[7] = [27, 75, 131, 197, 267, 310, 360]

; Run Au3Info.
Run("C:\Program Files\Autoit3\Au3Info.exe")

WinWait("[CLASS:Au3Info]")
Global $hWin = WinGetHandle("[CLASS:Au3Info]")
WinActivate($hWin)
While 1
    For $n = 0 To UBound($avX) - 1
        Sleep(1000)
        ControlClick($hWin, "", "[CLASSNN:SysTabControl321]", "Left", 1, $avX[$n], $Y)
    Next
WEnd

Func _Quit()
    WinClose($hWin)
    Exit
EndFunc

This depends on knowing exactly what X/Y coordinates in the tab control represent the tabs. If you didn't know that, you would instead use the _GuiCtrlTab_* UDFs.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks again Salty. I'm sure I can figure it out with the example script.

I'm somewhat excessive when it comes to learning new things so I've been a little shy to stem into the gew. Maybe this weekend will be dedicated to it.

I'll be a developer before you know it. :)

hehe

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