找回密码
 加入
搜索
楼主: zzmxd

[效率算法] while和Func如何共存?

 火.. [复制链接]
 楼主| 发表于 2012-9-2 07:15:01 | 显示全部楼层
回复 15# annybaby
嗯没错,的确是这样,有什么办法能解决?
发表于 2012-9-2 11:59:21 | 显示全部楼层
回复 16# zzmxd
把你完整的代码发上来~
 楼主| 发表于 2012-9-2 12:17:00 | 显示全部楼层
回复 17# annybaby
#NoTrayIcon
#include <Constants.au3> ; Required for the $TRAY_EVENT_PRIMARYDOUBLE and $TRAY_EVENT_SECONDARYUP constants.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)
Local $prefsitem1        = TrayCreateItem("显示")
Local $prefsitem2        = TrayCreateItem("隐藏")
TrayCreateItem("")
Local $aboutitem        = TrayCreateItem("关于")
TrayCreateItem("")
Local $exititem        = TrayCreateItem("退出")

TraySetState()
TraySetClick (8)
$Form1_1 = GUICreate("123", 523, 222, 192, 176)
$Button1 = GUICtrlCreateButton("高", 24, 24, 113, 57)
$Button2 = GUICtrlCreateButton("高于标准", 144, 24, 113, 57)
$Button3 = GUICtrlCreateButton("标准", 264, 24, 113, 57)
$Button4 = GUICtrlCreateButton("低于标准", 384, 24, 113, 57)
$Button5 = GUICtrlCreateButton("暂停", 416, 136, 89, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Local $msg = TrayGetMsg()
        Local $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_MINIMIZE
                        GUISetState(@SW_HIDE)
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button2
                        Local $i = 0
            Do
              ProcessSetPriority ( "1.exe", 3 )
                          Sleep (1000)
              $i = $i + 1
                        Until $i = 10
                                

        EndSwitch
        Select
                Case $msg = 0
                        ContinueLoop
                Case $msg = $prefsitem1
                        GUISetState(@SW_SHOWNORMAL)
                        Case $msg = $prefsitem2
                        GUISetState(@SW_HIDE)
                Case $msg = $aboutitem
                        MsgBox(64, "关于:", "http://www.autoitx.com/")
                Case $msg = $exititem
                        ExitLoop
        EndSelect
        
WEnd

TraySetState()
Example()

Func Example()

    TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TrayEvent")
    TraySetState(1) ; Show the tray menu.

    While 1
        Sleep(100)  ; 空闲循环
    WEnd
EndFunc   ;==>Example

Func TrayEvent()
    Switch @TRAY_ID ; Check the last tray item identifier.
        Case $TRAY_EVENT_PRIMARYDOUBLE
            ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
            MsgBox(4096, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
                    "Version: " & @AutoItVersion & @CRLF & _
                    "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "", 0, -1) - 1)) ; Find the folder of a full path.

    EndSwitch
EndFunc   ;==>TrayEvent


Func ExitScript()
    Exit
EndFunc   
发表于 2012-9-2 12:35:51 | 显示全部楼层
本帖最后由 netegg 于 2012-9-2 12:43 编辑

"TrayOnEventMode"   vs   TrayGetMsg()?
#NoTrayIcon vs tray-mode?
lz, 跟你说了,好好看看帮助吧
 楼主| 发表于 2012-9-2 13:31:01 | 显示全部楼层
回复 19# netegg

话说,我是在帮助文件里找到几个例子拼在一起修改而成的
发表于 2012-9-2 13:33:53 | 显示全部楼层
回复 20# zzmxd
就算是拼,好歹也要知道例子的每个语句到底是什么意思呀,象这么拼没用的
发表于 2012-9-2 13:45:24 | 显示全部楼层
回复 18# zzmxd

只能说代码完全没有逻辑性可言。

烦请楼主说明一下,到底什么时候会执行60-61行的代码。
发表于 2012-9-2 13:58:55 | 显示全部楼层
回复 20# zzmxd


    怪不得如此混乱~~

你主要的问题是无法同时响应GUI窗口和托盘菜单的命令吧??
我也另外帮你拼凑了个,你依样画葫芦吧~~

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt('TrayOnEventMode', 1)
Opt('traymenumode', 3)
$Form1 = GUICreate("GUI_Tray", 200, 100, 190, 120, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Button1 = GUICtrlCreateButton("Click me!", 24, 16, 153, 57)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
$test = TrayCreateItem('test!')
TrayItemSetOnEvent(-1, '_Tray')
$exit = TrayCreateItem('exit')
TrayItemSetOnEvent(-1, '_Tray')
While 1
        Sleep(1000000)
WEnd

Func Button1Click()
        MsgBox(0x40000, 0, 'GUI消息响应!')
EndFunc   ;==>Button1Click

Func Form1Close()
        MsgBox(0x40000, 0, 'GUI窗口关闭退出', 3)
        Exit
EndFunc   ;==>Form1Close

Func _Tray()
        Switch @TRAY_ID
                Case $test
                        MsgBox(0x40000, 0, '托盘事件响应!')
                Case $exit
                        MsgBox(0x40000, 0, '托盘菜单退出!', 3)
                        Exit
        EndSwitch
        
EndFunc   ;==>_Tray


其实我自己平时是很少用托盘的~~

评分

参与人数 1金钱 +20 贡献 +1 收起 理由
tryhi + 20 + 1

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 13:21 , Processed in 0.067601 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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