找回密码
 加入
搜索
查看: 1768|回复: 8

GUI循环请教

[复制链接]
发表于 2009-7-13 23:03:22 | 显示全部楼层 |阅读模式
本帖最后由 kkck 于 2009-7-15 14:56 编辑
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 292, 102, 832, 578)
$Button1 = GUICtrlCreateButton("1", 24, 24, 97, 41, $WS_GROUP)
$Button2 = GUICtrlCreateButton("2", 144, 24, 113, 41, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        a()
                Case $Button2
                        b()
        EndSwitch
WEnd


Func a()
        While 1
                Sleep(1000)
        WEnd
EndFunc

Func b()
        While 1
                Sleep(1000)
        WEnd
EndFunc
当a按钮运行后就不能运行b按钮(先按b,a就不能执行了) 窗口也不能关闭只能结束进程
怎样才能解决
发表于 2009-7-13 23:15:30 | 显示全部楼层
请使用事件模式。。。。
发表于 2009-7-13 23:21:03 | 显示全部楼层
"ControlDisable"
"ControlEnable"
看看这2个函数能帮到你不,自己研究下吧!
 楼主| 发表于 2009-7-14 00:52:23 | 显示全部楼层
请使用事件模式。。。。
大绯狼 发表于 2009-7-13 23:15
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("窗体1", 322, 130, 830, 320)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Button1 = GUICtrlCreateButton("Button1", 56, 24, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("Button2", 200, 40, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(100)
WEnd

Func Button1Click()
While 1    
        MsgBox(0,"1","1")
        Sleep(3000)
        WEnd
EndFunc

Func Button2Click()
While 1
        MsgBox(0,"2","2")
        Sleep(3000)
        WEnd
EndFunc

Func Form1Close()
Exit
EndFunc
还是按完第一个按钮后就不能用第二个按钮
也不能用右上角的叉来关闭
请你运行上面的代码试试
发表于 2009-7-14 01:56:47 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("窗体1", 322, 130, 830, 320)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Button1 = GUICtrlCreateButton("Button1", 56, 24, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("Button2", 200, 40, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)

While 1
        Sleep(100)
WEnd

Func Button1Click()
        MsgBox(0,"1","1")
EndFunc

Func Button2Click()
        MsgBox(0,"2","2")
EndFunc

Func Form1Close()
Exit
EndFunc
看看这个是不是你想要的效果
 楼主| 发表于 2009-7-14 11:44:52 | 显示全部楼层
首先谢谢楼上的帮忙
也许我真没表达清楚
Func Button1Click()

        MsgBox(0,"1","1")

EndFunc
这样只是跳一个提示吧
我想要的效果是当只按下button1click时
反复的执行MsgBox(0,"1","1")
当按下button2click时
反复的执行MsgBox(0,"2","2")
即终止了MsgBox(0,"1","1")的执行
所以加这个
while 1
wend
才能循环
现在遇到的是程序会一直循环在第一次按下的命令上
发表于 2009-9-23 14:14:24 | 显示全部楼层
我也想知道怎么做,大侠说一下啊!
发表于 2009-11-9 09:12:34 | 显示全部楼层
#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 292, 102, 832, 578)

$Button1 = GUICtrlCreateButton("1", 24, 24, 97, 41, $WS_GROUP)

$Button2 = GUICtrlCreateButton("2", 144, 24, 113, 41, $WS_GROUP)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###



While 1

        $nMsg = GUIGetMsg()

        Switch $nMsg

                Case $GUI_EVENT_CLOSE

                        Exit

                Case $Button1

                        a()

                Case $Button2

                        b()

        EndSwitch

WEnd





Func a()

        While 1
              if GUIGetMsg() = $Button2 then b()
                Sleep(1000)

        WEnd

EndFunc



Func b()

        While 1

                Sleep(1000)

        WEnd

EndFunc
发表于 2009-12-23 22:54:39 | 显示全部楼层
都没解决这个问题,怎么就关了呢?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-26 11:06 , Processed in 0.080762 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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