3

我在 VB6 应用程序中显示日语字符,系统区域设置为日本,非 Unicode 程序的语言为日语。对 GetACP() 的调用正确返回日语的 932。当我将日语字符串插入我的控件时,它们显示为“ƒAƒtƒŠƒJ‚Ì—‰¤”而不是“アフリカの女王”。如果我手动将 Font.Charset 设置为 128,那么它们会正确显示。

在 VB6 中确定给定 LCID 的正确字符集的最佳方法是什么?

4

3 回答 3

2

请参阅http://www.microsoft.com/globaldev/drintl/columns/014/default.mspx#E5B

于 2008-12-25T06:17:48.760 回答
2

扩展 Bob 的答案,这里有一些代码来获取当前的默认字符集。

Private Const LOCALE_SYSTEM_DEFAULT As Long = &H800
Private Const LOCALE_IDEFAULTANSICODEPAGE As Long = &H1004
Private Const TCI_SRCCODEPAGE = 2

Private Type FONTSIGNATURE
    fsUsb(4) As Long
    fsCsb(2) As Long
End Type

Private Type CHARSETINFO
    ciCharset As Long
    ciACP As Long
    fs As FONTSIGNATURE
End Type

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 TranslateCharsetInfo Lib "GDI32" ( _
    lpSrc As Long, _
    lpcs As CHARSETINFO, _
    ByVal dwFlags As Long _
) As Long

Public Function GetCharset() As Long
On Error GoTo ErrorHandler

    Dim outlen As Long
    Dim lCodepage As Long
    Dim outBuffer As String
    Dim cs As CHARSETINFO

    outBuffer = String$(10, vbNullChar)
    outlen = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, outBuffer, Len(outBuffer))

    If outlen > 0 Then
        lCodepage = val(Left$(outBuffer, outlen - 1))

        If TranslateCharsetInfo(ByVal lCodepage, cs, TCI_SRCCODEPAGE) Then
            GetCharset = cs.ciCharset
        End If
    End If

    Exit Function

ErrorHandler:
    GetCharset = 0
End Function
于 2009-06-02T14:19:09.383 回答
1

第二种最佳方法是使用字体数据库、font.charsets 和启发式算法,如下所示:

http://www.example-code.com/vb/vb6-display-unicode.asp

最好的办法是下沉船VB6)

于 2008-12-18T13:16:54.960 回答