#cs
完成于20141111
1、增加了 ’参考提示‘
2、了解了题库中 ’给定答案与用户的选择一致性‘如何用 Bitand()和if语句进行判读
下一阶段任务:
1、给试题添加图片
感谢:
地平线
lanfengc
#ce
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#Include <Misc.au3>
If _singleton(@scriptname,1)=0 Then
MsgBox(0,"请注意","目前有脚本程序正在运行")
Exit
EndIf
;强制脚本只执行一个设计实例
If Not FileExists(@ScriptDir&"\考试题.ini") Then
MsgBox(0,"请注意","考试题库不存在")
Exit
EndIf
;判断考试题库是否存在
Global $his
;$his一定要设置为“全局变量”,从该字段读题号
GUICreate("考驾照自测题系统",800,600,-1,-1,BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX))
$his=IniRead(@ScriptDir&"\考试题.ini","His","Num","x");考试从第1题开始
$question=IniRead(@ScriptDir&"\考试题.ini",$his,"问题","x")
$sela=IniRead(@ScriptDir&"\考试题.ini",$his,"SelectA","x")
$selb=IniRead(@ScriptDir&"\考试题.ini",$his,"SelectB","x")
$selc=IniRead(@ScriptDir&"\考试题.ini",$his,"SelectC","x")
$seld=IniRead(@ScriptDir&"\考试题.ini",$his,"SelectD","x")
$selimage=IniRead(@ScriptDir&"\考试题.ini",$his,"ImagePath","x")
;$selimage=IniRead(@ScriptDir"\考试题.ini",$his,"ImagePath","x")
;error:"\考试题.ini"前竟然落了一个 & ,找了半天才看到
;error:语法错误,原因是 $his 前多写了个 ,
;以上执行“将问题和选择从考试题库ini文件中读出来存储在指定的变量中
$key="x";答案变量初始值
$note="x";提示变量初始值
$GUInum=GUICtrlCreateLabel($his,30,40,55,20);自动创建窗口中 “题号” 的位置
$GUIque=GUICtrlCreateLabel($question,87,40,700,80);自动创建窗口中 “问题” 的位置
$GUIa=GUICtrlCreateRadio($sela,40,80,700,50,$BS_MULTILINE);以下是4个选择项建立
$GUIb = GUICtrlCreateRadio($selb,40,130,700,50,$BS_MULTILINE)
$GUIc = GUICtrlCreateRadio($selc,40,180,700,50,$BS_MULTILINE)
$GUId = GUICtrlCreateRadio($seld,40,230,700,50,$BS_MULTILINE)
$GUIpic=GUICtrlCreatePic($selimage,350,100,300,194)
;GUICtrlSetData($GUIpic,$selimage)
;把上面读到变量里的内容写在“窗口指定控件位置上”
$GUIsub=GUICtrlCreateButton("提交答案",40,330,100,40)
GUICtrlCreateLabel("参考答案:",50,400)
$GUIkey=GUICtrlCreateLabel($key,120,395,60,20)
GUICtrlCreateLabel("参考提示:",50,430)
$GUInote=GUICtrlCreateLabel($note,120,428,600,80)
;GUICtrlCreateLabel("已自动加载"&@CRLF&"上次答题进度",390,405,100,30,0x01,$WS_EX_CLIENTEDGE)
$GUItab1=GUICtrlCreateLabel("跳转到第",510,330,70,25)
$GUIinput=GUICtrlCreateInput($his,585,330,50,25)
$GUItab2=GUICtrlCreateLabel("题",640,330,20,25)
$GUIgo=GUICtrlCreateButton("Go",665,330,30,30)
$GUIbefore = GUICtrlCreateButton("<<-- 上一题",180,330,100,40)
$GUInext = GUICtrlCreateButton("下一题 -->>",320,330,100,40)
GUICtrlSetFont($GUInum,13)
GUICtrlSetFont($GUIque,13)
GUICtrlSetFont($GUIa,13)
GUICtrlSetFont($GUIb,13)
GUICtrlSetFont($GUIc,13)
GUICtrlSetFont($GUId,13)
GUICtrlSetFont($GUIkey,15)
GUICtrlSetFont($GUItab1,13)
GUICtrlSetFont($GUItab2,13)
GUICtrlSetFont($GUInote,11)
;为窗口设置界面
GUISetState(@SW_SHOW)
While 1
$msg=GUIGetMsg()
Select
Case $msg=$GUIsub
$i=IniRead(@ScriptDir&"\考试题.ini",GUICtrlRead($GUInum),"Key","x")
GUICtrlSetData($GUIkey,$i)
;从考试题库中读取正确答案并设置在提示答案处
;变量 $i 是为了在下面 _YN()函数中对用户的选择进行判断,否则也不用在此建立,就像下面的“答案”提示那样
GUICtrlSetData($GUInote,IniRead(@ScriptDir&'\考试题.ini',$his,"提示","×"))
;$tishi=IniRead(@ScriptDir&"考试题.ini",GUICtrlRead($GUInum),"提示","x")
;GUICtrlSetData($GUInote,$tishi)
;question1:考试题库中的关键字 ”提示“ 内容过多,多行显示,琢磨怎么通过 iniread()函数把它读取呢?
; 其实,在“记事本”中把“自动换行”功能关闭,再多的内容也给它弄成一行
;question2:在脚本中只显示“一行提示内容”?把显示内容的控件高度增加就OK了,哎!
_YN()
Case $msg=$GUInext
$his=$his+1
GUICtrlSetData($GUIkey,$key)
GUICtrlSetData($GUInote,$note)
GUICtrlSetBkColor($GUIkey,-1);去除“醒目”的背景色
_GUIset()
Case $msg=$GUIbefore
$his=$his-1
GUICtrlSetData($GUIkey,$key)
GUICtrlSetData($GUInote,$note)
GUICtrlSetBkColor($GUIkey,-1)
;question:一直减下去,会出负数,不妥?141111
If $his < 1 Then
$his=1
MsgBox(0,"请注意","目前已经回到第1题")
endif
_GUIset()
Case $msg=$GUIgo
$his=GUICtrlRead($GUIinput)
_GUIset()
Case $msg=$GUI_EVENT_CLOSE
IniWrite(@ScriptDir&"\考试题.ini","His","Num",$his);记忆用户上次答题的位置
ExitLoop
EndSelect
WEnd
GUIDelete()
Func _YN()
GUICtrlSetBkColor($GUIkey,-1);在提示答案处设置背景颜色
$a = BitAnd(GUICtrlRead($GUIa),$GUI_CHECKED)
$b = BitAnd(GUICtrlRead($GUIb),$GUI_CHECKED)
$c = BitAnd(GUICtrlRead($GUIc),$GUI_CHECKED)
$d = BitAnd(GUICtrlRead($GUId),$GUI_CHECKED)
;以上是判读哪个答案被选中了
If $i = "A" And $a <> 1 Then;如果题库给定答案与用户的选择不一致,则在答案提示处设置醒目颜色给以警示
GUICtrlSetBkColor($GUIkey,0xFF1E1E)
ElseIf $i = "B" And $b <> 1 Then
GUICtrlSetBkColor($GUIkey,0xFF1E1E)
ElseIf $i = "C" And $c <> 1 Then
GUICtrlSetBkColor($GUIkey,0xFF1E1E)
ElseIf $i = "D" And $d <> 1 Then
GUICtrlSetBkColor($GUIkey,0xFF1E1E)
EndIf
EndFunc ;==>_YN
Func _GUIset()
GUICtrlSetData($GUInum,$his);默认题号是 $his 的最初设置值
GUICtrlSetData($GUIque,IniRead(@ScriptDir&'\考试题.ini',$his,"问题","×"))
GUICtrlSetData($GUIa,IniRead(@ScriptDir&'\考试题.ini',$his,"SelectA","×"))
GUICtrlSetData($GUIb,IniRead(@ScriptDir&'\考试题.ini',$his,"SelectB","×"))
GUICtrlSetData($GUIc,IniRead(@ScriptDir&'\考试题.ini',$his,"SelectC","×"))
GUICtrlSetData($GUId,IniRead(@ScriptDir&'\考试题.ini',$his,"SelectD","×"))
$GUIpiccheck=IniRead(@ScriptDir&"\考试题.ini",$his,"ImagePath","")
If $GUIpiccheck="" Then
GUICtrlSetState($GUIpic,$GUI_HIDE)
Else
$GUIpic=GUICtrlCreatePic($GUIpiccheck,350,100,300,194)
;GUICtrlSetImage($GUIpic,$GUIpiccheck)
EndIf
;设置进入界面显示哪道题
;此处不需照猫画虎:GUICtrlSetData($GUInote,IniRead(@ScriptDir&'\考试题.ini',$his,"提示","×"))
EndFunc ;==>_GUIset