正在阅读:让你的VB程序支持多国语言的切换让你的VB程序支持多国语言的切换

2004-10-10 15:07 出处:CSDN 作者:tonylk 责任编辑:linjixiong

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



  模块 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


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键
302 Found

302 Found


Powered by Tengine
tengine