找回密码
 加入
搜索
查看: 4135|回复: 8

[GUI管理] [消息循环]窗体循环和拖盘循环问题【已解决】

  [复制链接]
发表于 2012-2-5 20:05:41 | 显示全部楼层 |阅读模式
本帖最后由 pp648852 于 2012-2-5 21:53 编辑
#NoTrayIcon

Opt("TrayMenuMode", 1 + 2)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 320, 200)
$Button1 = GUICtrlCreateButton("Button1", 24, 152, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 208, 152, 75, 25)

Global $prefsitem = TrayCreateItem("参数选择")
TrayCreateItem("")
Global $aboutitem = TrayCreateItem("关于...")
TrayCreateItem("")
Global $exititem = TrayCreateItem("退出")

GUISetState(@SW_SHOW)
TraySetState()
#endregion ### END Koda GUI section ###

Global $XyInfo

_MouseInfo()
_Main()
Exit

Func _MouseInfo()
While 1
$XyInfo = GUIGetCursorInfo()

If $XyInfo[0] < 0 Or $XyInfo[1] < -31 Or _
$XyInfo[0] > 320 Or $XyInfo[1] > 200 Then
;~ MsgBox(16,'提示','已超出窗口范围')
_Tray()
Else
ExitLoop
EndIf
WEnd
EndFunc ;==>_MouseInfo

Func _Main()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
;~ WinWaitActive($Form1)
Case $Button1
MsgBox(0, '测试1', '只是一个测试')
Case $Button2
MsgBox(0, '测试2', '只是一个测试')

EndSwitch
_MouseInfo()
WEnd
EndFunc ;==>_Main

Func _Tray()
While 1
Local $msg = TrayGetMsg()
Select
Case $msg = $prefsitem
MsgBox(64, "参数选择:", "系统版本:" & @OSVersion)
Case $msg = $aboutitem
MsgBox(64, "关于:", "AutoIt3-托盘示例.")
Case $msg = $exititem
Exit
EndSelect
_MouseInfo()
WEnd
EndFunc ;==>_Tray
点击最小化后,程序出错退出,请高手帮帮忙看看代码!
我想让它“点击最小化后,跳到拖盘循环”
还有移出窗体范围再移进,GUI窗体就无响应,怎么回事?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-2-5 21:01:12 | 显示全部楼层
本帖最后由 半芯竹 于 2012-2-5 21:02 编辑

回复 1# pp648852
#include <GuiConstantsEx.au3>
#include <GUIEdit.au3>
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3> 
#NoTrayIcon
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode",1+2)
Opt("TrayAutoPause",0)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 320, 200,-1,-1,-1, -1, WinGetHandle(AutoItWinGetTitle()))
$Button1 = GUICtrlCreateButton("Button1", 24, 152, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 208, 152, 75, 25)

Global $prefsitem = TrayCreateItem("参数选择")
TrayItemSetOnEvent($prefsitem, "select1")
Global $aboutitem = TrayCreateItem("关于...")
TrayItemSetOnEvent($aboutitem, "aboutscript")
Global $exititem = TrayCreateItem("退出")
TrayItemSetOnEvent($exititem, "ExitScript")
GUISetState(@SW_SHOW)
TraySetState()
#endregion ### END Koda GUI section ###
TraySetOnEvent ($TRAY_EVENT_PRIMARYDOWN,'show')
TraySetClick (8)
While 1
Switch GUIGetMsg($Form1)
        Case $GUI_EVENT_MINIMIZE
                        GUISetState(@SW_HIDE, $Form1)
                Case $GUI_EVENT_CLOSE
                        ExitScript()
Case $Button1
MsgBox(0, '测试1', '只是一个测试')
Case $Button2
MsgBox(0, '测试2', '只是一个测试')
EndSwitch
WEnd
Func Select1()
        MsgBox(0,0,'This is a test!')
        EndFunc
Func ExitScript()
    Exit
EndFunc  

Func aboutscript()
    MsgBox(0,"关于本程序!","程序版本:  2012.01.20"&@LF&"编译时间:  20012.01.20 "&@LF&"程序作者:  半芯竹."&@LF&"版权所有:  Copyright(c) 2012 半芯竹 ."&@LF&"My Blog :  JosonYang.Blog.163.com.")
EndFunc  
Func show()
       GUISetState(@SW_SHOW, $Form1)
       WinActivate($Form1)
        EndFunc

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2012-2-5 21:06:11 | 显示全部楼层
回复 2# 半芯竹


    只能采用“OnEvent模式”啊?
发表于 2012-2-5 21:08:27 | 显示全部楼层
回复 3# pp648852


    这样子有啥不好呢?那你有啥高见呢?老大。。。。
 楼主| 发表于 2012-2-5 21:13:53 | 显示全部楼层
本帖最后由 pp648852 于 2012-2-5 21:15 编辑

 "怎么不能加亮啊" 
 楼主| 发表于 2012-2-5 21:18:00 | 显示全部楼层
回复 4# 半芯竹


    “OnEvent模式”我还不会
 楼主| 发表于 2012-2-5 21:47:31 | 显示全部楼层
本帖最后由 pp648852 于 2012-2-5 21:48 编辑

回复 4# 半芯竹

我把代码简化了!
#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <GUIEdit.au3>
#include <APIConstants.au3>
#include <WinAPIEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1 + 2)

#region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 320, 200)
$Button1 = GUICtrlCreateButton("Button1", 24, 152, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 208, 152, 75, 25)

Global $prefsitem = TrayCreateItem("参数选择")
TrayItemSetOnEvent($prefsitem, "select1")
Global $aboutitem = TrayCreateItem("关于...")
TrayItemSetOnEvent($aboutitem, "aboutscript")
Global $exititem = TrayCreateItem("退出")
TrayItemSetOnEvent($exititem, "ExitScript")
GUISetState(@SW_SHOW)
TraySetState()
#endregion ### END Koda GUI section ###

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, 'show')
TraySetClick(8)

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_MINIMIZE
                        GUISetState(@SW_HIDE, $Form1)
                Case $GUI_EVENT_CLOSE
                        ExitScript()
                Case $Button1
                        MsgBox(0, '测试1', '只是一个测试')
                Case $Button2
                        MsgBox(0, '测试2', '只是一个测试')
        EndSwitch
WEnd

Func Select1()
        MsgBox(0, 0, 'This is a test!')
EndFunc   ;==>Select1

Func ExitScript()
        Exit
EndFunc   ;==>ExitScript

Func aboutscript()
        MsgBox(0, "关于本程序!", "程序版本:  2012.01.20" & @LF & "编译时间:  20012.01.20 " & @LF & "程序作者:  半芯竹." & @LF & "版权所有:  Copyright(c) 2012 半芯竹 ." & @LF & "My Blog :  JosonYang.Blog.163.com.")
EndFunc   ;==>aboutscript

Func show()
        GUISetState(@SW_SHOW, $Form1)
        WinActivate($Form1)
EndFunc   ;==>show
发表于 2012-2-5 21:52:08 | 显示全部楼层
回复 7# pp648852


    你这也叫简化。什么人啊。哎。。服你了。。。我不想回帖都成水贴。。。。
如果解决了,就编辑标题+[已解决]
发表于 2012-2-7 00:29:10 | 显示全部楼层
很有用,又学了一种方法
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 23:30 , Processed in 0.091191 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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