模块 MdlLanMgr.bas : Attribute VB_Name = "ModuleLanMgr" Option Explicit Private Declare Function GetPrivateProfileString& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) Private LanguageFileName As String '选择语言 Public Sub SelectLanguage(LanName As String) On Error Resume Next Select Case LanName '根据用户选择的语言的名称,分别读取不同的语言文件 Case "English": LanguageFileName = AddSplash(App.Path) & "English.Lan" Case "Chinese(Simplify)": LanguageFileName = AddSplash(App.Path) & "ChineseS.Lan" Case "Chinese(Traditional)": LanguageFileName = AddSplash(App.Path) & "ChineseT.Lan" Case Else: LanguageFileName = "" End Select End Sub '翻译文字 Public Function TranslateStr(sSection As String, sKey As String, sDefVal As String) As String Dim sValue As String * 128 Dim N As Long On Error Resume Next TranslateStr = sDefVal If Not FileExists(LanguageFileName) Then Exit Function End If N = GetPrivateProfileString(sSection, sKey, sDefVal, sValue, 127, LanguageFileName) If N > 0 Then TranslateStr = Left(sValue, N) End If End Function '自动转换Form上的一些基本控件(也可自行扩展,目前支持CommandButton,Label,OptionButton,CheckButton) Public Sub TranslateForm(Frm As Form) Dim I As Long On Error Resume Next Frm.Caption = TranslateStr(Frm.Name, "Caption", Frm.Caption) For I = 0 To Frm.Controls.Count - 1 If (TypeOf Frm.Controls(I) Is CommandButton) Or (TypeOf Frm.Controls(I) Is Label) _ Or (TypeOf Frm.Controls(I) Is OptionButton) Or (TypeOf Frm.Controls(I) Is CheckBox) Then Frm.Controls(I).Caption = TranslateStr(Frm.Name, Frm.Controls(I).Name, Frm.Controls(I).Caption) End If Next I End Sub |