该怎么讲解还没想清楚,先发代码,希望大家可以看明白。
附件中含有这两个例子。
例1.au3
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1);OnEvent模式
Global $Button[4][2], $Form1;定义主窗体和按钮
$Form1 = GUICreate("主窗体", 300, 35, 20, 5)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Local $Total = IniReadSection("例1.ini", "1")
For $I = 1 To $Total[0][0]
$Button[$I][0] = GUICtrlCreateButton($Total[$I][0], 60*$I, 2, 60, 30)
;~ 按钮文字为INI等号左边的值,$Button[$I][0]为按钮控件ID
$Button[$I][1] = $Total[$I][1];
;~ $Button[$I][1] 为INI等号右边的值,即要运行的程序。
GUICtrlSetOnEvent($Button[$I][0], "B_Msg")
;~ 将按钮点击注册到函数 B_Msg()
Next
GUISetState()
While 1
Sleep(1000)
WEnd
Func B_Msg()
For $i = 1 To UBound($Button, 1) - 1
If @GUI_CtrlId = $Button[$I][0] Then Run($Button[$I][1])
;~ 如果点下了$Button[$I][0],运行$Button[$I][1](即INI等号右边的值)
Next
EndFunc ;==>B_Msg
Func _Exit()
Exit
EndFunc
例1.ini 内容
[1]
1 记事本=C:\WINDOWS\system32\Notepad.exe
2 画 图=C:\WINDOWS\system32\mspaint.exe
3 计算器=C:\WINDOWS\system32\calc.exe
例2.au3
Local $RegKey[9][6] = _
[["HKCU\Software\Au3_Array_Test", "Test1", "REG_DWORD", "0", "1", "2"], _
["HKCU\Software\Au3_Array_Test", "Test2", "REG_DWORD", "0", "1", "2"], _
["HKCU\Software\Au3_Array_Test", "Test3", "REG_DWORD", "0", "1", "2"], _
["HKCU\Software\Au3_Array_Test", "Test4", "REG_DWORD", "0", "1", "2"], _
["HKCU\Software\Au3_Array_Test", "Test5", "REG_DWORD", "0", "1", "2"], _
["HKCU\Software\Au3_Array_Test", "Test6", "REG_DWORD", "0", "1", "2"], _
["HKCU\Software\Au3_Array_Test", "Test7", "REG_DWORD", "0", "1", "2"], _
["HKCU\Software\Au3_Array_Test", "Test8", "REG_DWORD", "0", "1", "2"], _
["HKCU\Software\Au3_Array_Test", "Test9", "REG_DWORD", "0", "1", "2"]]
Local $QS = MsgBox(3, "二维数组应用:写注册表项", "创建值为1的项?")
For $I = 0 To 8
If $QS = 6 Then;“是”
RegWrite($RegKey[$I][0], $RegKey[$I][1], $RegKey[$I][2], $RegKey[$I][3]);写入值“0”
ElseIf $QS = 7 Then;“否”
RegWrite($RegKey[$I][0], $RegKey[$I][1], $RegKey[$I][2], $RegKey[$I][4]);写入值“1”
Else;“取消”
RegWrite($RegKey[$I][0], $RegKey[$I][1], $RegKey[$I][2], $RegKey[$I][5]);写入值“2”
EndIf
Next
MsgBox(0,0,"创建完成,确认后将删除刚才试验用的注册表项")
RegDelete("HKCU\Software\Au3_Array_Test")
[ 本帖最后由 漠北雪~狼 于 2009-3-13 21:17 编辑 ] |