GUIOnEventMode下问题[已解决]
本帖最后由 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 = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
;~ $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 你这写法真蛋疼,看看点击确定后还不是反复弹出来#include <Process.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <inet.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)
$Version = "公告浏览"
Local $Week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],$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 本帖最后由 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 = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
;~ $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
变量怎么这么乱一个函数的变量跑到另一个函数里面去了。所有的函数都用的话直接Global 因为脚本里还有很多函数要同时运行,小弟不才,只学会这么多,也只会这么写。。。
以为是整个脚本的内容,望各位大哥可以修改精简下。#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 = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六','星期日'], $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") =1And 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
$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
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
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 <> 0Then 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 #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 = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六','星期日'], $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") =1And 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
$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
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
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 <> 0Then 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 好好看看帮助里有例程哦
页:
[1]