Click to See Complete Forum and Search --> : EM_CHARFROMPOS API not working with MBCS or DBCS


sajid.pk
July 4th, 2007, 07:19 AM
Hi,

EM_CHARFROMPOS api don't seem to work with double byte characterset. whenever I call these functions I get wrong int values returned...

any idea why?

Boris K K
July 4th, 2007, 07:36 AM
Are you treating the returned value as a byte offset (lpstrText + result) or as character offset (result times CharNext)? The documentation uses the term "character index" so I expect it to be the latter.

sajid.pk
July 4th, 2007, 08:26 AM
hi,

thanks Boris

I am using this function for finding next point insertion in rich textbox. When Double Byte Charter ( japaines char ) is entered in rich text box it return value is double


my code is given below



Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Type POINTAPI
X As Long
Y As Long
End Type


Public Function RTBCharFromPos(ByVal hwnd As Long, ByVal xPixels As Long, ByVal yPixels As Long) As Long
Dim tp As POINTAPI

tp.X = xPixels
tp.Y = yPixels
RTBCharFromPos = SendMessage(hwnd, EM_CHARFROMPOS, 0, tp)
End Function

Boris K K
July 4th, 2007, 12:21 PM
If I understand correctly that RTBCharFromPos is returning bigger value than expected in case of multi-byte characters, than the correct theory is that EM_CHARFROMPOS is returning byte offset, not number of characters.

Unfortunately, there is not much you can do with a MBCS byte offset inside VB, which internally works with Unicode strings.

Any reason why you cannot use an Unicode control and SendMessageW?

sajid.pk
July 5th, 2007, 06:03 AM
hi,
Which control i can use insted of richtx32.ocx for unicode support.


thanks

Boris K K
July 5th, 2007, 07:27 AM
Can you check with a tool like Spy++ which window class (and if possible, which dll) your text conrol is using?

animonkadhar
July 5th, 2007, 07:57 AM
Hi I have Seen sajid's System

It seems the Class Name is RichTextWndClass

RichTx32.OCX version-6.01.9782

Boris K K
July 5th, 2007, 10:50 AM
Yes, it seems (also from other sources), that RichTx32.ocx uses the earliest version (1.0) of Rich Edit. It does not seem to support Unicode.

sajid.pk
July 6th, 2007, 03:59 AM
Thanks for u r Valuable suggestion. Can u pls suggests a control which can be used instead of RichTx32.ocx that support unicode.

Boris K K
July 9th, 2007, 09:48 AM
Sorry, have no idea. You may have a better luck at some VB forum.