I been scouring the Internet for an answer to my problem, and a couple of times thought I had almost found the answer, but still to no avail.
I'm tying to use the Rich Edit class (riched20.dll), to display unicode text. The riched20.dll file is loaded by using the LoadLibrary function, and a Rich Edit control created with the CreateWindowEx function. The text is input into a string variable from a unicode text file. The text is then inserted into the control, by using the SendMessage function and the WM_SETTEXT message. The font is set after the text has been inserted by using the WM_SETFONT message, which uses the form's font. -
Private Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Any) As Long
-
Private Declare Function GetCurrentObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal uObjectType As Long) As Long
-
Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
-
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
-
Private Declare Function SendMessageString Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
-
-
Private Const ES_MULTILINE As Long = &H4
-
'Private Const ES_READONLY As Long = &H800
-
-
Private Const OBJ_FONT As Long = 6
-
-
Private Const ST_DEFAULT As Long = 0
-
-
Private Const WM_SETFONT As Long = &H30
-
Private Const WM_SETTEXT As Long = &HC
-
-
Private Const WM_USER As Long = &H400
-
Private Const EM_SETTEXTMODE As Long = (WM_USER + 89)
-
Private Const EM_SETTEXTEX As Long = (WM_USER + 97)
-
-
Private Const WS_CHILD As Long = &H40000000
-
Private Const WS_VISIBLE As Long = &H10000000
-
Private Const WS_VSCROLL As Long = &H200000
-
-
Private Const WS_EX_CLIENTEDGE As Long = &H200&
-
-
Private hFont As Long
-
Private hRich As Long
-
Private hWndRich As Long
-
-
Private Sub Form_Load()
-
-
hRich = LoadLibrary("riched20.dll")
-
-
Line Input #1, TempStr
-
For I = 1 To 6
-
Line Input #1, TempStr
-
lblDictAboutInfo(I) = TempStr
-
Next I
-
I = 0
-
-
Do Until TempStr = "[Notes]"
-
Line Input #1, TempStr
-
Loop
-
-
TempStr = vbNullString
-
TempStr2 = vbNullString
-
-
Line Input #1, TempStr
-
-
Do
-
TempStr2 = TempStr2 & (TempStr & vbCrLf)
-
Line Input #1, TempStr
-
Loop Until TempStr = "[Abbreviations]"
-
-
hWndRich = CreateWindowEx(WS_EX_CLIENTEDGE, "RichEdit20W", vbNullString, ES_MULTILINE Or ES_READONLY Or WS_CHILD Or WS_VISIBLE Or WS_VSCROLL, 9, 152, 476, 214, hWnd, 0, App.hInstance, 0)
-
-
SendMessageString hWndRich, WM_SETTEXT, 0, TempStr2
-
hFont = GetCurrentObject(hDC, OBJ_FONT)
-
SendMessage hWndRich, WM_SETFONT, hFont, 1
-
-
TempStr = vbNullString
-
TempStr2 = vbNullString
-
-
Seek #1, 1
-
-
End Sub
-
The majority of the text works fine, but there are special unicode characters that aren't displayed properly within the text. The font is set to Verdana, which should work with Unicode characters. I understand that version 1 of the Rich Edit class doesn't support Unicode, but version 2 or higher should.
I'm using Visual Basic 6, and Windows XP.
2 5449
Just an FYI - The whole Unicode thing is why I switched to VB.NET. While I could get VB6 to display some Unicode I was never able to propagate it properly throughout my application. Reading Unicode from the controls proved most annoying.
I think I've worked it out...
For those that are interested in using unicode in a VB6 app, here's some code for you to try out: -
Option Explicit
-
-
'General Function Declarations
-
Private Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Any) As Long
-
Private Declare Function GetCurrentObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal uObjectType As Long) As Long
-
Private Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInfo As OSVERSIONINFO) As Long
-
Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
-
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
-
Private Declare Function SendMessageStringA Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
-
Private Declare Function SendMessageStringW Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
-
-
'General Type Declarations
-
Private Type OSVERSIONINFO
-
dwOSVersionInfoSize As Long
-
dwMajorVersion As Long
-
dwMinorVersion As Long
-
dwBuildNumber As Long
-
dwPlatformId As Long
-
szCSDVersion As String * 128
-
End Type
-
-
'General Variable Declarations
-
Private Const OBJ_FONT As Long = 6
-
-
Private Const TM_PLAINTEXT As Long = 1
-
-
Private Const WM_USER As Long = &H400
-
Private Const EM_SETTEXTMODE As Long = (WM_USER + 89)
-
-
Private Const ES_MULTILINE As Long = &H4
-
-
Private Const WM_SETFONT As Long = &H30
-
Private Const WM_SETTEXT As Long = &HC
-
-
Private Const WS_CHILD As Long = &H40000000
-
Private Const WS_EX_CLIENTEDGE As Long = &H200&
-
Private Const WS_VISIBLE As Long = &H10000000
-
Private Const WS_VSCROLL As Long = &H200000
-
-
Private hFont As Long
-
Private hRich As Long
-
Private hWndRich As Long
-
-
Private TempStr As String
-
-
Private WinVer As OSVERSIONINFO
-
-
Private Sub Form_Load()
-
-
'Store operating system version information
-
WinVer.dwOSVersionInfoSize = Len(WinVer)
-
GetVersionEx WinVer
-
-
'Load the Rich Edit 2.0/3.0 library/class
-
hRich = LoadLibrary("riched20.dll")
-
-
'Create the control to be used with unicode
-
hWndRich = CreateWindowEx(WS_EX_CLIENTEDGE, "RichEdit20W", vbNullString, ES_MULTILINE Or WS_CHILD Or WS_VISIBLE Or WS_VSCROLL, 9, 10, 290, 180, hWnd, 0, App.hInstance, 0)
-
-
'Open the unicode file in binary mode
-
Open App.Path & "\unicode.txt" For Binary As #1
-
-
'Strips unicode file header
-
Seek 1, 3
-
-
'Store the unicode file contents to a string variable
-
Do
-
TempStr = TempStr & Input$(1, 1)
-
Loop Until EOF(1)
-
-
'Set the control to use "plain text" mode
-
SendMessage hWndRich, EM_SETTEXTMODE, TM_PLAINTEXT, 0
-
'Set the control to use the form's font
-
hFont = GetCurrentObject(hDC, OBJ_FONT)
-
SendMessage hWndRich, WM_SETFONT, hFont, 1
-
-
'Send the stored text to the control
-
If WinVer.dwPlatformId = 2 Then
-
SendMessageStringW hWndRich, WM_SETTEXT, 0, TempStr
-
Else
-
SendMessageStringA hWndRich, WM_SETTEXT, 0, TempStr
-
End If
-
-
'Close the file
-
Close #1
-
-
End Sub
-
The code should work on Windows 95 through to Windows Vista.
If you want to create a single line textbox instead, the multiline constant can be left out.
The control needs to be set to "plain text" mode, so that unicode characters are displayed properly (or are at least visible). This prevents the use of RTF formatting, and object embedding, plus the control is limited to using a single font.
If anyone knows of how this code could be improved, please post here. I will post any more decent information that I find out about unicode formatting, in the near future.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: KevenL |
last post by:
I'm trying to insert unicode characters into a VB Rich Text control
(in this case, the Full Block character (U+2588 on the character map).
If I copy and paste from the character map, the character...
|
by: Seth Russell |
last post by:
I'm running Kevin Roth's rte box and i want to deactivate the ability
to past inside the box. People sometimes paste outrageous things in
there that might break my site. How can I deactivate the...
|
by: PC User |
last post by:
I found this Rich Text Editor and I've been trying to recreate it in
my own application. I've had trouble with the COMCTL.ImageListCtrl
and the COMCTL.Toolbar to recreate the toolbar. And I've...
|
by: David Davis |
last post by:
Woll2Woll has a product for Delphi called Infopower which has a rtf control
with a built-in word processor. Does anyone know of a third party control
that has the same capabilities. I don't have...
|
by: Mick_fae_Glesga |
last post by:
Hello everyone!
OK, I'm writing a windows program that requires the user to enter
Cyrillic characters into an Edit control.
But, I can't seem to get the Cyrillic characters to appear in the...
| |
by: bob |
last post by:
Can anyone tell me the best way to update a dataset while it is being
edited/viewed in the DataGridView control? Is this something that
should be inserted into one of the grid's events? or should...
|
by: Prasad |
last post by:
Hi all, I am trying to develop a simple rich text editor
I do only require bold, itlaic, underline..
The code for IE is
<script>
function displayEditor(editor, html, width, height)
{
...
|
by: zhang |
last post by:
I create a project (base dialog) just use the mouse ,It can work if I do
not add "
Rich Edit 2.0 Control".
and the dialog diappeard after I add it.
why???I can not use "Rich Edit 2.0 Control"...
|
by: San07 |
last post by:
Hi All,
I don't know whether this is the right place to post my query.
Query:
This is in VC++. I have created a blank Dialog-based project with VC++ 6.0. When I run, I am able to see the Dialog....
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |