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

[GUI管理] 如何从循环中跳出?

 火.. [复制链接]
发表于 2011-9-8 20:37:43 | 显示全部楼层 |阅读模式
#include <GUIConstantsEx.au3>


    $main=GUICreate("main",600,400,-1,-1)
    $text =GUICtrlCreateLabel("hello,world",0,200)
    GUISetState(@SW_SHOW) ; 
      While 1
                
        $msg = GUIGetMsg()
                For $i=0 To 600 Step 20
                        Sleep(500)
                        ControlMove( $main,"",3,$i,200)
                        ;ExitLoop
                            If $msg = $GUI_EVENT_CLOSE Then ExitLoop
                        Next
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
上述代码如何能实现关闭窗口?
好像循环中出不来了,求指点
发表于 2011-9-8 20:48:09 | 显示全部楼层
回复 1# pdp320921


    别用两 层循环,只用一个就够了,你的是在第二重循环里出不来了。因为没有机会回到第一循环里给$msg赋新值,所以你在for循环里的If $msg = $GUI_EVENT_CLOSE Then ExitLoop根本没有用。
 楼主| 发表于 2011-9-8 20:55:45 | 显示全部楼层
感谢回复,道理我懂,可如何只用修改呢?
发表于 2011-9-8 20:59:49 | 显示全部楼层
本帖最后由 happytc 于 2011-9-8 21:02 编辑

回复 3# pdp320921

其实象这种要在死循环里跳出来,最好用一些au3提供的中断函数来做。


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$main = GUICreate("main", 600, 400, -1, -1)
$text = GUICtrlCreateLabel("hello,world", 0, 200)
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
GUISetState(@SW_SHOW) ;
_HelloWorld()

Func _HelloWorld()
        For $i = 0 To 600 Step 20
                Sleep(500)
                ControlMove($main, "", 3, $i, 200)
        Next
EndFunc


Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
        Local Const $SC_CLOSE = 0xF060

        If $hWnd == $main Then
                Switch BitAND($wParam, 0xFFF0)
                        Case $SC_CLOSE
                                Exit
                EndSwitch
        EndIf

        Return $GUI_RUNDEFMSG
EndFunc
发表于 2011-9-8 21:05:42 | 显示全部楼层
#include <GUIConstantsEx.au3>





    $main=GUICreate("main",600,400,-1,-1)

    $text =GUICtrlCreateLabel("hello,world",0,200)

    GUISetState(@SW_SHOW) ; 
    $i = 0
        $flag = 1
      While 1

                

        $msg = GUIGetMsg()
                If $msg = $GUI_EVENT_CLOSE Then ExitLoop
                If $flag = 1 Then

                     sleep(500)

                     ControlMove( $main,"",3,$i,200)

                     $i = $i + 20 
                                        If $i > 600 Then $flag = 0
                                EndIf
        

    WEnd
一个循环了,怎么还是出不来啊?郁闷
发表于 2011-9-8 21:08:37 | 显示全部楼层
本帖最后由 xms77 于 2011-9-8 21:10 编辑

回复 4# happytc
果然是高人啊,我用了一个循环还是不能及时出来啊!看了你的中断函数,没有明白什么意思,不懂,呵呵!
发表于 2011-9-8 21:16:05 | 显示全部楼层
回复 5# xms77


    其实你这个是可以跳出来的,只是不灵敏而已,原因就是sleep(500)了,可以改一下为下面的:

#include <GUIConstantsEx.au3>

$main = GUICreate("main", 600, 400, -1, -1)
$text = GUICtrlCreateLabel("hello,world", 0, 200)

GUISetState(@SW_SHOW) ;
$i = 0
$flag = 0
While 1
        $msg = GUIGetMsg()
        If $msg == $GUI_EVENT_CLOSE Then ExitLoop
        $flag += 1
        If 50 == $flag  Then
                ControlMove($main, "", 3, $i, 200)
                $i = $i + 20
                If $i > 600 Then Exit
                $flag = 0
        EndIf
        Sleep(10)
WEnd
 楼主| 发表于 2011-9-8 21:16:18 | 显示全部楼层
回复 4# happytc
0xF060代表什么?
     $GUI_Rundefmsg在哪可查?  
发表于 2011-9-8 21:16:37 | 显示全部楼层

#include <GUIConstantsEx.au3>





    $main=GUICreate("main",600,400,-1,-1)

    $text =GUICtrlCreateLabel("hello,world",0,200)

    GUISetState(@SW_SHOW) ; 
    $i = 0
        $flag = 1
      While 1

                

        $msg = GUIGetMsg()
                If $msg = $GUI_EVENT_CLOSE Then ExitLoop
                If $flag = 1 Then

                     sleep(500)

                     ControlMove( $main,"",3,$i,200)

                     $i = $i + 20  
                                        If $i > 600 Then ExitLoop   ;  ExitLoop 跳出循
                                EndIf
        

    WEnd
        
        MsgBox(0,0,"跳出循环")
发表于 2011-9-8 21:33:18 | 显示全部楼层
本帖最后由 xms77 于 2011-9-8 21:35 编辑

回复 7# happytc
我看楼主的意思好像不是在move完成后退出窗口,所以加了$flag,不让窗口关闭,只能通过X来关闭窗口,只是在Move过程中如果点击X不能及时关闭窗体。
弱弱地问一下,If 50 == $flag, 这个==是什么意思?菜鸟不明白,别笑我!
发表于 2011-9-8 21:40:14 | 显示全部楼层
回复 8# pdp320921


    不是很清楚嘛,0xF060就是消息SC_CLOSE的值呀
我不知道这个常量在au3的那个*Constants.au3里,所以直接写值了
可以在微软网上查到:http://msdn.microsoft.com/en-us/library/ms646360(v=vs.85).aspx
觉得au3的常量定义的文件有点乱,经常要猜一个常量可能在那个文件里

$GUI_Rundefmsg这个是返回au3内部句柄消息。
发表于 2011-9-8 21:41:40 | 显示全部楼层
回复 10# xms77

比较符呀,跟‘>’,‘<’等一样呀
发表于 2011-9-8 21:45:58 | 显示全部楼层
回复 12# happytc
为什么不是用“=”,而用“==”呢?
发表于 2011-9-8 21:51:11 | 显示全部楼层
回复 13# xms77


    本来==才是比较符,而=是赋值符。au3为了降低学难度,把=既当比较符,又当赋值符。

在if语句中用==比用=效率要高。
发表于 2011-9-8 22:00:06 | 显示全部楼层
回复 14# happytc
谢谢,总算明白了!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-11 15:17 , Processed in 0.084374 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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