找回密码
 加入
搜索
查看: 2369|回复: 4

[AU3基础] 关于onevent[已解决]

[复制链接]
发表于 2011-5-18 00:37:01 | 显示全部楼层 |阅读模式
本帖最后由 love5173 于 2011-5-18 12:08 编辑

帮别人写的一个小工具,由于自己这个模式也不是很熟练,导致循环退出出现问题,请高手指教一下
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("xxx亲情打造", 221, 315, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("执行次数:", 16, 256, 55, 17)
$Label2 = GUICtrlCreateLabel("0", 96, 248, 82, 33)
GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("开始", 48, 56, 113, 113)
GUICtrlSetFont(-1, 30, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $txt="三茅招聘管理软件 - 安装向导"


While 1
        Sleep(100)
WEnd

Func Button1Click()
        Global $i=0
        Global $a=0
        
        Global $zhuangtai=GUICtrlRead($Button1)
        If $zhuangtai="开始" Then
                GUICtrlSetData($Button1,"结束")
                Global $a=1
                While $a
                anzhuang()
                
                Sleep(2000)
                If $a Then  xiezai()
                
                cishu($i)
                WEnd
        Else
                GUICtrlSetData($Button1,"开始")
                ProcessClose("3MRecruitInstall.exe")
                ProcessClose("setup.exe")
                
                
        EndIf
EndFunc
Func Form1Close()
        Exit
EndFunc
Func anzhuang()
        Run("3MRecruitInstall.exe")
        WinWait($txt,"欢迎使用")
        WinActivate($txt,"欢迎使用")
        Send("!N")
        WinWait($txt,"许可证协议")
        WinActivate($txt,"许可证协议")
        ControlCommand($txt,"许可证协议","Button5","Check", "")
        Sleep(100)
        Send("!N")
        WinWait($txt,"选择目的地位置")
        WinActivate($txt,"选择目的地位置")
        Send("!N")
        WinWait($txt,"可以安装该程序了")
        WinActivate($txt,"可以安装该程序了")
        Send("{ENTER}")
        WinWait($txt,"安装向导")
        WinActivate($txt,"安装向导")
        Send("{SPACE}")
        Sleep(300)
        Send("{ENTER}")
        WinWait("readme.txt - 记事本","")
        WinClose("readme.txt - 记事本","")
EndFunc
Func xiezai()
        Run("C:\Program Files\InstallShield Installation Information\{2E2A12B5-84D7-4C2C-834E-E258159F6E3C}\setup.exe")
        WinWait("三茅招聘管理软件","欢迎")
        WinActivate("三茅招聘管理软件","欢迎")
        Send("!R")
        Sleep(300)
        Send("!N")
        Sleep(500)
        Send("Y")
        WinActivate("三茅招聘管理软件","卸载完成")
        Send("{DOWN}")
        Sleep(300)
        Send("{ENTER}")
        
EndFunc
Func cishu($i)
        $i+=1
        GUICtrlSetData($Label2,$i)
EndFunc
发表于 2011-5-18 10:41:21 | 显示全部楼层
因为没有与程序相关的软件,仅是猜测.
问题不是出在消息模式上,而是出在32行开始的循环上.因为AU3不支持多线程,所以只能提高响应级别来对循环进行中断.代码思路如下,不知道有没有帮助.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

Global $Flg = True
Global $Click = 0
Local $t = 0

$Form1 = GUICreate("Form1", 318, 120, 468, 171)
GUISetOnEvent(-3, "_exit")
$Button1 = GUICtrlCreateButton("开始循环", 48, 60, 80, 40)
GUICtrlSetOnEvent(-1, "Click")
$Lable = GUICtrlCreateLabel("", 208, 60, 80, 40)
;$Button2 = GUICtrlCreateButton("结束循环", 208, 60, 80, 40)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
        Sleep(100)
WEnd

Func _exit()
        Exit
EndFunc   ;==>_exit

Func Click()
        If GUICtrlRead($Button1) = "开始循环" And $Flg = True Then
                GUICtrlSetData($Button1, "结束循环")
                $Click += 1
                GUICtrlSetData($Lable, "执行第" & $Click & "次循环")
                TEST()
        Else
                GUICtrlSetData($Button1, "开始循环")
        EndIf
EndFunc   ;==>Click

Func TEST()
        While $Flg
                ToolTip($t)
                $t += 1
        WEnd
        $Flg = True
        $t = 0
EndFunc   ;==>TEST

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        #forceref $hWnd, $Msg
        Local $nNotifyCode = BitShift($wParam, 16)
        Local $nID = BitAND($wParam, 0x0000FFFF)
        Local $hCtrl = $lParam
        Switch $hCtrl
                Case GUICtrlGetHandle($Button1)
                        If GUICtrlRead($Button1) = "结束循环" Then
                                $Flg = False
                        Else
                                $Flg = True
                        EndIf
        EndSwitch
EndFunc   ;==>WM_COMMAND
 楼主| 发表于 2011-5-18 12:07:24 | 显示全部楼层
回复 2# 3mile
谢谢3M的代码,提高响应级别,以前没接触过,我要消化一下!
发表于 2011-6-9 12:17:03 | 显示全部楼层
回复 4# qqwangbiz


    哪里有才了??
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-2 01:22 , Processed in 0.109542 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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