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

请帮我看下这个代码

[复制链接]
发表于 2009-4-28 17:05:19 | 显示全部楼层 |阅读模式
本帖最后由 yeqing880 于 2009-4-28 19:53 编辑

运行时说button1没有声明,请问正确方法是在什么地方声明啊?  


#include <Constants.au3>
#include <md5.au3>
#include <StringMD5.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#NoTrayIcon
#AutoIt3Wrapper_run_debug_mode=Y
$Name_U = "保护工具"
If WinExists($Name_U) Then
MsgBox (16,"运行中","检测到程序正常在运行中......")
Exit
EndIf
AutoItWinSetTitle($Name_U)

Opt("TrayMenuMode", 1) ;没有默认的(暂停脚本和退出)菜单.
Opt("trayOnEventMode", 1) ;应用 OnEvent 函数于系统托盘.

$Start = TrayCreateItem("加载保护") ;创建第一个菜单项
TrayItemSetOnEvent($Start, "TrayMsg") ;注册第一个菜单项的(被点下)事件
;TrayCreateItem("") ;创建一个空白的菜单项(即横斜杠分割符)
$Close = TrayCreateItem("关闭保护") ;创建第二个菜单项
TrayItemSetOnEvent($Close, "TrayMsg") ;注册第二个菜单项的(被点下)事件
;TrayCreateItem("") ;
$Quit = TrayCreateItem("退出") ;创建第三个菜单项
TrayItemSetOnEvent($Quit, "TrayMsg") ;注册第二个菜单项的(被点下)事件
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TrayMsg") ;注册鼠标左键双击事件(只能在 TrayOnEventMode 设置为 1 时才能使用)
TraySetState()


Func Gui()
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("对话框", 357, 196, 302, 218)
GUISetIcon("D:\009.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 257, 185)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("确定(&O)", 272, 16, 75, 25, 0)
$Button2 = GUICtrlCreateButton("取消(&C)", 272, 48, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
EndFunc

Func guiitem()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox (0,"确定","你点的是确定")

        EndSwitch
WEnd
EndFunc


        


Func TrayMsg()
        
        Switch @TRAY_ID   ;选择产生消息的 TrayItem 或其它特殊事件(如鼠标左键双击事件)
                                Case $Start
                        MsgBox(48, "提示", "你点下了“启用”")
                Case $Close
                        MsgBox(48, "提示", "你点下了“关闭”")
                Case $TRAY_EVENT_PRIMARYDOUBLE
                        gui()
                Case $Quit
                        Exit
        EndSwitch
        EndFunc   ;==>TrayMsg
        
        
        
        
        
While 1
        $nMsg = GUIGetMsg()
    If $nMsg <> 0 Then guiitem()
WEnd
发表于 2009-4-28 17:23:31 | 显示全部楼层
func里嵌套#include很容易出错的。$Button1在一个func里创建又在另一个func里使用,而你又没声明为全局变量。。。
 楼主| 发表于 2009-4-28 17:27:40 | 显示全部楼层
我想应该是全局变量的问题,请问这种全局变量应该怎么声明呢?
发表于 2009-4-28 18:00:51 | 显示全部楼层
帮助文件 Dim / Global / Local / Const 一节
发表于 2009-4-28 18:09:19 | 显示全部楼层
不是没有声明 函数中默认是局部变量  你必须先用Global声明全局变量
 楼主| 发表于 2009-4-28 19:52:32 | 显示全部楼层
本帖最后由 yeqing880 于 2009-4-28 19:53 编辑

谢谢大家,问题解决了,,,,真是一句话的问题啊,我以后还得多动动脑子,不能在这样了.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-28 03:55 , Processed in 0.073547 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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