很多時候我們編一個程序不一定要用到注冊表來保存設置(如果說一個程序沒有
設置就不算好程序了)。
INI是一個很好的選擇。有人說,Savesetting是一個不錯的選擇,但是我了解到
,不能永久的保存(起碼在系統重裝的時候會丟失)。於是Ini作為一個Windows
配置文件,可以放在本地路徑,優勢就呈現出來。下面討論一下這個問題。
1,模塊:
Declare Function GetPrivateProfileString Lib "Kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String,
lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString As
String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function SaveINI Lib "Kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String)
As Long
Function GetINI(AppName As String, KeyName As String, filename As
String) As String
Dim RetStr As String
RetStr = String(10000, Chr(0))
GetINI = Left(RetStr, GetPrivateProfileString(AppName, ByVal
KeyName, "", RetStr, Len(RetStr), filename))
End Function
2,調用:
讀:Rtn=GetINI(appname, keyname, filename)
寫:SaveINI appname,keyname,string,filename
調用例子:SaveINI "main","FontColor","801085","D:\"
3,參數解釋:
例如INI文件中有這麼一塊:
[main]
FontColor=801085
其中:
main .................是appname
FontColor ..........是KeyName
801085 ...............是String
Filename ............INI的絕對路徑
怎麼,是不是現在可以用INI文件保存你的設置啦。