clsLanguagePack.cls
上传用户:bcdefg2008
上传日期:2013-02-28
资源大小:144k
文件大小:7k
源码类别:

Email服务器

开发平台:

Visual Basic

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsLanguagePack"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. ' Just to save the current pack loaded
  16. Public sCurrentFile As String
  17. ' It saves the properties of objects
  18. Private Type ObjectProperties
  19.   Name As String
  20.   Caption As String
  21.   ToolTip As String
  22. End Type
  23. ' It saves the properties of forms
  24. Private Type FormProperties
  25.   Name As String
  26.   Caption As String
  27.   ObjectCount As Integer
  28.   ObjProp() As ObjectProperties
  29. End Type
  30. ' The variable that saves the properties and the variable that saves the number of forms
  31. Private FormProp() As FormProperties
  32. Private iFormCount As Integer
  33. ' It loads the entire language pack
  34. Sub LoadLanguagePack(sFile As String)
  35.   ' Just some variables
  36.   Dim sLine As String, iPos As Integer, sTmp As String
  37.   Dim sFormName As String, sTmp2 As String
  38.   Dim bFormFound As Boolean
  39.   ' Set the current pack used and set the nuber of forms to 0
  40.   sCurrentFile = sFile
  41.   iFormCount = 0
  42.   ' Open the language pack file
  43.   Open sFile For Input As #1
  44.     Do
  45.       ' Get a line
  46.       Input #1, sLine
  47.       ' If the line starts with ; it is a comment line
  48.       ' If the line is a blank line then go to next line
  49.       If Left$(sLine, 1) = ";" Or sLine = "" Then GoTo Jump
  50.       ' End of form objects and properties
  51.       If Left$(sLine, 1) = "[" And Right$(sLine, 5) = ".End]" Then
  52.         bFormFound = False: GoTo Jump
  53.       End If
  54.       ' Begin of form objects and properties
  55.       If Left$(sLine, 1) = "[" And Right$(sLine, 1) = "]" Then
  56.         bFormFound = True
  57.         sFormName = Mid$(sLine, 2, Len(sLine) - 2)
  58.         iFormCount = iFormCount + 1
  59.         ReDim Preserve FormProp(iFormCount)
  60.         FormProp(iFormCount).Name = sFormName: GoTo Jump
  61.       End If
  62.       ' Form Caption found
  63.       If Left$(sLine, 7) = "Caption" Then
  64.         sTmp = Mid$(sLine, InStr(sLine, "=") + 2)
  65.         FormProp(iFormCount).Caption = Left$(sTmp, Len(sTmp) - 1)
  66.         GoTo Jump
  67.       End If
  68.       ' Verify if it's the caption properties of the object
  69.       iPos = InStr(sLine, ".Caption")
  70.       ' Caption was found
  71.       If iPos > 0 And bFormFound Then
  72.         FormProp(iFormCount).ObjectCount = FormProp(iFormCount).ObjectCount + 1
  73.         ReDim Preserve FormProp(iFormCount).ObjProp(FormProp(iFormCount).ObjectCount)
  74.         sTmp = Left$(sLine, iPos - 1)
  75.         FormProp(iFormCount).ObjProp(FormProp(iFormCount).ObjectCount).Name = sTmp
  76.         sTmp = Mid$(sLine, InStr(sLine, "=") + 2)
  77.         ' It verifys if VB got the entire line
  78.         ' The command Input #1, sLine gets a line
  79.         ' but if it has a ',' then VB thinks that
  80.         ' it is another line. Strange.
  81.         ' (Chr$(34) = '"' (comma I think))
  82.         If Right$(sTmp, 1) <> Chr$(34) Then
  83.           Do While Right$(sTmp, 1) <> Chr$(34)
  84.             Input #1, sTmp2
  85.             sTmp = sTmp & ", " & sTmp2
  86.           Loop
  87.         End If
  88.         If Right$(sTmp, 1) = Chr$(34) Then sTmp = Left$(sTmp, Len(sTmp) - 1)
  89.         ' Set the propertie
  90.         FormProp(iFormCount).ObjProp(FormProp(iFormCount).ObjectCount).Caption = sTmp
  91.         GoTo Jump
  92.       End If
  93.       ' Verify if it is a ToolTipText
  94.       iPos = InStr(sLine, ".ToolTip")
  95.       If iPos > 0 And bFormFound Then
  96.         sTmp = Left$(sLine, iPos - 1)
  97.         FormProp(iFormCount).ObjProp(FormProp(iFormCount).ObjectCount).Name = sTmp
  98.         sTmp = Mid$(sLine, InStr(sLine, "=") + 2)
  99.         ' This is the same thing in the Caption
  100.         ' propertie above.
  101.         If Right$(sTmp, 1) <> Chr$(34) Then
  102.           Do While Right$(sTmp, 1) <> Chr$(34)
  103.             Input #1, sTmp2
  104.             sTmp = sTmp & ", " & sTmp2
  105.           Loop
  106.         End If
  107.         If Right$(sTmp, 1) = Chr$(34) Then sTmp = Left$(sTmp, Len(sTmp) - 1)
  108.         ' Set the propertie
  109.         FormProp(iFormCount).ObjProp(FormProp(iFormCount).ObjectCount).ToolTip = sTmp
  110.         GoTo Jump
  111.       End If
  112.       
  113. Jump:
  114.     ' Loop until End Of File
  115.     Loop Until EOF(1)
  116.   ' Close the pack
  117.   Close #1
  118. End Sub
  119. ' As the name said, set the language pack in the form
  120. Sub SetLanguageInForm(frmForm As Form)
  121.   
  122.   On Local Error Resume Next
  123.   Dim I As Integer, j As Integer
  124.   Dim iForm As Integer
  125.   
  126.   ' It gets the index of the choosen form
  127.   For I = 1 To iFormCount
  128.     If FormProp(I).Name = frmForm.Name Then
  129.       iForm = I
  130.       Exit For
  131.     End If
  132.   Next I
  133.   
  134.   ' Set the caption of the form
  135.   frmForm.Caption = FormProp(iForm).Caption
  136.   ' Set the caption and tooltiptext of each control
  137.   For j = 1 To FormProp(iForm).ObjectCount
  138.     frmForm.Controls(FormProp(iForm).ObjProp(j).Name).Caption = FormProp(iForm).ObjProp(j).Caption
  139.     'Debug.Print FormProp(iForm).ObjProp(j).Caption
  140.     frmForm.Controls(FormProp(iForm).ObjProp(j).Name).ToolTipText = FormProp(iForm).ObjProp(j).ToolTip
  141.   Next j
  142.   
  143. End Sub
  144. ' Enumerate Language packs in the choosen folder
  145. Function EnumLanguagePacks(sFolder As String, sExtension As String) As String
  146.   ' Verify if the folder exists
  147.   If Not DirExists(sFolder) Then
  148.     MsgBox sFolder & " doesn't exist.", vbCritical
  149.     Exit Function
  150.   End If
  151.   
  152.   Dim sTmp As String
  153.   
  154.   ' Scan for language pack files
  155.   If Right$(sFolder, 1) <> "" Then sFolder = sFolder & ""
  156.   sTmp = Dir$(sFolder & sExtension)
  157.   If sTmp <> "" Then
  158.     EnumLanguagePacks = sTmp
  159.     sTmp = Dir$
  160.     While Len(sTmp) > 0
  161.       EnumLanguagePacks = EnumLanguagePacks & "|" & sTmp
  162.       DoEvents
  163.       sTmp = Dir$
  164.     Wend
  165.   End If
  166. End Function
  167. ' This function verify if the choosen dir exists
  168. ' Returns True if the dir exists and False if it doesn't exist
  169. Private Function DirExists(ByVal strDirName As String) As Integer
  170.     Const strWILDCARD$ = "*.*"
  171.     Dim strDummy As String
  172.     On Error Resume Next
  173.     If Right$(strDirName, 1) <> "" Then strDirName = strDirName & ""
  174.     strDummy = Dir$(strDirName & strWILDCARD, vbDirectory)
  175.     DirExists = Not (strDummy = vbNullString)
  176.     Err = 0
  177. End Function
  178. ' ////////////////////////////////////////////////////////
  179. ' // Same subs and function, but in Portuguese (Brazil) //
  180. ' ////////////////////////////////////////////////////////
  181. Sub CarregaPacotedeLinguagem(sArquivo As String)
  182.   
  183.   LoadLanguagePack sArquivo
  184.   
  185. End Sub
  186. Sub SetaLinguagemnoForm(frmForm As Form)
  187.   SetLanguageInForm frmForm
  188. End Sub
  189. Function EnumeraPacotesdeLinguagem(sDiretorio As String, sExtensao As String) As String
  190.   
  191.   EnumLanguagePacks sDiretorio, sExtensao
  192.   
  193. End Function