找回密码
 加入
搜索
查看: 4410|回复: 6

[GUI管理] 那位大神能帮我解答一下这段代码,本人不是很懂。能够详细点么。谢谢

  [复制链接]
发表于 2016-1-11 09:56:21 | 显示全部楼层 |阅读模式
悬赏2金钱未解决
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
Global $s = 5
$Form1 = GUICreate("Form1", 297, 122, 192, 124)
$Button1 = GUICtrlCreateButton("倒计时(" & $s & "秒)", 80, 72, 129, 33)
GUISetState(@SW_SHOW)
$Timer = DllCallbackRegister("_daojishi", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer))
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE, $Button1
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL[0])
                        Exit
 
        EndSwitch
WEnd
 
Func _daojishi($hWnd, $uiMsg, $Form1_idEvent, $dwTime)
        If $s < 1 Then
                GUICtrlSetData($Button1, "退出")
                Exit
        EndIf
        $s -= 1
        GUICtrlSetData($Button1, "倒计时(" & $s & "秒)")
EndFunc   ;==>_daojishi

评分

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

查看全部评分

 楼主| 发表于 2016-1-11 09:57:29 | 显示全部楼层
这是别人的代码。我看得不怎么懂。本人是菜鸟,希望大神能帮我解答一下。希望能详细点。谢谢啦
发表于 2016-1-11 14:49:01 | 显示全部楼层
弹出对话框无操作5秒自动退出
发表于 2016-1-12 13:22:56 | 显示全部楼层
我只能看懂这些了
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 ;定义全局变量
Global $s = 5
;创建GUI界面
$Form1 = GUICreate("Form1", 297, 122, 192, 124)
;创建按钮
$Button1 = GUICtrlCreateButton("倒计时(" & $s & "秒)", 80, 72, 129, 33)
;显现界面
GUISetState(@SW_SHOW)
;定义回调函数
$Timer = DllCallbackRegister("_daojishi", "int", "hwnd;uint;uint;dword")
;调用user32.dll里的SetTimer函数,1000毫秒回调到自定义函数
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer))
;生成无限循环
While 1
;        定义变量值为捕获窗口消息
        $nMsg = GUIGetMsg()
                ;创建条件$nMsg语句
        Switch $nMsg
                        ;如果满足$GUI_EVENT_CLOSE(点击关闭按钮), $Button1(点击按钮)
                        Case $GUI_EVENT_CLOSE, $Button1
                                       ;执行KillTimer函数
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL[0])
                                                ;退出
                        Exit
        ; 条件句结束语
         EndSwitch
;while循环句结束
WEnd
;自定义函数
Func _daojishi($hWnd, $uiMsg, $Form1_idEvent, $dwTime)
           ;如果 $s<1 那么
        If $s < 1 Then
                           ;刷新按钮文本为'退出'
                GUICtrlSetData($Button1, "退出")
                                ;退出
                Exit
                ;结束if语句                
        EndIf
                ;变量$s在经过1000毫秒后执行自身减1,既$s=$s-1
        $s -= 1
                ;刷新按钮文本为 "倒计时"加自身减1后的值
        GUICtrlSetData($Button1, "倒计时(" & $s & "秒)")
;自定义函数结束语                
EndFunc   ;==>_daojishi
发表于 2016-2-4 16:07:31 | 显示全部楼层
caicaicaicaijj 高手已经解读得很清楚了.
里面的精华是
DllCallbackRegister-- 创建自定义 DLL 回调函数.
DllCall   调用 DLL 文件中的函数.也就是调用强大的WINDOWS API函数.
把以上弄清楚了,WINDOWS API编程也就所向披靡了.也就不会觉得AUTOIT的函数不够用了.

顺便帖上SetTimer函数的原型
UINT_PTR SetTimer(
HWND hWnd, // 窗口句柄
UINT_PTR nIDEvent, // 定时器ID,多个定时器时,可以通过该ID判断是哪个定时器
UINT nElapse, // 时间间隔,单位为毫秒
TIMERPROC lpTimerFunc // 回调函数
);
返回值:
类型:UINT_PTR
如果函数成功,hWnd参数为0,则返回新建立的时钟编号,可以把这个时钟编号传递给KillTimer来销毁时钟.
发表于 2016-3-4 20:28:49 | 显示全部楼层
api的门外汉学习了。
发表于 2016-3-15 08:56:20 | 显示全部楼层
不明觉厉啊
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 06:11 , Processed in 0.078206 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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