找回密码
 加入
搜索
查看: 1838|回复: 5

[GUI管理] [已解决]右键菜单会暂停AdlibRegister吗

[复制链接]
发表于 2016-8-14 12:41:41 | 显示全部楼层 |阅读模式
本帖最后由 qqwwqqwww 于 2016-8-15 19:52 编辑

我用AdlibRegister设了个一秒一次的函数,点开了右键菜单,这个函数就不执行了
<p>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$Form1 = GUICreate("form")
$ProgressText = GUICtrlCreateLabel("", 10, 10, 140, 40)

;添加上下文菜单(右键)
$ContextMenu  = GUICtrlCreateContextMenu()
$Exit = GUICtrlCreateMenuItem("退出", $ContextMenu)

GUISetState(@SW_SHOW)
AdlibRegister("timer",1000)
$Time=50
While $Time>0
        Switch GUIGetMsg()
                Case $Exit,  $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
        GUICtrlSetData($ProgressText, StringFormat("%02d",Floor($Time/60)) &":"& StringFormat("%02d",Mod($Time,60)))
WEnd
GUIDelete($Form1)
Exit

Func timer()
        $Time-=1
        ;GUICtrlSetData($ProgressText, StringFormat("%02d",Floor($Time/60)) &":"& StringFormat("%02d",Mod($Time,60)))
EndFunc
我解决了,虽然用的笨办法。可以正常计时,但是右键菜单出来还是不会刷新界面
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$Form1 = GUICreate("form")
$ProgressText = GUICtrlCreateLabel("", 10, 10, 140, 40)
Global $TimeStamp

;添加上下文菜单(右键)
$ContextMenu  = GUICtrlCreateContextMenu()
$Exit = GUICtrlCreateMenuItem("退出", $ContextMenu)

GUISetState(@SW_SHOW)
$TimeStamp = TimerInit()
AdlibRegister("timer",1000)
$Time=50
While TimerDiff($TimeStamp)/1000<$Time
        Switch GUIGetMsg()
                Case $Exit,  $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd
GUIDelete($Form1)
Exit

Func timer()
        Local $t = Floor(TimerDiff($TimeStamp)/1000)
        GUICtrlSetData($ProgressText, StringFormat("%02d",Floor(($Time-$t)/60)) &":"& StringFormat("%02d",Mod($Time-$t,60)))
EndFunc
发表于 2016-8-14 18:23:59 | 显示全部楼层
本帖最后由 chamlien 于 2016-8-14 18:25 编辑

回复 1# qqwwqqwww


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


$Form1 = GUICreate("form")
$ProgressText = GUICtrlCreateLabel("", 10, 10, 140, 40)

;添加上下文菜单(右键)
$ContextMenu = GUICtrlCreateContextMenu()
$Exit = GUICtrlCreateMenuItem("退出", $ContextMenu)

GUISetState(@SW_SHOW)
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer))

$Time = 50
While $Time > 0
        Switch GUIGetMsg()
                Case $Exit, $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
        GUICtrlSetData($ProgressText, StringFormat("%02d",Floor($Time/60)) &":"& StringFormat("%02d",Mod($Time,60)))
WEnd
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL)
DllCallbackFree($Timer)
GUIDelete($Form1)
Exit

Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
        If $idEvent = $TimerDLL[0] Then $Time -= 1
EndFunc   ;==>Timer


上面代码右键点击后,计时不会停止,但是数字刷新会暂停,要解决这个问题,用Opt("GUIOnEventMode", 1)模式
发表于 2016-8-14 21:18:04 | 显示全部楼层
回复  qqwwqqwww



上面代码右键点击后,计时不会停止,但是数字刷新会暂停,要解决这个问题,用Opt( ...
chamlien 发表于 2016-8-14 18:23



    第22行移到第30行下面
发表于 2016-8-14 22:26:18 | 显示全部楼层
回复 3# afan


    嗯嗯,确实,一时糊涂了
 楼主| 发表于 2016-8-15 19:44:57 | 显示全部楼层
本帖最后由 qqwwqqwww 于 2016-8-15 19:46 编辑

谢谢chamlien、afan,我自己用了别的思路解决了。虽然右击会停掉,但是还是实现计时的功能了。
为什么我的代码没高亮呢,奇怪
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$Form1 = GUICreate("form")
$ProgressText = GUICtrlCreateLabel("", 10, 10, 140, 40)
Global $TimeStamp

;添加上下文菜单(右键)
$ContextMenu  = GUICtrlCreateContextMenu()
$Exit = GUICtrlCreateMenuItem("退出", $ContextMenu)

GUISetState(@SW_SHOW)
$TimeStamp = TimerInit()
AdlibRegister("timer",1000)
$Time=50
While TimerDiff($TimeStamp)/1000<$Time
        Switch GUIGetMsg()
                Case $Exit,  $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd
GUIDelete($Form1)
Exit

Func timer()
        Local $t = Floor(TimerDiff($TimeStamp)/1000)
        GUICtrlSetData($ProgressText, StringFormat("%02d",Floor(($Time-$t)/60)) &":"& StringFormat("%02d",Mod($Time-$t,60)))
EndFunc
 楼主| 发表于 2016-8-15 19:47:52 | 显示全部楼层
回复 2# chamlien


    winapi有什么地方可以查吗?想找个API的列表,就像这个SetTimer,不说都不知道有这个函数
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-15 03:04 , Processed in 0.084290 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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