How to align the position of a RichEdit palette object in Visual Basic 6?

We have a RichEdit into which we allow the user to paste Office MathML .

Basically the logic is like this: the user clicks on an insert math equation, we allow them to use an external MathML editor, then we insert an image to represent the equation in the RichEdit control:

' Paste the picture into the RichTextBox.
SendMessage ctlLastFocus.hwnd, WM_PASTE, 0, 0

      

Find its position and lock it using:

With ctlLastFocus
    'lock the image
    .SelStart = .SelStart - 1
    .SelLength = 1
    .SelProtected = True

      

This is all well and good in the beautiful ANSI world, but we also allow Unicode characters, and what I noticed is that when you use Chinese characters, the insertion position is incorrect at half the total position, i.e. if it should be at 7th position, it is now inserted at 3rd.

Basically divided by two, I think because Unicode takes two bytes compared to ANSI, which only requires one. Therefore, since I am a dummy with no experience with RTF , RichEdit and Visual Basic 6.

So my question is, can I change the position of the image when inserting it using the sendMessage string?

Or some other way to control the position of the image inserted into the RichEdit field?

+1


source to share


2 answers


My approach would be this, if you look at the property rtf.SelRTF

, you can see exactly what the RTF code that creates the visual in the RichTextBox is. Then you can save this to a file, load it in word and move the image until it is in the right place, save the file and look at the RTF code again. At this point, you should know enough about the combination of Chinese or other Unicode languages ​​in order to build your string manipulation code to do what you want. I'm not entirely sure if each unicode character is 2 bytes - worth checking if you are serious about maintaining the full range.



Hope it helps.

0


source


Why not get the position before insertion?



Dim iStartPos As Long
Dim iLength As Long
With ctlLastFocus
    iStartPos = .SelStart
    SendMessage.hwnd, WM_PASTE, 0, 0
    iLength = .SelStart - iStartPos
    .SelStart = iStartPos
    .SelLength = iLength
    .SelProtected = True
End With

      

0


source







All Articles