Link to home
Start Free TrialLog in
Avatar of gilabean
gilabean

asked on

Unicode Display In Visual Basic With VB Controls...

Hi Hi!

Something that I really need some feedback from anyone who had done this before. I'm trying to display some unicode character ( eg: chinese, japanese character ) into the message box. But then what I got is just " ??? " character.

I know that by starting the program like Chinese Star, I will be able to view it correctly but I'm trying to develop a program that we don't have to start a third party software to run the program correctly.

I managed to find out that Microsoft Form 2 Objects support unicode character but I'm still searching for solutions on the menu and message box on how to display the unicode character out without having to run a third party software.

Anyone with any ideas on how to do this? Thanks for the help in advance !

ASKER CERTIFIED SOLUTION
Avatar of catalin_tata
catalin_tata

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of catalin_tata
catalin_tata

You can try the following:
  1.Instead of use the VB MsgBox function for displaying the message try to use the unicode version of the WIndows API MessageBox...this is the declaration:

Public Declare Function MessageBox Lib "user32" Alias "MessageBoxW" (ByVal hwnd As Long,lpText As Any, ByVal lpCaption As String, ByVal wType As Long) As Long
   
   2.Do not pass the VB string directly,convert the string in a bytes array.A unicode character have 2 bytes.
   
   If you need more information,just let me know
   Regards,Catalin

Avatar of gilabean

ASKER

I don't really know how to use the API coz..I haven't use it before.

It would be great if you can give me an example on the usage of the messagebox.

thanks in advance.
:)

Cheers,
gilabean
I don't really know how to use the API coz..I haven't use it before.

It would be great if you can give me an example on the usage of the messagebox.

thanks in advance.
:)

Cheers,
gilabean
First thing that you need to have in mind when starting with api is the API text viewer utility that you can find in the Microsoft Visual Studio tools. There you can find declaration of functions,constants and types that can be use in VB when calling a API.
I show you an example with the usage of the MessageBox Api

In a vb module place the declaration:

Public Declare Function MessageBox Lib "user32" Alias "MessageBoxW" (ByVal hwnd As Long,lpText As Any, ByVal lpCaption As String, ByVal wType As Long) As Long

Public Const MB_OK = &H0&


then in youur program when you call the MsgBox use this:

strText="Message Box title in chinese" 'this is the text that will be put on the message box and can be any unicode character
msgTextB() as byte
Redim msgTextB(Len(strText)*2)
for i=1 to len(strText)
 msgTextB(i*2-1)=Ascw(Mid(strText,i,1))/256-1
 msgTextB(i*2)=Ascw(Mid(strText,i,1))mod 256
next i
MessageBox(frmMain.hwnd,msgtextB(0),"Box caption",MB_OK)

Hope this help you
Regards,Catalin

I don't really know how to use the API coz..I haven't use it before.

It would be great if you can give me an example on the usage of the messagebox.

thanks in advance.
:)

Cheers,
gilabean
I managed to display unicode character out but then the displayed text is not displayed correctly.

Let's say that I used chinese simplified character but when it output out in the messagebox, the displayed caption is not what I type.....

*headache* LoL

cheers,
gilabean
The above should work fine, but another approach might be just to simulate a msgbox using a small form with a (From 2.0 Object) label on it, and a command button to 'accept'.

For instance, create a small form called, say ChMsgbox. Put a Label on it (label1) and a commandbutton (Command1).
The form should only contain the following code, to enable the user to accept:

Private Sub Command1_Click()
Unload Me
End Sub

To call the fake msgbox, include this sub in the main form:

Private Sub UnicMsgBox(myMessage)
With ChMsgbox
.Show
.Label1.Font = "Arial Unicode MS"
.Label1.Caption = myMessage
End With
End Sub

Now, to make the message appear, simply use something like:

UnicMsgBox ChrW(20000) + ChrW(20001) + ChrW(20002)

Hope this helps,
but again, the API call is more satisfying.
Kindest regards,
Rhaedes
gilabean:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Avatar of DanRollins
Moderator, my recommended disposition is:

    Accept catalin_tata's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer