Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of implementing MUI programs with VB6

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This issue of the content of the editor will bring you about VB6 to achieve MUI program method is how, the article is rich in content and professional point of view for everyone analysis and description, after reading this article I hope you can get something.

What is described in detail for you is the method of implementing MUI programs in VB6. I hope this article can bring some enlightenment to your daily development work.

Previously, I was in charge of an office automation system written by VB6, which required the ability to switch between different languages at runtime (English, Chinese, Japanese, German, French and Spanish). The essence is to implement a VB6 MUI program.

The difficulty is that the standard controls for displaying text in VB6 (Label,Textbox, etc.) do not support Unicode;, but strings are saved as Unicode internally, that is to say, VB6 itself supports Unicode.

In VB6, the process for standard controls to display strings is as follows:

1) Standard controls convert Unicode strings to ANSI strings first

2) the standard control attempts to convert an ANSI string to a string in the character set format specified in its Font.Charset property; if the conversion fails, it is displayed as a question mark.

For more information, please refer to Display Unicode Strings in Visual Basic 6.0.

Therefore, there are two ways to implement MUI programs:

1) replace the standard control with one that supports Unicode

2) convert the text of different character sets in the resource file to ANSI format and provide it to standard controls for use

1) Forms 2.0 (fm20.dll) is available for this method

In the second way, I found two articles on the Internet, but each had its own shortcomings:

A) Auto-Detect Language and Display Unicode in VB6 TextBox and Label Controls

ChilkatCharset2 control needs to be purchased, with some Japanese punctuation marks (such as full-width period) does not support.

B) How To Convert from ANSI to Unicode & Unicode to ANSI for OLE

The test was not successful.

Next, I focus on what I consider to be a successful implementation, which uses ADODB.Stream (msado25.tlb); the idea of its implementation is as follows:

1) Save the text used in the program to a resource file in Unicode format

Saving resource text in double-byte Unicode format instead of Utf8 or Utf7 format can save the conversion process from other formats to Unicode format supported by VB6.

2) set the Font.Charset of the standard control that displays the text to the character set corresponding to the language that the program wants to display, and set a font to Font.Name attribute that supports this character set.

If g_Str.NumJapanese > 0 Then charset = "Shift_JIS" Text1.Font.Name = "MS UI Gothic" Text1.Font.charset = 128ElseIf g_Str.NumKorean > 0 Then charset = "ks_c_5601-1987" Text1.Font.Name = "GulimChe" Text1.Font.charset = 129ElseIf g_Str.NumCentralEuro > 0 Then charset = "windows-1250" Text1. Font.Name = "Arial" Text1.Font.charset = 238 ElseIf g_Str.NumArabic > 0 Then charset = "windows-1256" Text1.Font.Name = "Traditional Arabic" Text1.Font.charset = 178ElseIf g_Str.NumHebrew > 0 Then charset = "windows-1255" Text1.Font.Name = "David" Text1.Font.charset = 177ElseIf g_Str.NumCyrillic > 0 Then Charset = "windows-1251" Text1.Font.Name = "Arial" Text1.Font.charset = 204ElseIf g_Str.NumGreek > 0 Then charset = "windows-1253" Text1.Font.Name = "Arial" Text1.Font.charset = 161ElseIf g_Str.NumThai > 0 Then charset = "windows-874" Text1.Font.Name = "Angsana New" Text1.Font.charset ElseIf g_Str.NumChinese > 0 Then charset = "gb2312" Text1.Font.Name = "SimSun" Text1.Font.charset = 134' An alternative is to use Big5: 'Text1.Font.Name = "MingLiu"' charset = "big5" 'fontCh = 136Else charset = "windows-1252" Text1.Font.charset = 0 Text1.Font.Name = "Arial" End If

3) according to the language to be displayed, use ADODB.Stream to convert the string saved in Unicode format in the resource file into the string supported by the operating system's regional language (Locale).

'call API to get the operating system default locale setting (LocaleID) Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long "converts the Unicode string into a byte array of the specified character set;' is used to convert the text read in the resource file Public Function ConvertStringToBytes (ByRef strText As String Charset As String) As Byte () Dim objStream As ADODB.Stream Dim data () As Byte 'init stream Set objStream = New ADODB.Stream objStream.charset = charset objStream.Mode = adModeReadWrite objStream.Type = adTypeText objStream.Open' write bytes into stream objStream.WriteText strText objStream.Flush 'rewind stream and read text objStream .position = 0 objStream.Type = adTypeBinary 'objStream.Read 3' skip first 3 bytes as this is the utf-8 marker data = objStream.Read () 'close up and return objStream.Close ConvertStringToUtf8Bytes = data End Function' converted to a byte array of the specified character set A string converted to the character set corresponding to ANSI (that is, LocaleID) 'convert the byte array returned by ConvertStringToBytes () to a string of the GetCharset () character set. Public Function ConvertBytesToString (ByRef data () As Byte) Charset As String) As String Dim objStream As ADODB.Stream Dim strTmp As String 'init stream Set objStream = New ADODB.Stream objStream.charset = charset objStream.Mode = adModeReadWrite objStream.Type = adTypeBinary objStream.Open' write bytes into stream objStream.Write data objStream.Flush 'rewind stream and read text objStream.Position = 0 ObjStream.Type = adTypeText strTmp = objStream.ReadText 'close up and return objStream.Close ConvertUtf8BytesToString = strTmp End Function' get the character set corresponding to the default regional language of the operating system Public Function GetCharset () As String Dim localeId As Long Dim charset As String 'get the LocaleId localeId = GetSystemDefaultLCID () Select Case localeId of the operating system Case 1033 charset = "windows-1252" Case 2052 charset = "gb2312" Case 1041 charset = "Shift_JIS" Case Else charset = "windows-1252" End Select GetCharset = charset End Function 'display the text Private Sub DisplayText (filename As String) in the resource text 'The variable Dim textBytes As Variant Dim f As New FileSystemObject Dim fs As TextStream that holds the text in the resource text 'reads the Unicode text into the variable Set fs = f.OpenTextFile (filename ForReading, False, TristateTrue) Do While Not fs.AtEndOfStream textBytes = fs.ReadAll Loop fs.Close 'Convert to a Unicode string: Dim s As String s = textBytes Dim t As Long' CkString is a free third-party component It can automatically determine the character set corresponding to a string 'download address: http://www.chilkatsoft.com/download/CkString.zip Dim g_Str As New CkString g_Str.Str = s' to get the character set name represented by the resource text. Set the corresponding font and character set to textbox Dim charset As String If g_Str.NumJapanese > 0 Then 'Japanese charset = "Shift_JIS" Text1.Font.Name = "MS UI Gothic" Text1.Font.charset = 128ElseIf g_Str.NumKorean > 0 Then' Korean charset = "ks_c_5601-1987" Text1.Font.Name = " GulimChe "Text1.Font.charset = 129ElseIf g_Str.NumCentralEuro > 0 Then 'Central European charset =" windows-1250 "Text1.Font.Name =" Arial "Text1.Font.charset = 238 ElseIf g_Str.NumArabic > 0 Then' Arabic charset =" windows-1256 "Text1.Font.Name =" Traditional Arabic " Text1.Font.charset = 178ElseIf g_Str.NumGreek > 0 Then 'Greek charset = "windows-1253" Text1.Font.Name = "Arial" Text1.Font.charset = 161ElseIf g_Str.NumThai > 0 Then' Thai charset = "windows-874" Text1.Font.Name = "Angsana New" Text1.Font.charset = 222ElseIf g_Str.NumChinese > 0 Then 'Chinese charset = "gb2312" Text1.Font.Name = "SimSun" Text1.Font.charset = 134' traditional use Big5:' Text1.Font.Name = "MingLiu" 'charset = "big5"' Text1.Font.charset = 136Else 'default value charset = "windows-1252" Text1.Font.charset = 0 Text1.Font.Name = "Arial" End If Dim bytes () As Byte Dim g_OSCharset As String 'get the character set corresponding to the operating system default language g_OSCharset = GetCharset ()' first convert the Unicode resource text into the corresponding byte array Bytes = ConvertStringToBytes (s, charset) 'convert the byte array into the string corresponding to ANSI (that is, the default character set) vbstr2 = ConvertBytesToString (bytes, g_OSCharset)' set the string to the standard control of VB6 Me.Text1.Text = vbstr2 End Sub above is how the Xiaobian shares the method of realizing MUI program for everyone. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report