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

[系统综合] GUIOnEventMode下问题[已解决]

  [复制链接]
发表于 2012-3-9 09:37:23 | 显示全部楼层 |阅读模式
本帖最后由 linteyue 于 2012-3-12 09:03 编辑

请教各位大哥,
现在问题是以下这段脚本一运行就自己先跑了OKButton($Button1)里面的东东,
怎么改成按“确定后”才运行OKButton($Button1)呢?
小弟不才,麻烦各位大哥帮助下,谢谢!
#include <Process.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <inet.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)
$Version = "公告浏览" 
Local $Week[7] = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
;~ $Exegettime = FileGetTime("C:\Support\BOBootHint.au3", 0, 1)

For $i = 1 To 16
        _msbox()
        Sleep(5000)
Next

Func _msbox()
        If WinExists($Version) <> 1 Then
                $PonHint = GUICreate($Version, 560, 230, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
                $Label1 = GUICtrlCreateLabel("请各位店铺经理切记:", 16, 24, 508, 57)
                GUICtrlSetFont(-1, 40, 400, 0, "宋体")
                $Button1 = GUICtrlCreateButton("确 定", 216, 168, 83, 33)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                $Label3 = GUICtrlCreateLabel($Version, 24, 104, 510, 31)
                GUICtrlSetFont(-1, 20, 400, 0, "宋体")
                $Group1 = GUICtrlCreateGroup("", 400, 152, 153, 73)
                $Label2 = GUICtrlCreateLabel("今天是: " & @YEAR & "-" & @MON & "-" & @MDAY, 408, 168, 138, 24)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                $Label4 = GUICtrlCreateLabel($week[@WDAY-1], 480, 192, 52, 24)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                GUICtrlSetOnEvent($Button1, OKButton($Button1))
                WinSetOnTop($Version, "", 1)
                GUISetState(@SW_SHOW)
        Else
                GUISetState(@SW_SHOW) 
        EndIf
EndFunc        

Func OKButton($Button1)
        WinSetOnTop($Version, "", 0)
        GUICtrlSetState($Button1, $GUI_DISABLE)
        $var = MsgBox(262161,"","234") 
        If $var  = 1 Then
        GUISetState(@SW_HIDE)
        EndIf
;~         WinSetOnTop($Version, "", 1)
EndFunc

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2012-3-9 10:16:31 | 显示全部楼层
你这写法真蛋疼,看看点击确定后还不是反复弹出来
#include <Process.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <inet.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)
$Version = "公告浏览" 
Local $Week[7] = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],$Button1
;~ $Exegettime = FileGetTime("C:\Support\BOBootHint.au3", 0, 1)

For $i = 1 To 16
        _msbox()
        Sleep(5000)
Next

Func _msbox()
        If WinExists($Version) <> 1 Then
                $PonHint = GUICreate($Version, 560, 230, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
                $Label1 = GUICtrlCreateLabel("请各位店铺经理切记:", 16, 24, 508, 57)
                GUICtrlSetFont(-1, 40, 400, 0, "宋体")
                $Button1 = GUICtrlCreateButton("确 定", 216, 168, 83, 33)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                $Label3 = GUICtrlCreateLabel($Version, 24, 104, 510, 31)
                GUICtrlSetFont(-1, 20, 400, 0, "宋体")
                $Group1 = GUICtrlCreateGroup("", 400, 152, 153, 73)
                $Label2 = GUICtrlCreateLabel("今天是: " & @YEAR & "-" & @MON & "-" & @MDAY, 408, 168, 138, 24)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                $Label4 = GUICtrlCreateLabel($week[@WDAY-1], 480, 192, 52, 24)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                GUICtrlSetOnEvent($Button1, "OKButton")
                WinSetOnTop($Version, "", 1)
                GUISetState(@SW_SHOW)
        Else
                GUISetState(@SW_SHOW) 
        EndIf
EndFunc        

Func OKButton()
        WinSetOnTop($Version, "", 0)
        GUICtrlSetState($Button1, $GUI_DISABLE)
        $var = MsgBox(262161,"","234") 
        If $var  = 1 Then
        GUISetState(@SW_HIDE)
        EndIf
;~         WinSetOnTop($Version, "", 1)
EndFunc

评分

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

查看全部评分

发表于 2012-3-9 10:45:08 | 显示全部楼层
本帖最后由 lixiaolong 于 2012-3-9 10:47 编辑

回复 1# linteyue

在用户定义函数里的变量一般不能再其他的用户定义函数里用.
如果想用声明变量.

还有GUICtrlSetOnEvent 的用法不对.
GUICtrlSetOnEvent ( 控件ID, "函数名" )
#include <Process.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <inet.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)

Global $Button1; 全局变量
$Version = "公告浏览"
Local $Week[7] = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
;~ $Exegettime = FileGetTime("C:\Support\BOBootHint.au3", 0, 1)
For $i = 1 To 16
        _msbox()
        Sleep(5000)
Next

Func _msbox()
        If WinExists($Version) <> 1 Then
                $PonHint = GUICreate($Version, 560, 230, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
                $Label1 = GUICtrlCreateLabel("请各位店铺经理切记:", 16, 24, 508, 57)
                GUICtrlSetFont(-1, 40, 400, 0, "宋体")
                $Button1 = GUICtrlCreateButton("确 定", 216, 168, 83, 33)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                GUICtrlSetOnEvent($Button1, "OKButton")
                
                $Label3 = GUICtrlCreateLabel($Version, 24, 104, 510, 31)
                GUICtrlSetFont(-1, 20, 400, 0, "宋体")
                $Group1 = GUICtrlCreateGroup("", 400, 152, 153, 73)
                $Label2 = GUICtrlCreateLabel("今天是: " & @YEAR & "-" & @MON & "-" & @MDAY, 408, 168, 138, 24)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                $Label4 = GUICtrlCreateLabel($Week[@WDAY - 1], 480, 192, 52, 24)
                GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                GUICtrlCreateGroup("", -99, -99, 1, 1)
                WinSetOnTop($Version, "", 1)
                GUISetState(@SW_SHOW)
        Else
                GUISetState(@SW_SHOW)
        EndIf
EndFunc   ;==>_msbox

Func OKButton()
        WinSetOnTop($Version, "", 0)
        GUICtrlSetState($Button1, $GUI_DISABLE)
        $var = MsgBox(262161, "", "234")
        If $var = 1 Then
                GUISetState(@SW_HIDE)
        EndIf
;~         WinSetOnTop($Version, "", 1)
EndFunc   ;==>OKButton

评分

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

查看全部评分

发表于 2012-3-9 11:27:02 | 显示全部楼层
变量怎么这么乱  一个函数的变量跑到另一个函数里面去了。  所有的函数都用的话直接Global
 楼主| 发表于 2012-3-9 15:48:38 | 显示全部楼层
因为脚本里还有很多函数要同时运行,小弟不才,只学会这么多,也只会这么写。。。
以为是整个脚本的内容,望各位大哥可以修改精简下。
#include <inet.au3>
#Include <Date.au3>
#include <Process.au3>
#include <Constants.au3> 
#include <GuiListView.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC",0)

$Version = "公告浏览" 
Local $Week[8] = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六','星期日'], $Button1, $ListView1, $Label1
Dim $AddTime = "公告日期", $TaskTime = "生效日期", $NoticeLabel = "公告内容", $Cont = "周期"
Dim $Exegettime = FileGetTime("C:\Support\BOBootHint.au3", 0, 1)
Dim $Config_File = "C:\Support\Noticeconfig.ini"

For $i = 1 To 16
        If $Exegettime <> FileGetTime("C:\Support\BOBootHint.au3", 0, 1) Then
                Run("C:\Support\BORebootau3.bat", "C:\Support", @SW_HIDE)
                Exit
        EndIf
        _msbox()
        _UpdateCKUtil()
        _VPDN()
        _SetPrinter()
        Sleep(900000)
Next
Run("C:\Support\BORebootau3.bat", "C:\Support", @SW_HIDE)

Func _SetPrinter()
        If FileExists("C:\Program Files\普通发票管理系统\nsrptfp.exe") =1  And ProcessExists("nsrptfp.exe") = 0 Then
                For $i = 1 to 10
                        $Printername = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts", $i)
                        if @error <> 0 Then ExitLoop
                        if stringmid($Printername,1,2) = "HP" Then
                                RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\windows","Device","REG_SZ",$Printername & "," & _
                                RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts",$Printername))
                        EndIf
                next
        EndIf
EndFunc

Func _UpdateCKUtil()
        If FileGetTime("C:\Support\CKUtil.exe", 0, 1) <> FileGetTime("C:\Support\CKUtil_new.exe", 0, 1) Then
                ProcessClose("CKUtil.exe")
                Sleep(5000)
                _RunDOS ("xcopy C:\Support\CKUtil_new.exe C:\Support\CKUtil.exe /y /c /r")
                _RunDOS ("xcopy C:\Support\CKUtil_new.pdb C:\Support\CKUtil.pdb /y /c /r")
                Run("C:\Support\CKUtil.exe", "C:\Support")
        EndIf
        If ProcessExists ("CKUtil.exe") = 0 Then Run("C:\Support\CKUtil.exe", "C:\Support")
EndFunc

Func _msbox()
        If @HOUR&@MIN > 0900 And @HOUR&@MIN < 0930 Then
                If WinExists($Version) <> 1 Then
                        $Form1 = GUICreate($Version, 422, 300, -1, -1,BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
                        $Button1 = GUICtrlCreateButton("关闭", 160, 220, 100, 40)
                        $LabelToday = GUICtrlCreateLabel("今天是: " & @YEAR & "-" & @MON & "-" & @MDAY, 300, 220, 138, 15)
                        $LabelWDay = GUICtrlCreateLabel($Week[@WDAY-1], 348, 240, 138, 20)
                        WinSetOnTop($Version, "", 1)
                        GUICtrlSetOnEvent($Button1, "OKButton")
                Else
                        GUICtrlSetState($Label1,$GUI_Hide)
                        GUICtrlSetState($Button1,$GUI_SHOW)
                EndIf
                Add_List()
        EndIf
EndFunc        

Func Add_List()
        GUICtrlDelete($ListView1)
        $var = IniReadSectionNames($Config_File)
        $ListView1 = GUICtrlCreateListView("*|"& $NoticeLabel, 8, 8, 400, 200)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 30)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 360)
        GUICtrlSetFont($ListView1,16)
        If Not @error Then
                $now = @YEAR & "-" & @MON & "-" & @MDAY
                $S = 0
                For $n = 1 To $var[0]
                        $ReadINITaskTime = IniRead($Config_File, $var[$n], $TaskTime, " ") 
                        $Readnotice = IniRead($Config_File, $var[$n], $NoticeLabel, " ")
                        If IniRead($Config_File, $var[$n], $Cont, "") = "A" Then
                                If _DateDiff('d', $now, $ReadINITaskTime) = 0 Then
                                $S = $S +1
                                GUICtrlCreateListViewItem($S & ".|" & $Readnotice & "|", $ListView1)
                                EndIf
                        EndIf
                        If IniRead($Config_File, $var[$n], $Cont, "") = "C" Then
                                $RITWStr = StringSplit($ReadINITaskTime,",")
                                For $i = 1 To $RITWStr[0]
                                        If $Week[@WDAY-1] = $RITWStr[$i] Then
                                        $S = $S +1
                                        GUICtrlCreateListViewItem($S & ".|" & $Readnotice & "|", $ListView1)        
                                        EndIf
                                Next
                        EndIf
                        
                        If IniRead($Config_File, $var[$n], $Cont, "") = "D" Then
                                $RITMStr = StringSplit(StringTrimRight(StringTrimLeft($ReadINITaskTime,2),1),",")
                                $Mday = @MDAY
                                If StringLeft(@MDAY, 1) = 0 Then $Mday = StringTrimLeft(@MDAY, 1)
                                For $i = 1 To $RITMStr[0]
                                        If $Mday = $RITMStr[$i] Then 
                                        $S = $S +1
                                        GUICtrlCreateListViewItem($S & ".|" & $Readnotice & "|", $ListView1)        
                                        EndIf
                                Next
                        EndIf
                        
                        If IniRead($Config_File, $var[$n], $Cont, "") = "B" Then
                                $S = $S +1
                                GUICtrlCreateListViewItem($S & ".|" & $Readnotice & "|", $ListView1)
                        EndIf
                        If @error <> 0 Then ExitLoop
                Next
                If $S <> 0  Then GUISetState(@SW_SHOW)
        EndIf
EndFunc

Func OKButton()
        GUICtrlSetState($Button1, $GUI_DISABLE)
        WinSetOnTop($Version, "", 0)
        $Mvar = MsgBox(262417,"关闭提示","是否已阅读公告内容?")
        If $Mvar = 1 Then
                GUICtrlSetState($Button1,$GUI_Hide)
                WinSetOnTop($Version, "", 1)
                $Label1 = GUICtrlCreateLabel("", 152, 230, 120, 40)
                GUICtrlSetColor($Label1,0xff0000)
                For $ii = 10 To 1 Step -1
                        GUICtrlSetData($Label1, "窗口将于" & $ii & "秒后关闭")
                        Sleep(1000)
                Next
                GUISetState(@SW_HIDE)
        EndIf
        GUICtrlSetState($Button1, $GUI_ENABLE)
        WinSetOnTop($Version, "", 1)
EndFunc

Func _VPDN()
        FileDelete(@DesktopDir & "\Storesupport.txt")
        _INetGetSource("http://172.25.128.15:4080/ip.asp?PC=" & @ComputerName)
EndFunc
 楼主| 发表于 2012-3-9 15:49:08 | 显示全部楼层
#include <inet.au3>
#Include <Date.au3>
#include <Process.au3>
#include <Constants.au3> 
#include <GuiListView.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC",0)

$Version = "公告浏览" 
Local $Week[8] = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六','星期日'], $Button1, $ListView1, $Label1
Dim $AddTime = "公告日期", $TaskTime = "生效日期", $NoticeLabel = "公告内容", $Cont = "周期"
Dim $Exegettime = FileGetTime("C:\Support\BOBootHint.au3", 0, 1)
Dim $Config_File = "C:\Support\Noticeconfig.ini"

For $i = 1 To 16
        If $Exegettime <> FileGetTime("C:\Support\BOBootHint.au3", 0, 1) Then
                Run("C:\Support\BORebootau3.bat", "C:\Support", @SW_HIDE)
                Exit
        EndIf
        _msbox()
        _UpdateCKUtil()
        _VPDN()
        _SetPrinter()
        Sleep(900000)
Next
Run("C:\Support\BORebootau3.bat", "C:\Support", @SW_HIDE)

Func _SetPrinter()
        If FileExists("C:\Program Files\普通发票管理系统\nsrptfp.exe") =1  And ProcessExists("nsrptfp.exe") = 0 Then
                For $i = 1 to 10
                        $Printername = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts", $i)
                        if @error <> 0 Then ExitLoop
                        if stringmid($Printername,1,2) = "HP" Then
                                RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\windows","Device","REG_SZ",$Printername & "," & _
                                RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts",$Printername))
                        EndIf
                next
        EndIf
EndFunc

Func _UpdateCKUtil()
        If FileGetTime("C:\Support\CKUtil.exe", 0, 1) <> FileGetTime("C:\Support\CKUtil_new.exe", 0, 1) Then
                ProcessClose("CKUtil.exe")
                Sleep(5000)
                _RunDOS ("xcopy C:\Support\CKUtil_new.exe C:\Support\CKUtil.exe /y /c /r")
                _RunDOS ("xcopy C:\Support\CKUtil_new.pdb C:\Support\CKUtil.pdb /y /c /r")
                Run("C:\Support\CKUtil.exe", "C:\Support")
        EndIf
        If ProcessExists ("CKUtil.exe") = 0 Then Run("C:\Support\CKUtil.exe", "C:\Support")
EndFunc

Func _msbox()
        If @HOUR&@MIN > 0900 And @HOUR&@MIN < 0930 Then
                If WinExists($Version) <> 1 Then
                        $Form1 = GUICreate($Version, 422, 300, -1, -1,BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
                        $Button1 = GUICtrlCreateButton("关闭", 160, 220, 100, 40)
                        $LabelToday = GUICtrlCreateLabel("今天是: " & @YEAR & "-" & @MON & "-" & @MDAY, 300, 220, 138, 15)
                        $LabelWDay = GUICtrlCreateLabel($Week[@WDAY-1], 348, 240, 138, 20)
                        WinSetOnTop($Version, "", 1)
                        GUICtrlSetOnEvent($Button1, "OKButton")
                Else
                        GUICtrlSetState($Label1,$GUI_Hide)
                        GUICtrlSetState($Button1,$GUI_SHOW)
                EndIf
                Add_List()
        EndIf
EndFunc        

Func Add_List()
        GUICtrlDelete($ListView1)
        $var = IniReadSectionNames($Config_File)
        $ListView1 = GUICtrlCreateListView("*|"& $NoticeLabel, 8, 8, 400, 200)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 30)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 360)
        GUICtrlSetFont($ListView1,16)
        If Not @error Then
                $now = @YEAR & "-" & @MON & "-" & @MDAY
                $S = 0
                For $n = 1 To $var[0]
                        $ReadINITaskTime = IniRead($Config_File, $var[$n], $TaskTime, " ") 
                        $Readnotice = IniRead($Config_File, $var[$n], $NoticeLabel, " ")
                        If IniRead($Config_File, $var[$n], $Cont, "") = "A" Then
                                If _DateDiff('d', $now, $ReadINITaskTime) = 0 Then
                                $S = $S +1
                                GUICtrlCreateListViewItem($S & ".|" & $Readnotice & "|", $ListView1)
                                EndIf
                        EndIf
                        If IniRead($Config_File, $var[$n], $Cont, "") = "C" Then
                                $RITWStr = StringSplit($ReadINITaskTime,",")
                                For $i = 1 To $RITWStr[0]
                                        If $Week[@WDAY-1] = $RITWStr[$i] Then
                                        $S = $S +1
                                        GUICtrlCreateListViewItem($S & ".|" & $Readnotice & "|", $ListView1)        
                                        EndIf
                                Next
                        EndIf
                        
                        If IniRead($Config_File, $var[$n], $Cont, "") = "D" Then
                                $RITMStr = StringSplit(StringTrimRight(StringTrimLeft($ReadINITaskTime,2),1),",")
                                $Mday = @MDAY
                                If StringLeft(@MDAY, 1) = 0 Then $Mday = StringTrimLeft(@MDAY, 1)
                                For $i = 1 To $RITMStr[0]
                                        If $Mday = $RITMStr[$i] Then 
                                        $S = $S +1
                                        GUICtrlCreateListViewItem($S & ".|" & $Readnotice & "|", $ListView1)        
                                        EndIf
                                Next
                        EndIf
                        
                        If IniRead($Config_File, $var[$n], $Cont, "") = "B" Then
                                $S = $S +1
                                GUICtrlCreateListViewItem($S & ".|" & $Readnotice & "|", $ListView1)
                        EndIf
                        If @error <> 0 Then ExitLoop
                Next
                If $S <> 0  Then GUISetState(@SW_SHOW)
        EndIf
EndFunc

Func OKButton()
        GUICtrlSetState($Button1, $GUI_DISABLE)
        WinSetOnTop($Version, "", 0)
        $Mvar = MsgBox(262417,"关闭提示","是否已阅读公告内容?")
        If $Mvar = 1 Then
                GUICtrlSetState($Button1,$GUI_Hide)
                WinSetOnTop($Version, "", 1)
                $Label1 = GUICtrlCreateLabel("", 152, 230, 120, 40)
                GUICtrlSetColor($Label1,0xff0000)
                For $ii = 10 To 1 Step -1
                        GUICtrlSetData($Label1, "窗口将于" & $ii & "秒后关闭")
                        Sleep(1000)
                Next
                GUISetState(@SW_HIDE)
        EndIf
        GUICtrlSetState($Button1, $GUI_ENABLE)
        WinSetOnTop($Version, "", 1)
EndFunc

Func _VPDN()
        FileDelete(@DesktopDir & "\Storesupport.txt")
        _INetGetSource("http://172.25.128.15:4080/ip.asp?PC=" & @ComputerName)
EndFunc
发表于 2012-3-10 14:31:59 | 显示全部楼层
好好看看帮助里有例程哦
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 19:28 , Processed in 0.090224 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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