找回密码
 加入
搜索
查看: 3305|回复: 7

[AU3基础] (已解决)Is there got a function can search the letters on a button?

  [复制链接]
发表于 2010-5-20 09:24:03 | 显示全部楼层 |阅读模式
本帖最后由 yarsye 于 2010-9-4 12:29 编辑

Sorry , my current running system is Eng OS , i just want to click a button not using Control ID or Advanced(Class) , for they will change on the same button on different OSes, so i think it could be done if click the button using search the letters on that button .Is there got a function or a method able to solve this issue?
Thanks for your viewing .
发表于 2010-5-20 09:37:25 | 显示全部楼层
CLASS also change on the different OS?
发表于 2010-5-20 09:41:31 | 显示全部楼层
本帖最后由 netegg 于 2010-5-20 09:45 编辑

Try function guictrlread($button) if the program is made by youself. If not, they shouldn't be changed, just like sxd's thought.
 楼主| 发表于 2010-5-20 10:14:00 | 显示全部楼层
Yes ,in my system there is a button in the application got two same Control ID (1003) ,and the Advanced(Class) :[CLASS:Button; INSTANCE:8]-- "INSTANCE8"will also change to 20 or 38 , i have no idea about this , but it really comes.
发表于 2010-5-20 10:37:15 | 显示全部楼层
See 'advanced window matching options', which locates in Help File->AutoIt->Using AutoIt->Window Titles and Text (Advanced).

PS:
Q: How to resolve my system language problem?
A: Control Panel->Regional and Language Options->Advanced->select 'Chinese (RPC)' for a non-Unicode program->OK->Restart your computer.
发表于 2010-5-20 10:55:52 | 显示全部楼层
Maybe different wintitle's letters was got on different OSes, and if you want to search the letters you must be get the correct title of the window ,so I don't find a way to do that(Maybe you can make a Multilingual version~~ :-)  ).
But, if you just want to click a button , you can try the function "Mouseclick()"
You can see the Autoit Helpfile for the "Mouseclick()" function.
发表于 2010-5-20 10:58:15 | 显示全部楼层
test this code.
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $BtClickFlg=True  ;Declare a global variable ,if button clicked, this global variable will control the function not to run again.
$Form1 = GUICreate("Form1", 122, 196, 192, 114)   ;create form
$Button1 = GUICtrlCreateButton("Myfirst BT", 8, 8, 105, 41)   ;create button
$Button2 = GUICtrlCreateButton("Mysecond BT", 8, 72, 105, 41)
$Button3 = GUICtrlCreateButton("Mythird BT", 8, 136, 105, 41)
GUISetState(@SW_SHOW)   ;show form
#EndRegion ### END Koda GUI section ###
$stringtoclickbt=InputBox("Input","Please input which button you want to click:","","",300,80)  ;input the letter on the button which you want to click
While 1   ;message loop
        $nMsg = GUIGetMsg()  ;get message
        Switch $nMsg  ;switch message
                Case $GUI_EVENT_CLOSE  ;if message is $GUI_EVENT_CLOSE,exit program
                        Exit
                Case $Button1  ;if message is button1
                        MsgBox(0,"Button1 Click","You clicked button1!")  ;show a messagebox, title is 'button1 click',text is 'You clicked button1!'
                        $BtClickFlg=False  ;set button click flg to false,the function just run once
                Case $Button2   
                        MsgBox(0,"Button2 Click","You clicked button2!")
                        $BtClickFlg=False
                Case $Button3
                        MsgBox(0,"Button3 Click","You clicked button3!")
                        $BtClickFlg=False
        EndSwitch
        If $BtClickFlg=True Then   ;if button click flg is true , call function clickbutton to Sends a mouse click command to the button witch you type in the inputbox
                clickbutton($stringtoclickbt)
        EndIf
WEnd

Func clickbutton($stringonbutton)
        Local $string1=GUICtrlRead($Button1)  ;Declare a local variable ,set the value is button1's text
        Local $string2=GUICtrlRead($Button2)  ;Declare a local variable ,set the value is button2's text
        Local $string3=GUICtrlRead($Button3)  ;Declare a local variable ,set the value is button3's text
        If $stringonbutton=$string1 Then   ;if button1's text is same to the string you type in, Sends a mouse click command to button1
                ControlClick($Form1,"",$Button1,"left")
        EndIf
        If $stringonbutton=$string2 Then  ;if button2's text is same to the string you type in, Sends a mouse click command to button2
                ControlClick($Form1,"",$Button2,"left")
        EndIf
        If $stringonbutton=$string3 Then  ;if button3's text is same to the string you type in, Sends a mouse click command to button3
                ControlClick($Form1,"",$Button3,"left")
        EndIf
EndFunc
 楼主| 发表于 2010-5-20 11:42:06 | 显示全部楼层
test this code.
lanfengc 发表于 2010-5-20 10:58


wonderful ! that's what i wanted . thanks
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-18 11:00 , Processed in 0.080661 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表