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

[AU3基础] 如何两个gui窗口同时显示出来?

  [复制链接]
发表于 2011-3-6 08:59:50 | 显示全部楼层 |阅读模式
如下的代码,如何点托盘菜单让“配置”窗口和“关于“窗口”同时显示在屏幕上?

知道au3难以支持多线程,但记得伟大的p版说过用汇编来实现,不懂汇编,怎么实现?



#NoTrayIcon
TrayMenu()
While True
        Sleep(200)
WEnd


Func TrayMenu()                
        $TrayIconHide = 0 
        Opt("TrayIconHide", 0)
        Opt("TrayMenuMode", 1)
        Opt("TrayOnEventMode",1)
        TraySetClick(16)
        $ConfigGUI = TrayCreateItem("配置", -1, 0, 1)
        TrayItemSetOnEvent($ConfigGUI, "ConfigGUI") 
        $AboutProgram = TrayCreateItem("关于", -1, 2, 1)
        TrayItemSetOnEvent($AboutProgram, "AboutProgram")
        $ExitProgram = TrayCreateItem("退出", -1, 3, 1)
        TrayItemSetOnEvent($ExitProgram, "ExitProgram")
        TraySetState()
EndFunc

Func ConfigGUI()
        GUICreate("Config")
        $ok = GUICtrlCreateButton("Hi:", 10, 10, 30, 20)
        GUISetState()
        
        While 1
                $msg = GUIGetMsg()
                Switch $msg
                        Case -3
                                ExitLoop
                        Case $ok
                                ExitLoop
                EndSwitch
        WEnd
        GUIDelete()
EndFunc

Func AboutProgram()
        GUICreate("About")
        $About = GUICtrlCreateLabel("This is About", 10, 10, 100, 20)
        $ok = GUICtrlCreateButton("Ok", 10, 50, 30, 20)
        GUISetState()
        
        While 1
                $msg = GUIGetMsg()
                Switch $msg
                        Case -3
                                ExitLoop
                        Case $ok
                                ExitLoop
                EndSwitch
        WEnd
        GUIDelete()
EndFunc

Func ExitProgram()
        Exit
EndFunc
发表于 2011-3-6 09:58:15 | 显示全部楼层
两个函数写成一个就可以了
 楼主| 发表于 2011-3-6 10:02:53 | 显示全部楼层
回复 2# manlty

这样,明显不合实际需求呀!
发表于 2011-3-6 12:52:37 | 显示全部楼层
用事件驱动模式。
发表于 2011-3-6 13:28:43 | 显示全部楼层
本帖最后由 yhxhappy 于 2011-3-6 17:22 编辑

楼主的贴的代码语法高亮是什么做的?
#NoTrayIcon
#include <Constants.au3>
#include <GUIConstantsEx.au3>


Opt("TrayMenuMode",1)   ; 不显示默认菜单(脚本暂停/退出).
Opt("GUIOnEventMode", 1) ;事件模式

Global $ConfigGUI, $ok1, $ok2

$ConfigProgram = TrayCreateItem("配置", -1, 0, 1)
$AboutProgram = TrayCreateItem("关于", -1, 2, 1)
$ExitProgram = TrayCreateItem("退出", -1, 3, 1)
TraySetClick(16)
TraySetState()

While 1
    $msg = TrayGetMsg()
    Switch $msg
                Case $ConfigProgram
                        ConfigGUI()
        Case $AboutProgram
            AboutProgram()
        Case $ExitProgram
            Exit
        Case $TRAY_EVENT_PRIMARYDOWN
                ConfigGUI()
                AboutProgram()
        EndSwitch
WEnd

Func ConfigGUI($a = 0)
        $ConfigGUI = GUICreate("Config")
        GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI")
        $ok1 = GUICtrlCreateButton("Hi:", 10, 10, 30, 20)
        GUICtrlSetOnEvent(-1, "_GUI")
        GUISetState()
EndFunc

Func AboutProgram()
        $Pos = WinGetPos($ConfigGUI)
        If $Pos = 0 Then 
                $x = Default
                $y = Default
        Else
                $x = $Pos[0]+$Pos[2]+10
                $y = $Pos[1]
        EndIf
        GUICreate("About", -1, -1, $x, $y)
        GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI")
        $About = GUICtrlCreateLabel("This is About", 10, 10, 100, 20)
        $ok2 = GUICtrlCreateButton("Ok", 10, 50, 30, 20)
        GUICtrlSetOnEvent(-1, "_GUI")
        GUISetState()
EndFunc
        
Func _GUI()
        Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE, $ok1, $ok2
                GUIDelete(@GUI_WinHandle)
        EndSwitch
EndFunc
发表于 2011-3-6 17:03:04 | 显示全部楼层
回复 5# yhxhappy


    点击添加代码的那个符号,在底下的编辑框有  【code】【/code】 这样的字符
把其中的code改为AU3 即可
发表于 2011-3-7 23:59:13 | 显示全部楼层
一个和尚挑水喝,两个和尚抬水喝,三个和尚没水喝这个道理大家要明啊!
lol!!!

#NoTrayIcon
Opt("GUIOnEventMode", 1)
TrayMenu()
While True
        Sleep(200)
WEnd


Func TrayMenu()
        $TrayIconHide = 0
        Opt("TrayIconHide", 0)
        Opt("TrayMenuMode", 1)
        Opt("TrayOnEventMode", 1)
        TraySetClick(16)
        $ConfigGUI = TrayCreateItem("配置", -1, 0, 1)
        TrayItemSetOnEvent($ConfigGUI, "ConfigGUI")
        $AboutProgram = TrayCreateItem("关于", -1, 2, 1)
        TrayItemSetOnEvent($AboutProgram, "AboutProgram")
        $ExitProgram = TrayCreateItem("退出", -1, 3, 1)
        TrayItemSetOnEvent($ExitProgram, "ExitProgram")
        TraySetState()
EndFunc   ;==>TrayMenu

Func ConfigGUI()
        GUICreate("Config")
        GUISetOnEvent(-3, "GuiEvent")
        $ok = GUICtrlCreateButton("Hi:", 10, 10, 30, 20)
        GUISetState()
EndFunc   ;==>ConfigGUI

Func AboutProgram()
        GUICreate("About")
        GUISetOnEvent(-3, "GuiEvent")
        $About = GUICtrlCreateLabel("This is About", 10, 10, 100, 20)
        $ok = GUICtrlCreateButton("Ok", 10, 50, 30, 20)
        GUISetState()
EndFunc   ;==>AboutProgram

Func GuiEvent()
        Switch @GUI_CtrlId
                Case -3
                        GUIDelete(@GUI_WinHandle)
        EndSwitch
EndFunc

Func ExitProgram()
        Exit
EndFunc   ;==>ExitProgram

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

本版积分规则

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

GMT+8, 2024-9-21 13:35 , Processed in 0.076294 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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