让你的VB程序支持多国语言的切换
2006-02-27 21:09:35 来源:WEB开发网模块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
->更多精彩
赞助商链接