快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

易游娱乐易游电子易游老虎机:用VB6分离出文本框的单词



编程喜欢者必然应用过金山词霸的即指即译功能,它实际上是首先从文本平分离出鼠标所在位置的单词,然后对比英汉信息数据库的相关信息进行翻译。下面的代码演示了若何从一个RECHTEXT文本框平分离出单词,并且将它显示在一个标签控件中。

启动vb6,建立一个标准exe工程,单击“工程”――“部件”,选中Microsoft rich text control6.0,单击“确定”按钮,然后在窗体中添加该控件,命名为rchMainText,在窗体底部添加一个标签控件命名为label1,双击窗体,写入以下代码:

Option Expli易游娱乐易游电子易游老虎机cit

Private C易游娱乐易游电子易游老虎机onst EM_CHARFROMPOS& = &HD7‘返回易游娱乐易游电子易游老虎机鼠标所在位置的字符指针

Private Type POINTAPI

X As Long

Y A易游娱乐易游电子易游老虎机s 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

Public Function RichWordOver(rch As RichTextBox, X As Single, Y As Single) As String

'当鼠标移动到richtext控件时,分离出当前的单词

Dim pt As POINTAPI ‘鼠标指针坐标

Dim pos As Integer

Dim start_pos As Integer

Dim end_pos As Integer

Dim ch As String

Dim txt As String

Dim txtlen As Integer

pt.X = X \ Screen.TwipsPerPixelX

pt.Y = 易游娱乐易游电子易游老虎机Y \ Screen.TwipsPerPixelY

‘得到鼠标所在位置

pos = SendMessage(rch.hWnd, EM_CHARFROMPOS, 0&, pt)

If pos = "0" And ch = "a" And ch = "A" And ch = "0" And ch = "a" And ch = "A" And chtxt Then

label1.Caption = txt

‘将返回的单词通报给LABEL1标签

End Sub

Private Sub Form_Unload(Cancel As Integer)

End

End Sub‘法度榜样停止

您可能还会对下面的文章感兴趣: