找回密码
 加入
搜索
查看: 3353|回复: 1

[GUI管理] 请教两个问题,GUI界面中添加倒计时 & 求助下如何检测多个Radio中被选中的是哪个

[复制链接]
发表于 2014-1-20 17:27:07 | 显示全部楼层 |阅读模式
本帖最后由 yunnl 于 2014-1-20 17:29 编辑

想做一个检测网络是否通畅的小程序
ping第一次以后,如何在gui空间中实现显示下一次ping的时间?
以下是我的代码,但是GUI无法监听事件
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$hGUI2 = GUICreate("正在监测", 469, 239, -1, -1)
$P_Label1 = GUICtrlCreateLabel("正在监听网络", 32, 40, 404, 49)
GUICtrlSetFont ($P_Label1, 30  , 600  , -1  , "微软雅黑"   )
$P_Button1 = GUICtrlCreateButton("立即关机", 24, 176, 193, 41)
$P_Button2 = GUICtrlCreateButton("停止并退出程序", 232, 176, 217, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $P_Button1

                Case $P_Button2
                        Exit

        EndSwitch
_A()
WEnd
Func _A()
        GUICtrlSetData($P_Label1,"3")
        Sleep(1000)
        GUICtrlSetData($P_Label1,"2")
        Sleep(1000)
        GUICtrlSetData($P_Label1,"1")
        Sleep(1000)
        GUICtrlSetData($P_Label1,"0")
        MsgBox(0,0,0)
EndFunc



另外关于Radio的问题,我用的代码是
 If BitAND(GUICtrlRead($Radio1),$GUI_CHECKED) Then
         执行语句
 ElseIf BitAND(GUICtrlRead($Radio2),$GUI_CHECKED) Then
         执行语句
 ElseIf BitAND(GUICtrlRead($Radio3),$GUI_CHECKED) Then
         执行语句
 ElseIf BitAND(GUICtrlRead($Radio4),$GUI_CHECKED) Then
         执行语句

感觉如果Radio很多的话,这样的效率会很低,求各位指导一下
发表于 2014-1-20 21:05:23 | 显示全部楼层
回复 1# yunnl


第一个问题:倒计时论坛很多示例,搜一下就有,这里有几个:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
 
Global $time = 30
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("倒计时测试窗口", 350, 172, 193, 125)
$Label1 = GUICtrlCreateLabel("30秒后将进入主程序!", 56, 32, 232, 28)
GUICtrlSetFont(-1, 18, 400, 0, "楷体_GB2312")
$Progress1 = GUICtrlCreateProgress(8, 88, 333, 17)
$Button1 = GUICtrlCreateButton("确定(&Y)", 53, 128, 73, 25, 0)
$Button2 = GUICtrlCreateButton("退出(&X)", 210, 128, 73, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibEnable("_timer", 1000)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE, $Button2
                        Exit
                Case $Button1
                        ExitLoop
        EndSwitch
        If $time <= 0 Then ExitLoop
WEnd
main()
Exit
 
Func _timer()
        $time -= 1
        GUICtrlSetData($Label1, $time & "秒后将进入主程序!")
        GUICtrlSetData($Progress1, (30 - $time) / 0.3)
        If $time <= 0 Then AdlibDisable()
EndFunc   ;==>_timer
 
Func main()
        MsgBox(0, 'test', '倒计时结束,进入主程序.', 10)
        ;以下为主程序
EndFunc   ;==>main
Global $time = 5
$Form1 = GUICreate("Form1", 297, 122, 192, 124)
$Button1 = GUICtrlCreateButton("倒计时(5秒)", 80, 72, 129, 33)
GUISetState(@SW_SHOW)
AdlibRegister("_timer", 1000)
While 1
        Switch GUIGetMsg()
                Case - 3,$Button1
                                                Exit
        EndSwitch
WEnd
Func _timer()
        $time -= 1
       GUICtrlSetData($Button1, "倒计时("&$time&")秒" )
        If $time <= 0 Then Exit
EndFunc   ;==>_timer
$Form1 = GUICreate("Form1", 297, 122, 192, 124)
$Button1 = GUICtrlCreateButton("倒计时(5秒)", 80, 72, 129, 33)
GUISetState(@SW_SHOW)
Global $timeA=5
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer))
While 1
        Switch GUIGetMsg()
                Case - 3,$Button1
                                                Exit
        EndSwitch
WEnd
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
        If $idEvent = $TimerDLL[0] Then
                        $timeA-=1
                GUICtrlSetData($Button1, "倒计时("&$timeA&"秒)"  )
                                If $timeA=0 Then Exit
        EndIf
EndFunc
第二个问题:http://www.autoitx.com/thread-39892-1-1.html
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 04:14 , Processed in 0.075857 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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