苦闷那!!Richtextbox图片+中文问题!!

zq972 2006-02-21 10:06:33
我的程序是这样的,一个Pic里有一image控件数组,每个对应一个表情
往richtextbox中插入表情的代码如下

***************模块中**************************
Public Const WM_USER = &H400

Public Const EM_PASTESPECIAL = WM_USER + 64
Public Const CF_BITMAP = 2
Public Const CF_TEXT = 1
Public Const DVASPECT_CONTENT = 1
Public Const DVASPECT_ICON = 4
Public re As repastespecial
Public Type repastespecial
dwAspect As Long
dwParam As Long
End Type
***********************************************

******************窗体中************************
private sub image1_click(Index As Integer)
re.dwAspect = DVASPECT_CONTENT
Clipboard.Clear
Clipboard.SetData ImgFace(Index).Picture
txtMsg.SelStart = Len(txtMsg.Text) + 2
DoEvents
SendMessage txtMsg.hwnd, EM_PASTESPECIAL, CF_BITMAP, re
DoEvents
end sub
************************************************
在点击image的时候将表情插入到文本的最后

此时问题出现了,当输入全是英文时没有任何问题,
但是出现了2个或2个以上的中文字符后表情的位置
总是不对,总是忘前跳几个位置,哪位高人能指点
一下这是为什么啊!!!
txtMsg.SelStart = Len(txtMsg.Text) + 2
txtMsg.SelStart = Len(txtMsg.Text)
txtMsg.SelStart = Len(txtMsg.Text) + 2
txtMsg.SelStart = LenB(StrConv(txtMsg.Text, vbFromUnicode))
txtMsg.SelStart = LenB(StrConv(txtMsg.Text, vbUnicode))
都得不到正确的插入位置,郁闷死了!!!

请大家帮帮忙,或者有其他有效的插入表情的方法也可以。


http://community.csdn.net/Expert/topic/4567/4567384.xml?temp=.6279108
...全文
220 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
happywqw 2006-03-28
  • 打赏
  • 举报
回复
http://www.cnpopsoft.com/blog/article.asp?id=3
zq972 2006-02-22
  • 打赏
  • 举报
回复
我已经自己解决了。多谢rainstormmaster的关注!!
rainstormmaster 2006-02-21
  • 打赏
  • 举报
回复
简单的说,就是不能用SelStart定位,原因是SelStart是基于字符的,而不是基于字节的,你应该发送EM_EXSETSEL消息定位,可以看看这里:

http://rainstormmaster.cnblogs.com/archive/2006/02/19/333330.html
zq972 2006-02-21
  • 打赏
  • 举报
回复
多谢老大,我晚上好好研究一下

我也测试了一下,richtextbox的定位确实有问题,当只有两个中文的时候插入不准确,
但是两个中文后面加几个空格后又可以了,但是后面再加几个中文后又开始不准确了。
太郁闷了,但是98下面是没有问题的。
rainstormmaster 2006-02-21
  • 打赏
  • 举报
回复
你先看看这个吧:
http://topic.csdn.net/t/20031223/21/2595831.html
rainstormmaster 2006-02-21
  • 打赏
  • 举报
回复
晕,好象是richtextbox的bug,我先在剪贴板中复制一幅图片,然后按ctrl-v粘贴,依然不能准确定位
rainstormmaster 2006-02-21
  • 打赏
  • 举报
回复
先等等,好象有问题
去掉:
SendMessage(RichTextBox1.hwnd, EM_PASTESPECIAL, CF_BITMAP, re)
这一句,光标可以正常定位,加上它,问题又出来了,我先查查资料
rainstormmaster 2006-02-21
  • 打赏
  • 举报
回复
晕啊,你怎么用的?

算了,还是给你写一段代码吧:
'一个按钮,一个picturebox,一个richtextbox
'预先为picturebox载入一幅图片
Option Explicit
Private Type repastespecial
dwAspect As Long
dwParam As Long
End Type

Const WM_USER = &H400
Const EM_PASTESPECIAL = WM_USER + 64
Const CF_BITMAP = 2
Const CF_TEXT = 1
Const DVASPECT_CONTENT = 1
Const DVASPECT_ICON = 4
Private Const EM_EXGETSEL = (WM_USER + 52)
Private Const EM_EXSETSEL = (WM_USER + 55)
Private Type CharRange
cpMin As Long
cpMax As Long
End Type


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

Private Sub Command1_Click()
Dim re As repastespecial
re.dwAspect = DVASPECT_CONTENT
Dim mCharRange As CharRange
With mCharRange
.cpMin = -1
.cpMax = -1
End With
RichTextBox1.SetFocus
SendMessage RichTextBox1.hwnd, EM_EXSETSEL, 0, mCharRange
Clipboard.Clear
Clipboard.SetData Picture1.Image
Call SendMessage(RichTextBox1.hwnd, EM_PASTESPECIAL, CF_BITMAP, re)

End Sub
zq972 2006-02-21
  • 打赏
  • 举报
回复
******************窗体中************************
private sub image1_click(Index As Integer)
re.dwAspect = DVASPECT_CONTENT
Clipboard.Clear
Clipboard.SetData ImgFace(Index).Picture
SendMessage txtMsg.hWnd, EM_EXGETSEL, 0, OldCharRange
SendMessage txtMsg.hWnd, EM_EXSETSEL, 0, OldCharRange
DoEvents
SendMessage txtMsg.hwnd, EM_PASTESPECIAL, CF_BITMAP, re
DoEvents
end sub
************************************************

还是不行,错误依然,
例如应该是:
"你好"表情1
在"你好"后点击image变成了
"你"表情1"好"
zq972 2006-02-21
  • 打赏
  • 举报
回复
sorry,不太会用。
但是我刚试了一下在98下没有这个问题,太郁闷了。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧