473,473 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Rich Edit 2 DLL with Unicode

31 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. 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
  2. Private Declare Function GetCurrentObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal uObjectType As Long) As Long
  3. Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
  4. 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
  5. 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
  6.  
  7. Private Const ES_MULTILINE As Long = &H4
  8. 'Private Const ES_READONLY As Long = &H800
  9.  
  10. Private Const OBJ_FONT As Long = 6
  11.  
  12. Private Const ST_DEFAULT As Long = 0
  13.  
  14. Private Const WM_SETFONT As Long = &H30
  15. Private Const WM_SETTEXT As Long = &HC
  16.  
  17. Private Const WM_USER As Long = &H400
  18. Private Const EM_SETTEXTMODE As Long = (WM_USER + 89)
  19. Private Const EM_SETTEXTEX As Long = (WM_USER + 97)
  20.  
  21. Private Const WS_CHILD As Long = &H40000000
  22. Private Const WS_VISIBLE As Long = &H10000000
  23. Private Const WS_VSCROLL As Long = &H200000
  24.  
  25. Private Const WS_EX_CLIENTEDGE As Long = &H200&
  26.  
  27. Private hFont As Long
  28. Private hRich As Long
  29. Private hWndRich As Long
  30.  
  31. Private Sub Form_Load()
  32.  
  33.     hRich = LoadLibrary("riched20.dll")
  34.  
  35.     Line Input #1, TempStr
  36.     For I = 1 To 6
  37.         Line Input #1, TempStr
  38.         lblDictAboutInfo(I) = TempStr
  39.     Next I
  40.     I = 0
  41.  
  42.     Do Until TempStr = "[Notes]"
  43.         Line Input #1, TempStr
  44.     Loop
  45.  
  46.     TempStr = vbNullString
  47.     TempStr2 = vbNullString
  48.  
  49.     Line Input #1, TempStr
  50.  
  51.     Do
  52.         TempStr2 = TempStr2 & (TempStr & vbCrLf)
  53.         Line Input #1, TempStr
  54.     Loop Until TempStr = "[Abbreviations]"
  55.  
  56.     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)
  57.  
  58.     SendMessageString hWndRich, WM_SETTEXT, 0, TempStr2
  59.     hFont = GetCurrentObject(hDC, OBJ_FONT)
  60.     SendMessage hWndRich, WM_SETFONT, hFont, 1
  61.  
  62.     TempStr = vbNullString
  63.     TempStr2 = vbNullString
  64.  
  65.     Seek #1, 1
  66.  
  67. End Sub
  68.  
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.
Mar 28 '08 #1
2 5449
!NoItAll
297 Contributor
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.
Mar 28 '08 #2
tristanlbailey
31 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. 'General Function Declarations
  4. 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
  5. Private Declare Function GetCurrentObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal uObjectType As Long) As Long
  6. Private Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (lpVersionInfo As OSVERSIONINFO) As Long
  7. Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
  8. 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
  9. 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
  10. 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
  11.  
  12. 'General Type Declarations
  13. Private Type OSVERSIONINFO
  14.     dwOSVersionInfoSize As Long
  15.     dwMajorVersion As Long
  16.     dwMinorVersion As Long
  17.     dwBuildNumber As Long
  18.     dwPlatformId As Long
  19.     szCSDVersion As String * 128
  20. End Type
  21.  
  22. 'General Variable Declarations
  23. Private Const OBJ_FONT As Long = 6
  24.  
  25. Private Const TM_PLAINTEXT As Long = 1
  26.  
  27. Private Const WM_USER As Long = &H400
  28. Private Const EM_SETTEXTMODE As Long = (WM_USER + 89)
  29.  
  30. Private Const ES_MULTILINE As Long = &H4
  31.  
  32. Private Const WM_SETFONT As Long = &H30
  33. Private Const WM_SETTEXT As Long = &HC
  34.  
  35. Private Const WS_CHILD As Long = &H40000000
  36. Private Const WS_EX_CLIENTEDGE As Long = &H200&
  37. Private Const WS_VISIBLE As Long = &H10000000
  38. Private Const WS_VSCROLL As Long = &H200000
  39.  
  40. Private hFont As Long
  41. Private hRich As Long
  42. Private hWndRich As Long
  43.  
  44. Private TempStr As String
  45.  
  46. Private WinVer As OSVERSIONINFO
  47.  
  48. Private Sub Form_Load()
  49.  
  50.     'Store operating system version information
  51.     WinVer.dwOSVersionInfoSize = Len(WinVer)
  52.     GetVersionEx WinVer
  53.  
  54.     'Load the Rich Edit 2.0/3.0 library/class
  55.     hRich = LoadLibrary("riched20.dll")
  56.  
  57.     'Create the control to be used with unicode
  58.     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)
  59.  
  60.     'Open the unicode file in binary mode
  61.     Open App.Path & "\unicode.txt" For Binary As #1
  62.  
  63.     'Strips unicode file header
  64.     Seek 1, 3
  65.  
  66.     'Store the unicode file contents to a string variable
  67.     Do
  68.         TempStr = TempStr & Input$(1, 1)
  69.     Loop Until EOF(1)
  70.  
  71.     'Set the control to use "plain text" mode
  72.     SendMessage hWndRich, EM_SETTEXTMODE, TM_PLAINTEXT, 0
  73.     'Set the control to use the form's font
  74.     hFont = GetCurrentObject(hDC, OBJ_FONT)
  75.     SendMessage hWndRich, WM_SETFONT, hFont, 1
  76.  
  77.     'Send the stored text to the control
  78.     If WinVer.dwPlatformId = 2 Then
  79.         SendMessageStringW hWndRich, WM_SETTEXT, 0, TempStr
  80.     Else
  81.         SendMessageStringA hWndRich, WM_SETTEXT, 0, TempStr
  82.     End If
  83.  
  84.     'Close the file
  85.     Close #1
  86.  
  87. End Sub
  88.  
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.
Apr 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
14
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...
1
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...
4
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...
2
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...
2
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...
7
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) { ...
2
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"...
4
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....
0
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...
0
Oralloy
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,...
0
tracyyun
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...
0
agi2029
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.