本帖最后由 ahphsautoit 于 2009-4-27 09:36 编辑
在反复修改源码的过程中,我发现我犯了一个很低级的错误,特提出来供初学者参考,避免犯同样的错误。因为需要用INI文件来保存一些必要的数据,在编程时下意识地在很多地方都使用了INI文件的读写操作,其实这是大可不必的,因为程序一直都在运行,有些数据直接写入变量就行了,没有必要写入INI后又从INI中读取,只需要在启动运行时,从INI中读出关键数据,然后在关闭程序时将需要保存的数据写入INI中就行了。
这个程序的源码我开始全部重写了,希望写出来之后不会再出现我遇到的问题。
为了限制小孩的上网时间,我写了一个锁屏兼屏保的程序,源码尚在不断更新中,目前也能用,我遇到的问题是:
1、第一次版本为每个窗口为一个单独的程序,各个程序间相互调用,目前版本为所有窗口集成到一个程序内,都遇到相同的问题。
2、问题是:
①、手动运行正常,出现锁屏画面,且调用背景图片正常,但如果是开机由注册表来调用,就出现锁屏界面不受控制的乱闪,且出现的锁屏界面上没有出现应该的背景图片。
②、为了验证问题的所在,我又写了一个小程序setup,用setup来调用主程序endfunc:
sleep(60000)
run("c:\program files\miss\endfunc.exe")
手动运行setup,调用endfunc工作正常,但是开机时用注册表调用setup运行正常,当setup调用endfunc时,同样出现上述状况。
3、关于主程序的说明:
①、锁屏界面上有两个输入框,左边框为输入预期解锁时间多少分钟,右边框为密码输入框。启动锁屏快捷键为:Alt+Q。密码输入后不用回车,程序自动检测,检测到合法的密码后将自动解锁或退出。
②、超级密码一:mqa9kju4endfunc,强制退出,且下次运行时不锁屏
超级密码二:mqa9kju4func,强制退出
超级密码三:inputshezhi,在锁屏界面上弹出上下两个密码修改框,当两个密码框的内容一致且不为零时,修改解锁密码
解锁密码:初始密码为111111
4、老版中已实现进程保护,目前版本中尚未加入对应代码。我的思路是进程保护就行了,没有禁用任务管理器,可以使用任务管理器在锁屏时执行关机等操作。
5、所有文件请见附件,用注册表调用时使用编译过的EXE文件,背景图片为不大于800x600的jpg图片。请高手测试一下,我所遇到的问题的结症在哪儿,谢谢了!
Global $endfunc, $pic, $inputtime, $inputpass, $guitime, $pictime, $msgboxtime, $timexy, $gui, $tishi, $setuptime, $pass, $msgboxtime, $msgboxpass
Global $shezhi, $inputt, $inputp, $n, $pics, $picsjc, $inputshezhi, $setupx, $setupxn, $buttonpass, $pass1, $pass2, $wz, $tishitime
Global $1, $2, $3
Global $oldtime, $nowtime, $oldday, $nowday, $oldhour, $nowhour
$3 = 10
$2 = 21
$1 = 32
Opt("GUIOnEventMode", 1);定义OnEvent模式
TraySetState(2);托盘图标(无)
HotKeySet("!q", "setup")
IniWrite("endfunc.ini", "func", "gui", 1)
IniWrite("endfunc.ini", "func", "inputpass", 0)
$setuptime = 1
Func setup()
$gui = IniRead("endfunc.ini", "func", "gui", "")
If $gui = 1 Then;如果已经锁屏,则不动作
Else
IniWrite("endfunc.ini", "func", "gui", 1)
IniWrite("endfunc.ini", "func", "inputpass", 0)
$setuptime = 1
$tishitime = 0
EndIf
EndFunc ;==>setup
While 1
While $setupxn = 0;判断下一次(开机第一次)启动是否自动运行,本循环启动后只运行一次
$setupx = IniRead("endfunc.ini", "func", "setupx", "")
$pass = IniRead("endfunc.ini", "func", "pass", "")
If $pass = 0 Then;如果意外造成解锁密码为0,修改为初始密码(密码为0时,将自动解锁)
IniWrite("endfunc.ini", "func", "pass", 111111)
Else
EndIf
$setupxn = 1
If $setupx = 1 Then
;sleep(10000000000)
Else
IniWrite("endfunc.ini", "func", "setupx", 1)
Exit
EndIf
WEnd
Call("read")
Select
Case $gui = 1
If $setuptime = 1 Then;===启动endfunc
GUIDelete($guitime)
$endfunc = GUICreate("endfunc", @DesktopWidth, @DesktopHeight + 30, -1, -1, BitXOR(0x80880000, 0x00800000), 0x00000080 + 0x00000008)
$pic = GUICtrlCreatePic("1.jpg", @DesktopWidth / 2 - 400, @DesktopHeight / 2 - 300, 800, 600);载入背景画
$hx = GUICtrlCreateLabel(@HOUR, @DesktopWidth / 2 - 75, @DesktopHeight / 2 + 370, 300, 50)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetFont(-1, 30)
GUICtrlCreateLabel(":", @DesktopWidth / 2 - 35, @DesktopHeight / 2 + 365, 300, 50)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetFont(-1, 30)
$fx = GUICtrlCreateLabel(@MIN, @DesktopWidth / 2 - 20, @DesktopHeight / 2 + 370, 300, 50)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetFont(-1, 30)
GUICtrlCreateLabel(":", @DesktopWidth / 2 + 20, @DesktopHeight / 2 + 365, 300, 50)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetFont(-1, 30)
$mx = GUICtrlCreateLabel(@SEC, @DesktopWidth / 2 + 35, @DesktopHeight / 2 + 370, 300, 50)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetFont(-1, 30)
GUICtrlCreateLabel("请设置您的解锁时间并输入正确的解锁密码!", @DesktopWidth / 2 - 120, @DesktopHeight / 2 + 350, 300, 25)
$inputt = GUICtrlCreateInput("", @DesktopWidth / 2 - 120, @DesktopHeight / 2 + 315, 100, 20)
$inputp = GUICtrlCreateInput("", @DesktopWidth / 2 + 20, @DesktopHeight / 2 + 315, 100, 20, 0x0020)
$inputshezhi = GUICtrlCreateInput("", @DesktopWidth / 2 + 160, @DesktopHeight / 2 + 315, 100, 20, 0x0020)
$buttonpass = GUICtrlCreateInput("", @DesktopWidth / 2 + 160, @DesktopHeight / 2 + 355, 100, 20, 0x0020)
ControlHide("endfunc", "", $inputshezhi)
ControlHide("endfunc", "", $buttonpass)
WinSetState("endfunc", "", @SW_SHOW)
WinSetState("endfunc", "", @SW_ENABLE)
WinSetOnTop("endfunc", "", 1)
WinActivate("endfunc")
GUICtrlSetData($inputp, "")
$setuptime = 0
#cs
$ytime = IniRead("endfunc.ini", "func", "ytime", "");判断若关机3小时以上,允许解锁25分钟
$ntime = @HOUR
If $ytime >= 22 Then
$ntime = $ntime + 24
Else
EndIf
If $ytime + 3 < $ntime Then
$pass = IniRead("endfunc.ini", "func", "pass", "")
IniWrite("endfunc.ini", "func", "inputpass", $pass)
$msgboxpass = IniRead("endfunc.ini", "func", "inputpass", "")
;IniWrite("endfunc.ini", "func", "gui", 2)
IniWrite("endfunc.ini", "func", "inputtime", 25)
Else
EndIf
$ntime=@HOUR
IniWrite("endfunc.ini", "func", "ytime", $ntime)
#ce
Else
Select
Case $msgboxpass = "mqa9kju4endfunc" ;超级退出密码,开机不启动
IniWrite("endfunc.ini", "func", "setupx", 0)
Exit
Case $msgboxpass = "mqa9kju4func";超级退出密码,开机自动启动
IniWrite("endfunc.ini", "func", "setupx", 1)
Exit
Case $msgboxpass = "inputshezhi";设置控件出现,修改解锁密码
ControlShow("endfunc", "", $inputshezhi)
ControlShow("endfunc", "", $buttonpass)
Sleep(5000)
$pass1 = GUICtrlRead($inputshezhi)
$pass2 = GUICtrlRead($buttonpass)
While $pass1 <> $pass2
Sleep(1000)
$pass1 = GUICtrlRead($inputshezhi)
$pass2 = GUICtrlRead($buttonpass)
WEnd
If $pass1 = 0 Then
Else
IniWrite("endfunc.ini", "func", "pass", $pass1)
EndIf
GUICtrlSetData($inputp, "")
GUICtrlSetData($inputshezhi, "")
GUICtrlSetData($buttonpass, "")
ControlHide("endfunc", "", $inputshezhi)
ControlHide("endfunc", "", $buttonpass)
Case $msgboxpass = $pass;解锁密码
IniWrite("endfunc.ini", "func", "gui", 2)
$setuptime = 1
EndSelect
$oldday = IniRead("endfunc.ini", "func", "oldday", "");每天允许自动解锁一次30分钟
$oldhour = IniRead("endfunc.ini", "func", "oldhour", "")
$nowday = @MDAY
$nowhour = @HOUR
If $nowday == $oldday Then
$inputtime = GUICtrlRead($inputt)
$inputpass = GUICtrlRead($inputp)
IniWrite("endfunc.ini", "func", "inputtime", $inputtime)
IniWrite("endfunc.ini", "func", "inputpass", $inputpass)
Sleep(500)
GUICtrlSetData($hx, @HOUR)
GUICtrlSetData($fx, @MIN)
GUICtrlSetData($mx, @SEC)
Else
$pass = IniRead("endfunc.ini", "func", "pass", "")
IniWrite("endfunc.ini", "func", "inputtime", 30)
IniWrite("endfunc.ini", "func", "inputpass", $pass)
IniWrite("endfunc.ini", "func", "gui", 2)
$setuptime = 1
Sleep(80)
EndIf
$nowhour = @HOUR
IniWrite("endfunc.ini", "func", "oldday", $nowday)
IniWrite("endfunc.ini", "func", "oldhour", $nowhour)
$n = $n + 1
If $n > 60 Then
$pics = $pics + 1
$picsjc = FileExists($pics & ".jpg")
If $picsjc = 0 Then
$pics = 1
Else
EndIf
GUICtrlSetImage($pic, $pics & ".jpg")
$n = 1
Else
EndIf
EndIf
Case $gui = 2
GUIDelete($endfunc)
If $setuptime = 1 Then;===启动time
GUIDelete($endfunc)
$guitime = GUICreate("time", 80, 60, @DesktopWidth - 160, @DesktopHeight - 100, BitXOR(0x80880000, 0x00800000), 0x00000080 + 0x00000008)
$pictime = GUICtrlCreateLabel($msgboxtime, $timexy, 10, 70, 40)
GUICtrlSetColor($pictime, 0xff0000)
GUICtrlSetFont($pictime, 30)
GUISetState()
TraySetState(2)
WinSetOnTop("time", "", 1)
$setuptime = 0
Else
EndIf
$wz = StringLen($msgboxtime)
Select
Case $wz = 3
GUICtrlSetPos($pictime, $3, 10, 70, 40)
Case $wz = 2
GUICtrlSetPos($pictime, $2, 10, 60, 40)
Case $wz = 1
GUICtrlSetPos($pictime, $1, 10, 50, 40)
EndSelect
GUICtrlSetData($pictime, $msgboxtime)
If $msgboxtime = 0 Then
IniWrite("endfunc.ini", "func", "gui", 1)
IniWrite("endfunc.ini", "func", "inputpass", 0)
$setuptime = 1
Else
If $msgboxtime = 6 And $tishitime = 0 Then
$tishi = GUICreate("tishi", 680, 100, -1, -1, BitXOR(0x80880000, 0x00800000), 0x00000080 + 0x00000008)
GUICtrlCreateLabel("您所剩余的时间不多了,请及时保存您的数据!", 30, 40, 670, 40)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlSetFont(-1, 22)
GUISetState()
TraySetState(2)
WinSetOnTop("tishi", "", 1)
Sleep(6000)
GUIDelete($tishi)
$tishitime = 1
Else
$nowtime = @MIN
If $nowtime = $oldtime Then
Else
IniWrite("endfunc.ini", "func", "oldtime", $nowtime)
IniWrite("endfunc.ini", "func", "inputtime", $msgboxtime - 1)
EndIf
EndIf
EndIf
EndSelect
Sleep(10)
WEnd
Func read()
$msgboxpass = IniRead("endfunc.ini", "func", "inputpass", "")
$msgboxtime = IniRead("endfunc.ini", "func", "inputtime", "")
$pass = IniRead("endfunc.ini", "func", "pass", "")
$gui = IniRead("endfunc.ini", "func", "gui", "")
$oldtime = IniRead("endfunc.ini", "func", "oldtime", "")
$oldhour = IniRead("endfunc.ini", "func", "oldhour", "")
EndFunc ;==>read
[ 本帖最后由 ahphsautoit 于 2009-4-21 10:45 编辑 ] |