模塊MdlLanMgr.bas:
AttributeVB_Name="ModuleLanMgr"
OptionExplicit
PrivateDeclareFunctionGetPrivateProfileString&Lib"kernel32"Alias"GetPrivateProfileStringA"(ByVallpApplicationNameAsString,ByVallpKeyNameAsString,ByVallpDefaultAsString,ByVallpReturnedStringAsString,ByValnSizeAsLong,ByVallpFileNameAsString)
PrivateLanguageFileNameAsString
'選擇語言
PublicSubSelectLanguage(LanNameAsString)
OnErrorResumeNext
SelectCaseLanName'根據用戶選擇的語言的名稱,分別讀取不同的語言文件
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"
CaseElse:
LanguageFileName=""
EndSelect
EndSub
'翻譯文字
PublicFunctionTranslateStr(sSectionAsString,sKeyAsString,sDefValAsString)AsString
DimsValueAsString*128
DimNAsLong
OnErrorResumeNext
TranslateStr=sDefVal
IfNotFileExists(LanguageFileName)Then
ExitFunction
EndIf
N=GetPrivateProfileString(sSection,sKey,sDefVal,sValue,127,LanguageFileName)
IfN>0Then
TranslateStr=Left(sValue,N)
EndIf
EndFunction
'自動轉換Form上的一些基本控件(也可自行擴展,目前支持CommandButton,Label,OptionButton,CheckButton)
PublicSubTranslateForm(FrmAsForm)
DimIAsLong
OnErrorResumeNext
Frm.Caption=TranslateStr(Frm.Name,"Caption",Frm.Caption)
ForI=0ToFrm.Controls.Count-1
If(TypeOfFrm.Controls(I)IsCommandButton)Or(TypeOfFrm.Controls(I)IsLabel)_
Or(TypeOfFrm.Controls(I)IsOptionButton)Or(TypeOfFrm.Controls(I)IsCheckBox)Then
Frm.Controls(I).Caption=TranslateStr(Frm.Name,Frm.Controls(I).Name,Frm.Controls(I).Caption)
EndIf
NextI
EndSub
->