以前做过一个vb的小项目,客户需要软件同时能够支持中文和英文,为此写了一个自动语言切换的模块来用,不敢独享,拿来给大家参考一下,如果你有什么改进也可以写信给我。。mailto:tonyki@citiz.net
模块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
->