musy 发表于 2011-7-2 15:48:11

在执行一个死循环期间如何响应托盘的点击事件?

程序开始时要执行一个死循环去监视某个窗口是否存在,但我又想在执行监视循环期间能响应托盘的点击事件,是否要用到多线程才行?

chenronting 发表于 2011-7-2 21:36:43

如果是这样, 为何不注册一个AdlibRegister 函数来帮你呢,这个可不会死循环;
当然,是看你的用法!下面是我的想法:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $winexists=0

AdlibRegister('_winexists',500)
AdlibRegister('_openthenotepad',3000)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

Func _WinExists()
        If WinExists('无标题 - 记事本') Then
                $winexists=1
                MsgBox(64,'提示','现在窗口出现了,你可以使用变量 winexists 传递消息')
                AdlibUnRegister('_winexists')
                AdlibUnRegister('_openthenotepad')
                WinClose('无标题 - 记事本')
        EndIf
EndFunc

Func _openthenotepad()
        Run('notepad.exe')
EndFunc
页: [1]
查看完整版本: 在执行一个死循环期间如何响应托盘的点击事件?