Qual è il modo migliore per determinare il corretto Charset per un dato LCID in fase di esecuzione in VB6?
-
22-08-2019 - |
Domanda
Sto visualizzare i caratteri giapponesi in un'applicazione VB6 con la lingua del sistema impostato in Giappone e la lingua per programmi non Unicode come giapponese. Una chiamata a GetACP () restituisce correttamente 932 per il giapponese. Quando inserisco le stringhe giapponesi nei miei controlli che vengono visualizzati come “ƒAƒtƒŠƒJ,Ì- ‰ ¤” piuttosto che “ア フ リ カ の 女王”. Se fisso manualmente il Font.Charset a 128 poi visualizzati correttamente.
Qual è il modo migliore per determinare il corretto Charset per un dato LCID in VB6?
Soluzione
L'espansione risposta di Bob, ecco qualche codice per ottenere il set di caratteri di default corrente.
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
Altri suggerimenti
Il modo secondo migliore è usare un database di font, font.charsets, ed euristiche, come viene fatto qui:
http://www.example-code.com/vb /vb6-display-unicode.asp
( migliore modo è quello di scendere dalla nave che affonda che è VB6)