找回密码
 加入
搜索
查看: 1949|回复: 5

[AU3基础] 如何用自定义按钮而不是关闭按钮跳出循环

  [复制链接]
发表于 2017-10-11 00:12:13 | 显示全部楼层 |阅读模式
本帖最后由 lyf362345 于 2017-10-11 00:33 编辑

搜索了下 目前能用点击关闭跳出来了, 但是没找到用自定义按钮跳出的方式

想做到的结果是 点击开始按钮 开始循环, 点击关闭 结束循环

参考这个 已经解决 http://autoitx.com/forum.php?mod=viewthread&tid=37727

但是有个小问题就是 如果 sleep 的时间过久, 比如5秒, 那么点击停止就会延迟5秒才会生效, 这个怎么弄呢
发表于 2017-10-11 19:53:06 | 显示全部楼层
回复 1# lyf362345


    你那链接 不是 写得好详细了么? 用注册 消息
GUICreate('test', 200, 100)
$button1 = GUICtrlCreateButton('start', 50, 50)
$button2 = GUICtrlCreateButton('stop', 150, 50)
GUISetState()
GUIRegisterMsg(0x111, '_WM_COMMAND')

Dim $a=1
While 1
        $msg = GUIGetMsg()
        Switch $msg
                Case -3
                        Exit
                Case $button1
                        test()
                Case $button2
                        
        EndSwitch
WEnd

Func Button_2()
exit MsgBox(0, '', 'a='&$a)
EndFunc

Func test()
For $i=1 to 999999
sleep(999)
$a+=1
Next
EndFunc   ;==>test


Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        If BitAND($wParam, 0x0000FFFF) = $button2 Then Button_2()
EndFunc   ;==>_WM_COMMAND
发表于 2017-10-11 20:16:29 | 显示全部楼层
本帖最后由 lin6051 于 2017-10-11 20:18 编辑


GUICreate('test', 200, 100)
$button1 = GUICtrlCreateButton('start', 50, 50)
$button2 = GUICtrlCreateButton('stop', 150, 50)
GUISetState()
GUIRegisterMsg(0x111, '_WM_COMMAND')
GUIRegisterMsg(0x112, '_WM_SYSCOMMAND')

Dim $a = 1
While 1
        $msg = GUIGetMsg()
        Switch $msg
                Case $button1
                        test()
        EndSwitch
WEnd

Func Button_2()
        Exit MsgBox(0, '', 'a=' & $a)
EndFunc   ;==>Button_2

Func test()
        For $i = 1 To 999999
                Sleep(999)
                $a += 1
        Next
EndFunc   ;==>test


Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        Switch BitAND($wParam, 0x0000FFFF)
                Case $button2
                        Button_2()
        EndSwitch
EndFunc   ;==>_WM_COMMAND


Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)
        Switch $wParam
                Case 0xF060
                        Button_2()
        EndSwitch
EndFunc   ;==>_WM_SYSCOMMAND

 楼主| 发表于 2017-10-11 22:57:26 | 显示全部楼层
回复 2# lin6051


    感谢, 我研究下看看
 楼主| 发表于 2017-10-11 22:57:35 | 显示全部楼层
回复 3# lin6051


    谢谢
发表于 2017-10-12 08:07:14 | 显示全部楼层
回复 3# lin6051


    我研究下看看
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-20 21:41 , Processed in 0.070527 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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