User Tools

Site Tools


displaying_20unicode_20text_20in_20a_20control

Displaying Unicode text in a control

by Richard Russell, February 2012

Versions 1.80 and later of LB Booster provide built-in support to output Unicode text to the mainwin, and to the printer using LPRINT, but not to GUI controls. In the case of controls other than a TEXTEDITOR it is quite easy to support Unicode output using a little API code.

Below is listed a program to illustrate displaying Cyrillic text in a STATICTEXT control. The SetTextUnicode subroutine can also be used with a BUTTON, a CHECKBOX, a GROUPBOX, a RADIOBUTTON or a TEXTBOX (ensure that you select Unicode Support in the Options menu):

   global CP.UTF8
   CP.UTF8 = hexdec("FDE9")
   nomainwin
 
   statictext #w.s1, "", 10, 10, 300, 100
   open "Unicode test" for window as #w
   #w "trapclose  [quit]"
   #w "font Times_New_Roman 20"
   hws1 = hwnd(#w.s1)
   call SetTextUnicode hws1, "Это демонстрация российского текста"
   wait
 
  [quit]
   close #w
   end
 
  sub SetTextUnicode hwin, utf8$
   calldll #kernel32, "MultiByteToWideChar", _
     CP.UTF8 as long, 0 as long, _
     utf8$ as ptr, -1 as long, _
     0 as long, 0 as long, ret as long
     bytes = 2 * ret
   calldll #kernel32, "GlobalAlloc", 0 as long, _
     bytes as long, wide as long
   calldll #kernel32, "MultiByteToWideChar", _
     CP.UTF8 as long, 0 as long, _
     utf8$ as ptr, -1 as long, _
     wide as long, ret as long, ret as long
   calldll #user32, "SendMessageW", _
     hwin as long, _WM_SETTEXT as long, _
     0 as long, wide as long, ret as long
   calldll #kernel32, "GlobalFree", wide as long, _
     ret as long
  end sub
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
displaying_20unicode_20text_20in_20a_20control.txt · Last modified: 2018/04/17 16:50 by tbest3112