如何在 Visual Basic 6 中对齐 RichEdit 粘贴对象位置?

发布于 2024-07-10 00:42:12 字数 1076 浏览 10 评论 0原文

我们有一个 RichEdit 控件,我们可以在其中添加允许用户插入 Office MathML 方程对象。

基本上逻辑是这样的:用户单击插入数学方程,我们允许他们使用外部 MathML 编辑器,然后我们将表示方程的图像粘贴到 RichEdit 控件中:

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

找到其位置并使用以下方法锁定它

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

:在 ANSI 的美丽世界中一切都很好,但我们也允许 Unicode 字符,以及什么我注意到,当你使用汉字时,插入的位置错误了总位置的一半,即如果它应该是第七个位置,现在它被插入到第三个位置。

基本上除以二,我猜是因为 Unicode 需要两个字节,而 ANSI 只需要一个字节。 因为我是个傻瓜,没有使用 RTF、RichEdit 和 Visual Basic 6 的经验。

所以我的问题是:使用 sendMessage 行粘贴图像时可以更改图像的位置吗?

或者通过其他方式来控制插入RichEdit框中的图像的位置?

We have a RichEdit control into which we allow the user to insert an Office MathML equation object.

Basically the logic goes like this: the user click on insert math equation, we allow them to use an external MathML editor, then we will paste an image to represent the equation into the RichEdit control:

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

Find its position and lock it down using:

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

It's all nice and good in the beautiful world of ANSI, but we also allow Unicode characters, and what I've noticed is that when you use Chinese characters, the position of the insertion is wrong by half the total position, i.e if it's supposed to be the 7th position now it's inserted at the third.

Basically divided by two, I guess because Unicode takes two bytes as compared to ANSI which requires just one. So because I'm a dummy with no experience with the RTF, RichEdit and Visual Basic 6.

So my question is: can I change the position of the image when I paste it using the sendMessage line?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢欲 2024-07-17 00:42:13

为什么不在粘贴前检索位置?

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

Why not retrieve the position before pasting?

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
诗笺 2024-07-17 00:42:12

我的方法是这样的,如果您查看 rtf.SelRTF 属性,您将能够准确地看到在 RichTextBox 中创建视觉效果的 RTF 代码是什么。 然后,您可以将其保存到文件中,将其加载到 Word 中并移动图像,直到其位于正确的位置,保存文件并再次查看 RTF 代码。 那时,您应该对中文或其他 Unicode 语言的组合有足够的了解,以构建字符串操作代码来执行您想要的操作。 我不完全确定每个 unicode 字符都是 2 个字节 - 值得检查一下您是否认真支持整个范围。

希望有帮助。

My approach would be this, if you look at the rtf.SelRTFproperty you'll be able to see exactly what the RTF code is that's creating the visual in the RichTextBox. You can then save that into a file, load it in word and move the image around until it's in the right place, save the file and look at the RTF code again. At that point you should know enough about the combination of chinese or other Unicode languages to build the string manipulation code to do what you want. I'm not entirely sure that every unicode character is 2 bytes - worth checking out if your serious about supporting the full range.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文