找回密码
 加入
搜索
查看: 11269|回复: 24

[GUI管理] 怎么不用热键而用一个按钮终止一个循环?[已解决]

 火.. [复制链接]
发表于 2010-3-2 19:57:34 | 显示全部楼层 |阅读模式
本帖最后由 haorui658 于 2010-3-7 13:56 编辑

Start按钮的开始的循环怎么用Stop按钮终止呢?我知道热键可以,但是按钮可以吗?
#include <GUIConstants.au3>
$var = 1
$pause=False
$Mail = GUICreate("邮件发送", 450, 500) 
$Group1 = GUICtrlCreateGroup("基本配置", 8, 8, 330, 300)
$SmtpServer_Label = GUICtrlCreateLabel("SMTP服务器", 20,  40, 80, 20) 
$UP_Label = GUICtrlCreateLabel ("用户名/密码", 20,  70, 80, 20)
$FromAddress_Label = GUICtrlCreateLabel ("From", 20,  100, 80, 20) 
$To_Label = GUICtrlCreateLabel ("To", 20,  130, 80, 20) 
$Subject_Label = GUICtrlCreateLabel ("标题", 20,  160, 80, 20)
$Body_Label = GUICtrlCreateLabel ("正文", 20,  190, 80, 20)
$Start_Label = GUICtrlCreateLabel ("起始", 20,  360, 80, 20)
$Start_Label = GUICtrlCreateLabel ("数量", 80,  360, 80, 20)

$SMTP = GUICtrlCreateInput ("", 100,  40, 220, 20) 
$Username = GUICtrlCreateInput ("", 100, 70, 100, 20)
$Password= GUICtrlCreateInput ("", 220, 70, 100, 20,0x0020 )
$From= GUICtrlCreateInput("", 100, 100, 220, 20)
$To =GUICtrlCreateInput("", 100,  130, 220, 20) 
$Subject =GUICtrlCreateInput("subject", 100,  160, 220, 20) 
$Body = GUICtrlCreateEdit("Mail Body", 100,  190, 220, 100)


$Start = GUICtrlCreateButton("Start", 340, 200, 70)
$Stop = GUICtrlCreateButton("Stop", 340, 280, 70)

GUISetState(@SW_SHOW) 
        
While 1
  $msg = GUIGetMsg()

  Select
  Case $msg = $Start
          While($var <= 2000 )
                                   MsgBox(0,"","Send")
                                   ;sendmail ()
                                   $var = $var + 1
                                   if $pause=true then exitloop 
                          Sleep(500)
                  WEnd
        Case $msg = $Stop
            $pause=true                  
                Case $msg = $GUI_EVENT_CLOSE 
                                 Exit
        EndSelect
WEnd 

Func sendmail ()
        ;.....发送邮件
EndFunc

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-3-2 20:03:04 | 显示全部楼层
 楼主| 发表于 2010-3-2 20:25:19 | 显示全部楼层
回复 2# afan


    我把代码改了,依旧不行,可能我邯郸学步了,望指正
 While($var <= 2000 )
        $nMsg1 = GUIGetMsg()
                        If $nMsg1 = $Stop then Exit
                MsgBox(0,"","Send")
                sendmail ()
                var = $var + 1                                    
WEnd
发表于 2010-3-2 20:27:18 | 显示全部楼层
要达到你的目的得用AdlibRegister
发表于 2010-3-2 20:33:59 | 显示全部楼层
回复 3# haorui658


    这里不要用 Msgbox() 调试,会间接影响 GUIGetMsg()
发表于 2010-3-2 21:15:18 | 显示全部楼层
本帖最后由 ddx13 于 2010-3-2 21:16 编辑

晕,看错题目。
 楼主| 发表于 2010-3-2 21:18:51 | 显示全部楼层
回复 5# afan


    但是去掉MSgbox问题依旧,用AdlibRegister怎么解决呢?
发表于 2010-3-2 21:27:31 | 显示全部楼层
本帖最后由 llztt 于 2010-3-2 21:56 编辑

我去试试写个例子
发表于 2010-3-2 22:07:18 | 显示全部楼层
本帖最后由 C.L 于 2010-3-2 22:09 编辑

回复 1# haorui658

可以,帮你改下代码,另外,你在循环内用太大的sleep会很影响响应,也改了一下,为了显示效果,按钮加了颜色区分,代码如下:
#include <GUIConstants.au3>

Opt ("GUIOnEventMode",1)

$var = 1
$pause=False
$Mail = GUICreate("邮件发送", 450, 500) 
GUISetOnEvent ($GUI_EVENT_CLOSE,"_exit")
$Group1 = GUICtrlCreateGroup("基本配置", 8, 8, 330, 300)
$SmtpServer_Label = GUICtrlCreateLabel("SMTP服务器", 20,  40, 80, 20) 
$UP_Label = GUICtrlCreateLabel ("用户名/密码", 20,  70, 80, 20)
$FromAddress_Label = GUICtrlCreateLabel ("From", 20,  100, 80, 20) 
$To_Label = GUICtrlCreateLabel ("To", 20,  130, 80, 20) 
$Subject_Label = GUICtrlCreateLabel ("标题", 20,  160, 80, 20)
$Body_Label = GUICtrlCreateLabel ("正文", 20,  190, 80, 20)
$Start_Label = GUICtrlCreateLabel ("起始", 20,  360, 80, 20)
$Start_Label = GUICtrlCreateLabel ("数量", 80,  360, 80, 20)

$SMTP = GUICtrlCreateInput ("", 100,  40, 220, 20) 
$Username = GUICtrlCreateInput ("", 100, 70, 100, 20)
$Password= GUICtrlCreateInput ("", 220, 70, 100, 20,0x0020 )
$From= GUICtrlCreateInput("", 100, 100, 220, 20)
$To =GUICtrlCreateInput("", 100,  130, 220, 20) 
$Subject =GUICtrlCreateInput("subject", 100,  160, 220, 20) 
$Body = GUICtrlCreateEdit("Mail Body", 100,  190, 220, 100)

$Start = GUICtrlCreateButton("Start", 340, 200, 70)
GUICtrlSetOnEvent (-1,"_start")
$Stop = GUICtrlCreateButton("Stop", 340, 280, 70)

GUISetState(@SW_SHOW) 
        
While 1
 Sleep (1000)
WEnd

Func _exit ()
        Exit
EndFunc

Func _start ()
        $time = TimerInit ()
        While Int(TimerDiff ($time)/1000) <= 1000
                 Opt ("GUIOnEventMode",0)
                 ToolTip ("Send")
                ;sendmail ()
                If $pause == True Then
                        GUICtrlSetBkColor ($stop,0xff0000)
                Else
                        GUICtrlSetBkColor ($stop,0x00ff00)
                EndIf
                $msg = GUIGetMsg()
                if $pause=true then 
                        $pause = Not $pause
                        Opt ("GUIOnEventMode",1)
                        exitloop 
                EndIf
                
                Switch $msg
                        Case $Stop                                
                                $pause = Not $pause
                EndSwitch
        WEnd
EndFunc

Func sendmail ()

        ;.....发送邮件

EndFunc

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-3-2 22:17:09 | 显示全部楼层
仍用消息循环的例子,LZ根据实际情况看着办吧
#include <GUIConstants.au3>
$var = 1
$pause = False
$Mail = GUICreate("邮件发送", 450, 500)
$Group1 = GUICtrlCreateGroup("基本配置", 8, 8, 330, 300)
$SmtpServer_Label = GUICtrlCreateLabel("SMTP服务器", 20, 40, 80, 20)
$UP_Label = GUICtrlCreateLabel("用户名/密码", 20, 70, 80, 20)
$FromAddress_Label = GUICtrlCreateLabel("From", 20, 100, 80, 20)
$To_Label = GUICtrlCreateLabel("To", 20, 130, 80, 20)
$Subject_Label = GUICtrlCreateLabel("标题", 20, 160, 80, 20)
$Body_Label = GUICtrlCreateLabel("正文", 20, 190, 80, 20)
$Start_Label = GUICtrlCreateLabel("起始", 20, 360, 80, 20)
$Start_Label = GUICtrlCreateLabel("数量", 80, 360, 80, 20)
$Label = GUICtrlCreateLabel("准备", 80, 400, 80, 20)
$SMTP = GUICtrlCreateInput("", 100, 40, 220, 20)
$Username = GUICtrlCreateInput("", 100, 70, 100, 20)
$Password = GUICtrlCreateInput("", 220, 70, 100, 20, 0x0020)
$From = GUICtrlCreateInput("", 100, 100, 220, 20)
$To = GUICtrlCreateInput("", 100, 130, 220, 20)
$Subject = GUICtrlCreateInput("subject", 100, 160, 220, 20)
$Body = GUICtrlCreateEdit("Mail Body", 100, 190, 220, 100)


$Start = GUICtrlCreateButton("Start", 340, 200, 70)
$Stop = GUICtrlCreateButton("Stop", 340, 280, 70)

GUISetState(@SW_SHOW)

While 1
        $msg = GUIGetMsg()

        Select
                Case $msg = $Start
                        $var = 1
                        While ($var <= 2000)
                                $nMsg = GUIGetMsg()
                                If $nMsg = $Stop Then ExitLoop (MsgBox(0, 0, 'Stop'))
                                GUICtrlSetData($Label, 'Send' & $var)
                                sendmail()
                                $var += 1
                        WEnd

                Case $msg = $GUI_EVENT_CLOSE
                        Exit
        EndSelect
WEnd

Func sendmail()
        Sleep(50)
        ;.....发送邮件
EndFunc   ;==>sendmail
 楼主| 发表于 2010-3-2 22:49:19 | 显示全部楼层
十分感谢C.L和afan,受教了
 楼主| 发表于 2010-3-2 23:18:58 | 显示全部楼层
本帖最后由 haorui658 于 2010-3-2 23:30 编辑

当afan的send程序中sleep时间为50ms时还可以,但是要是1000ms或者更长的间隔时间的话就不行了?汗 问题有点多
发表于 2010-3-3 08:24:16 | 显示全部楼层
本帖最后由 netegg 于 2010-3-3 08:54 编辑

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
。。。
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
        #forceref $hWnd, $Msg
        Local $nNotifyCode = BitShift($wParam, 16)
        Local $hCtrl = $lParam
       
        Switch $hCtrl
                Case $btn, $Stop
                        Switch $nNotifyCode
                                Case $BN_CLICKED
                                     exit
                        endswitch
                        Return 0
        EndSwitch
        Return $GUI_RUNDEFMSG
endfunc
只是做个参考,结合你的程序自己改吧

评分

参与人数 1金钱 +10 收起 理由
afan + 10

查看全部评分

发表于 2010-3-3 15:23:45 | 显示全部楼层
用LS蛋蛋说的注册系统消息的方法也不错,LZ可以试试,应该可以解决 sleep N长造成的 GUIGetMsg() 不响应的问题
 楼主| 发表于 2010-3-3 17:57:48 | 显示全部楼层
好的 我有时间试试 恩 一个小帖子让我受益匪浅啊
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-16 15:14 , Processed in 0.105356 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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