汽车尾气检测网络系统QQ:357766186__MSN:MSNTHW19850316@
Option Explicit
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 Const EM_POSFROMCHAR = 214
Private Const EM_GETSEL = &HB0
Private Sub Command1_Click()
Dim ret As Long
Dim intStart As Integer
Dim intEnd As Integer
Dim intStartX As Integer
Dim intEndX As Integer
ret = SendMessage(RichTextBox1.hwnd, EM_GETSEL, 0, 0)
intStart = ret And 65535
intEnd = (ret And &HFFFF0000) / (2 ^ 16)
ret = SendMessage(RichTextBox1.hwnd, EM_POSFROMCHAR, intStart, 0)
intStartX = ret And 65535
ret = SendMessage(RichTextBox1.hwnd, EM_POSFROMCHAR, intEnd + 1, 0)
intEndX = ret And 65535
MsgBox intEndX - intStartX
End Sub
已经解决了,这个可以得到选中字符的实际宽度