HOWTO: Display DBCS in a VB Application Running on Windows NT
ID: Q158870
|
The information in this article applies to:
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
SUMMARY
This article provides information on how to display double-byte characters
(for example, Kanji, Chinese, Korean), that are written with a
non-localized version of Visual Basic and run on non-localized Windows NT.
MORE INFORMATION
The following steps and sample code demonstrate how to display Kanji
characters. Cp_932.nls, the Kanji character code page, and Msgothic.ttf, a
TrueType font, are required for this demonstration. This approach does not
apply to Windows 95. Windows 95 does not support TextOutW API.
NOTE: Cp_932.nls and Msgothic.ttf can be downloaded from the Microsoft Web
site: http://www.microsoft.com/msdownload/ieadd/02002.htm.
Step 1: Register the Code Page File
- Copy the code page file, cp_932.nls, into the \Windows\System directory.
- Start the Registry Editor and locate the following:
HKEY_LOCAL_MACHINE
Subtree: \System\CurrentControlSet\Control\NLS\CodePage
- If entry 932=cp_932.nls does not exist in the registry list, add a new
value from the Edit menu:
Value Name: 932
Data Type : REG_SZ
String : cp_932.nls
Step 2: Install Kanji Font
- Open the Control Panel.
- Double-click the Fonts icon.
- On the File menu, click Install New Font to install Msgothic.ttf.
Step 3: Create the Visual Basic Application
- Start a new project in Visual Basic. Form1 is created by default.
- On the Insert menu, click Module. The default is Module1.
- Paste the following code into the General Declarations section of
Module1:
Declare Function TextOutU Lib "gdi32" Alias "TextOutW" _
(ByVal hdc As Long, ByVal nXStart As Long, _
ByVal nYStart As Long, lpUnicode As Any, _
ByVal cbString As Long) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
ByVal hgdiObj As Long) As Long
Declare Function CreateFontA Lib "gdi32" (ByVal nHight As Long, _
ByVal nWidth As Long, ByVal nEscapement As Long, _
ByVal nOrientation As Long, _
ByVal fnWeight As Long, _
ByVal fdwItalic As Long, _
ByVal fdwU As Long, ByVal fdwS As Long, _
ByVal fdwChar As Long,ByVal fdwO As Long, _
ByVal fdwC As Long, ByVal fdwQ As Long, _
ByVal fdwP As Long, ByVal lpszFase As String) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Type Unicode
h As Byte
l As Byte
End Type
- Add a command button (Command1) to Form1.
- Paste the following code into the General Declarations section of Form1:
Private Sub Command1_Click()
Dim hFont As Long
Dim hOldFont As Long
hFont = CreateFontA(32, 16, 0, 0, 400, 0, 0, 0, 128, 3, 2, 1, 49, _
"MS Gothic")
hOldFont = SelectObject(Form1.hdc, hFont)
Dim MyUniCode(3) As Unicode
MyUniCode(0).h = CByte(140)
MyUniCode(0).l = CByte(128)
MyUniCode(1).h = CByte(140)
MyUniCode(1).l = CByte(127)
MyUniCode(2).h = 0
MyUniCode(2).l = 0
Dim di
di = TextOutU(Form1.hdc, 100, 100, MyUniCode(0), 2)
Call SelectObject(Form1.hdc, hOldFont)
DeleteObject (hFont)
End Sub
Additional query words:
kbVBp400 kbVBp kbdss kbDSupport kbIntl
Keywords : kbGrpVB
Version : WINDOWS:4.0
Platform : WINDOWS
Issue type : kbhowto
|