|
Tweet
|
wwnavi_string.rc
...
#pragma code_page(1252)
STRINGTABLE
BEGIN
101 "My Name" // MsgBox ("My Name"), MyClass.cls
102 "Form1" // Caption = "Form1", Form1.frm
103 "MS PGothic" // Name = "MS PGothic", Form1.frm
104 "Button1" // Caption = "Button1", Form1.frm
105 "@Arial Unicode MS" // Name = "@Arial Unicode MS", Form1.frm
106 "Label1" // Caption = "Label1", Form1.frm
107 "Ms Mincho" // Name = "Ms Mincho", Form1.frm
108 "array 1" // strs1(0) = "array 1", Form1.frm
109 "array 2" // strs2(0) = "array 2", Form1.frm
110 "Hello, how are you? This is sample for Windows DLL." // MsgBox ("Hello, how are you? This is sample for Windows DLL."), Form1.frm
111 "this is simple text." // msg = "this is simple text.", Module1.bas
112 "This is message 2." // MsgBox ("This is message 2."), Module1.bas
END
*コードページとファイルのエンコーディングは対応している必要があります。
Private Declare Function GetThreadLocale Lib "kernel32" () As Long Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" _ (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, _ ByVal cchData As Long) As Long Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _ (ByVal lpLibFileName As String) As Long Private Declare Function LoadString Lib "user32" Alias "LoadStringA" _ (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, _ ByVal nBufferMax As Long) As Long Private Const LOCALE_IDEFAULTANSICODEPAGE = &H1004& Private Const LOCALE_SISO639LANGNAME = &H59GetThreadLocale, GetUserDefaultLCID ... 現在のロケールを取得
MsgBox (wwnaviGetString(110))
...
Function WwnaviGetString(id As Long) As String
Dim buf As String * 512
Dim rslt As Long
rslt = LoadString(wwnaviH, id, buf, 512)
WwnaviGetString = buf
End Function
wwnaviH ... DLLモジュールへのポインタ(後述)
Private wwnaviH As Long
Function WwnaviLoadLibrary() As Long
Dim libName As String
Dim langName As String * 10
Dim langName2 As String
Dim lcId As Long
Dim rslt As Long
Dim posNull As Long
Dim cnt As Integer
Dim i As Integer
'lcId = GetThreadLocale()
lcId = GetUserDefaultLCID()
rslt = GetLocaleInfo(lcId, LOCALE_SISO639LANGNAME, langName, 10)
posNull = InStr(langName, Chr$(0))
langName = Left$(langName, posNull - 1)
langName2 = ""
cnt = Len(langName)
For i = 1 To cnt
If Mid(langName, i, 1) <> " " Then
langName2 = langName2 & Mid(langName, i, 1)
End If
Next i
libName = "./" & langName2 & "/wwnavi_string_VBTest.dll"
wwnaviH = LoadLibrary(libName)
If wwnaviH = 0 Then
wwnaviH = LoadLibrary("./wwnavi_string_VBTest.dll")
End If
WwnaviLoadLibrary = wwnaviH
End Function
Function WwnaviGetModule() As Long
WwnaviGetModule = wwnaviH
End Function
Function WwnaviGetString(id As Long) As String
Dim buf As String * 512
Dim rslt As Long
If WwnaviGetModule() = 0 Then
WwnaviLoadLibrary(*1)
End If
rslt = LoadString(wwnaviH, id, buf, 512)
WwnaviGetString = buf
End Function
wwnaviH ... DLLモジュールへのポインタ
Form1.frm
...
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1530
...
BeginProperty Font
Name = "MS PGothic" (*1)
Size = 8.25
...
Private Sub Form_Load()
WwnaviSetCaption
End Sub
Private Sub WwnaviSetCaption()
Form1.Caption = wwnaviGetString(102) ' "Form1"
'Form1.Font.Name = "Lucida Sans Unicode"
Form1.Font.Name = wwnaviGetString(103) (*2) ' "MS PGothic"
Command1.Caption = wwnaviGetString(104) ' "Button1"
'Command1.Font.Name = "Lucida Sans Unicode"
Command1.Font.Name = wwnaviGetString(105) ' "@Arial Unicode MS"
Label1.AutoSize = True
Label1.Font.Charset = WwnaviGetCharSet(WwnaviGetCodePage)
Label1.Caption = wwnaviGetString(106) ' "Label1"
'Label1.Font.Name = "Lucida Sans Unicode"
Label1.Font.Name = wwnaviGetString(107) ' "Ms Mincho"
End Sub
*1)IDEによるデフォルトフォント。これは自動生成されたコードであり、手動で編集できません。
./Foo.exe ... 実行ファイル ./wwnavi_string.rc -> ./wwnavi_string.res -> ./wwnavi_string.dll ... <- * デフォルトDLL ./wwnavi_string_ja.rc -> ./wwnavi_string_ja.res -> ./ja/wwnavi_string.dll ... <- * 日本語DLL