[VB6] 多語系程式

這篇是當時在 VBQA 上回覆的,VBQA已經關站好幾年了,目前備份檔可在小紀的 VB 入門網找到。小紀那邊這篇的網址:
看文之前,微軟的範例與建議是採用資源檔來處理,不過每個人有不同的喜好,我個人偏向翻譯讓使用者去搞,所以當時才會這樣做。

發言者: crystaldn 時間: 2003/2/26 下午 05:15:20 來自: 61.144.16.182

請各位前輩幫忙,
小弟想做一個能選擇切換中文,英語,中文繁體語言顯示的程式,就是能改變控制項的標簽。
可是如果表單中有text控制項就會出錯,因爲text沒有caption屬性,請問如下程式如何才能
跳過text,以及其他沒caption屬性的控制項。
還有,雖然menu有caption屬性,可是不支援修改,又應該如何改。


發言者: [我] 時間: 2003/2/27 上午 12:21:40 來自: 61.219.36.27

說明沒空寫…
———————————————————
for a lot of elements:
Public Function LoadFormText(ByVal hForm As Object, ByVal strFileName As String)
strSection = TypeName(hForm)
LoadElementText hForm, strFileName, strSection
SetElementProperty hForm, strFileName, strSection, “Caption"
For Each elements In hForm
LoadElementText elements, strFileName, strSection
Next
End Function
Private Function LoadElementText(ByVal hObject As Object, ByVal strFileName As String, ByVal strSection As String, Optional ByVal strObject As String)
strType = TypeName(hObject)
Select Case LCase(strType)
Case “label", “menu", “commandbutton"
SetElementProperty hObject, strFileName, strSection, “Caption"
Case “textbox"
SetElementProperty hObject, strFileName, strSection, “Text"
Case “ibutton"
SetElementProperty hObject, strFileName, strSection, “Caption", strObject
SetElementProperty hObject, strFileName, strSection, “Description", strObject
Case “ipanel"
SetElementProperty hObject, strFileName, strSection, “Text", strObject
Case “statusbar"
With hObject
For i = 1 To .Panels.Count
LoadElementText .Panels(i), strFileName, strSection, .Name & “."
Next
End With
Case “toolbar"
With hObject
For i = 1 To .Buttons.Count
LoadElementText .Buttons(i), strFileName, strSection, .Name & “."
Next
End With
Case Else
End Select
SetElementProperty hObject, strFileName, strSection, “ToolTipText", strObject
End Function
Private Function SetElementProperty(ByVal hObject As Object, ByVal strFileName As String, ByVal strSection As String, ByVal strProperty As String, Optional ByVal strObject As String)
On Error Resume Next
strObjName = hObject.Name
If Err.Number <> 0 Then
strType = TypeName(hObject)
Select Case LCase(strType)
Case “ipanel"
strObjName = “Panels"
Case “ibutton"
strObjName = “Buttons"
Case “app"
strObjName = “App"
End Select
End If
Err.Clear
nIndex = hObject.Index
If Err.Number = 0 Then
strItem = strObjName & “(" & nIndex & “)."
Else
strItem = strObjName & “."
End If
Err.Clear
On Error GoTo 0
strItem = strObject & strItem & strProperty
strRead = myGetPrivateProFileString(strSection, strItem, “", strFileName)
If strRead <> “" Then
SetElementProperty = CallByName(hObject, strProperty, VbLet, strRead)
End If
End Function
——————————————
Data File [xxx.ini]
——————————————
[frmBasicGIS]
frmBasicGIS.Caption=frmBasicGIS
tbrView.Buttons(1).ToolTipText=Select
tbrView.Buttons(3).ToolTipText=Zoom In
tbrView.Buttons(4).ToolTipText=Zoom Out
tbrView.Buttons(5).ToolTipText=Fitting Window
tbrView.Buttons(7).ToolTipText=Layers Options
txtXYCoor.Text=Now Locate of Coordinate
txtXYCoor.ToolTipText=Mouse Locate of Coordinate
[Message]
1001=Watershed Polygon
1002=Triangulated Irregular Networks(TIN)
1003=Center Point of Elevation of TIN


發言者: [我] 時間: 2003/2/27 上午 12:25:54 來自: 61.219.36.32

漏了有 menu 的樣本…
———————————–
[FormTableGrid]
FormTableGrid.Caption=Table of Network Set
mnuTableFileMain.Caption=&File
mnuTableFileOpen.Caption=&Open…
mnuTableFileSave.Caption=&Save…
mnuTableFileSaveAs.Caption=Save &As…
mnuTableFileClose.Caption=&Close
mnuTableOptionsMain.Caption=&Options
mnuTableOptionsRowMain.Caption=&Row
mnuTableOptionsRowAuto.Caption=&Auto Fitting Height
mnuTableOptionsColMain.Caption=&Column
mnuTableOptionsColAuto.Caption=&Auto Fitting Width
mnuTableWindowMain.Caption=&Window
mnuTableWindowCascade.Caption=Arrange &Cascade
mnuTableWindowTile.Caption=Arrange &Tile
mnuTableWindowArrange.Caption=Arrange &Icons
mnuTableHelpMain.Caption=&Help
mnuTableHelpContents.Caption=&Contents…
mnuTableHelpAbout.Caption=&About…
mnuPopup.Caption=Popup Menu
mnuTableDrawPolyline.Caption=Draw &Polyline
mnuPopupCopy.Caption=&Copy
———————————
直接用物件名,省得麻煩,另有存檔函數,以利翻譯使用
若需存檔函數,請提需求,再補貼


另外抓目前系統預設語系的函數:

Categories: 技術分享 | 發表留言

文章導覽

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

在 WordPress.com 建立免費網站或網誌.

%d 位部落客按了讚: