How to display Unicode characters in VB6? [duplicate]

女生的网名这么多〃 提交于 2019-11-29 15:18:15

问题


Possible Duplicate:
What’s the best option to display Unicode text (hebrew, etc.) in VB6

What is the correct way to display the unicode character 9646 (BLACK VERTICAL RECTANGLE) in VB6?

When I try ChrW(9646) it displays ?.


回答1:


Here is a tutorial to explore. Take a look at this article for the black vertical rectangle.

Assuming Unicode is turned on, send the following string to a window to display:

Wchar_t mStr[] = {9646,0,0};

Reference. This code snippet and reference is more inlined with C++. Where you would turn off/on UNICODE in Visual C++ using following steps:

  1. Open your project in VS2008/2010;

  2. Right click the project in Solution Explorer and click Properties;

  3. Select Configuration Properties-> General, select Character Set and change the current value to Use Multi-Byte Character Set. (turning off)


Good article aboubt displaying UNICODE in VB.

When you are working with a textbox control in a Form, add the Microsoft Forms 2.0 Object Library as a reference library. This component provides Unicode supportted controls, such as: textbox, label, command button,list box, combo box, checkbox, radio button, toggle button, image, tabstrip, and multiple page control.

Working with VB6 and displaying non-us-ANSI characters you need 3 main things to understand:

  • Internally, VB6 stores strings as Unicode.
  • When displaying a string, the standard VB6 textbox and label controls do an implicit (and internal) conversion from Unicode to ANSI.
  • The standard VB6 textbox and label controls display the ANSI bytes according to a character encoding that you can specify.

After the Unicode-to-ANSI conversion, VB6 then attempts to display the character data according to the control's Font.Charset property, which if left unchanged is equal to the ANSI charset. Changing the control's Font.Charset changes the way VB6 interprets the "ANSI" bytes. In other words, you're telling VB6 to treat the bytes as some other character encoding instead of "ANSI".

For e.g. consider trying to display a Unicode Japanese string on an English computer: You set the Font.Charset = 128 (for Japanese), but your Unicode string displays as all question mark characters. It's because VB6 is first trying to convert your Japanese Unicode string to ANSI, which is Windows-1252 for English computers. Japanese characters are not representable in Windows-1252. Each character fails to convert and is replaced with a question mark. for e.g. Selecting the Japanese script in the TextBox control's property settings is the same as setting the Font.Charset at runtime.

As Jukka said Font plays a vital role showing UNICODEs given the availability of the characters within a Font. As Hans said, glyph unsupported Font produces a rectangle. So you need to make sure the Font you select is capable of rendering glyphs. For e.g. MS Sans Serif font does not render ƒ (LATIN SMALL LETTER F WITH HOOK, 2-byte Unicode value is 0x0192), so you'll see a thin solid rectangular box in its place. However on Windows, there are very few fonts with a wide enough character repertoire to represent Chinese..

In the following code the Font Name () is set during Run Time along the Font CharSet

Charset properties:

134     Simplified Chinese, gb2312 - Mainland China(PRC) and Singapore
136     Traditional Chinese, big5 - Taiwan and Hong Kong

Code:

Sub changeToUniCodes()
Dim strTxt2 As String    

UserForm1.TextBox2.Font.Charset = 134    '--CHINESESIMPLIFIED_CHARSET
UserForm1.TextBox2.Font.Name = ChrW(&H5B8B) + ChrW(&H4F53) '-- 宋体 SimSun font

UserForm1.TextBox2.Text = ChrW(37446)
strTxt2 = UserForm1.TextBox2.Text
'notice that ChrW(9246) produces a different character in Chinese
UserForm1.TextBox2.Text = strTxt2 & " " & ChrW(9246)
End Sub

Output in VBE IDE: You may give it a try in VB6 form as well.

After all the above writing, I noticed this MSDN article. Well at least it's VB confirmation :D




回答2:


What you need is to use "Unicode aware" controls. VB6 only came with a few of these, though in Vista and later or XP (Tablet Edition only unless you use the non-Ink redist version of this library) the InkEdit control can do this.

InkEdit1.Text = ChrW$(9646)

Note the $ which indicates a function returning a String instead of a Variant with one embedded in it.

An InkEdit control is really an enhanced RichTextBox that supports ink entry as well as typing on ink-enabled systems. It is also a Unicode control, and one that supports Unicode properties such as .Text.

The standard MSHFlexGrid, DataGrid, and a few other controls are also Unicode-aware.

See http://www.alanwood.net/unicode/geometric_shapes.html for characters like the one in question. You can basically ignore the jibber-jabber about ANSI, Charset, etc. It is relevant but not applicable here.

▮ 9646 ▮ 25AE BLACK VERTICAL RECTANGLE




回答3:


The reason why it displays a question mark is that the character is not present in the font being used. You need to set the font to one that supports BLACK VERTICAL RECTANGLE, such as Arial Unicode MS or Lucida Sans Unicode.



来源:https://stackoverflow.com/questions/14080723/how-to-display-unicode-characters-in-vb6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!