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

发布于 2024-07-10 08:02:07 字数 232 浏览 4 评论 0原文

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

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

I am displaying Japanese characters in a VB6 application with the system locale set to Japan and the language for non Unicode programs as Japanese. A call to GetACP() correctly returns 932 for Japanese. When I insert the Japanese strings into my controls they display as “ƒAƒtƒŠƒJ‚Ì—‰¤” rather than “アフリカの女王”. If I manually set the Font.Charset to 128 then they display correctly.

What is the best way to determine the correct Charset for a given LCID in VB6?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮光之海 2024-07-17 08:02:07

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

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

Expanding Bob's answer, here's some code to get the current default charset.

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
听风念你 2024-07-17 08:02:07

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

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

最好的方法是下车沉船即VB6)

The second best way is to use a database of fonts, font.charsets, and heuristics, such as is done here:

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

(The best way is to get off the sinking ship that is VB6)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文