vc 读取ini文件,关于INI文件读取

关于INI文件读取 - 故障解答 - 电脑教程网

关于INI文件读取

日期:2006-04-25   荐:
关于INI文件读取我的程序要做两个语言选择界面,一个是简体,一个是繁体。我在程序目录下新建立一个文件夹language,里面有两个INI文件,chs,cht。两个文件里面已经设置了界面要显示的文字信息,是按照INI规范设置的,一对一的关系,就像FLASHGET这个软件的语言包一样。其实我想实现的就是FLASHGET的语言切换功能。现在问题是,我不懂得怎样操作。http://www.mndsoft.com/blog/default.asp我给你找吧以下是我收藏的一个模块,保存为RWini.bas就可以了:'*************************************************************************'**模 块 名:RWini'**说 明:对INI文件进行读写操作'**创 建 人:马大哈'**日 期:2003年10月26日'**修 改 人:'**日 期:'**描 述:'**版 本:'*************************************************************************Option ExplicitPublic Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongPublic Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As LongPublic Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As LongPublic IniFileName As StringFunction GetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal DefString As String) As StringDim ResultString As String * 144, Temp As IntegerDim S As String, I As IntegerTemp% = GetPrivateProfileString(SectionName, KeyWord, "", ResultString, 144, IniFileName)If Temp% > 0 Then S = "" For I = 1 To 144 If Asc(Mid$(ResultString, I, 1)) = 0 Then Exit For Else S = S & Mid$(ResultString, I, 1) End If NextElse Temp% = WritePrivateProfileString(SectionName, KeyWord, DefString, IniFileName) S = DefStringEnd IfGetIniS = SEnd FunctionFunction GetIniN(ByVal SectionName As String, ByVal KeyWord As String, ByVal DefValue As Integer) As IntegerDim D As Long, S As StringD = DefValueGetIniN = GetPrivateProfileInt(SectionName, KeyWord, DefValue, IniFileName)If D <> DefValue Then S = "" & D D = WritePrivateProfileString(SectionName, KeyWord, S, IniFileName)End IfEnd FunctionSub SetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValStr As String)Dim Res%Res% = WritePrivateProfileString(SectionName, KeyWord, ValStr, IniFileName)End SubSub SetIniN(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValInt As Integer)Dim Res%, S$S$ = Str$(ValInt)Res% = WritePrivateProfileString(SectionName, KeyWord, S$, IniFileName)End Sub使用很简单,把IniFileName定义为INI文件名(含路径),再调用这几个函数就行了出处忘了,不好意思,不是有意的.
标签: