如何用vb点击取词,并把所取的词按取词顺序放入文本框,求源码

解决方案 »

  1.   

    当然可以屏幕抓取,但是对于VB实现比较复杂,要hook API函数。有2个简便的方法:(1)利用金山词霸现成的抓取库来实现,可以Google下。
    (2)得到鼠标所在窗口的handle,调用getwindowtext() sendmessage(wm_gettext)等等api获取文字,这样大部分控件的也能得到。
      

  2.   

    我点击的词会被自动复制,并且按照点击顺序自动在word或记事本或写字板上排列
      

  3.   

    之前代码可以用的。中文如果不需要空格就修改一下。Private Sub Text1_Click()
    Dim s$, ss$, n&, s1$, s2$
    s = Form1.Text1.Text
    n = Form1.Text1.SelStart
    s1 = Left(s, n): s2 = Mid(s, n + 1)
    ss = Mid(s1, InStrRev(s1, Space(1)) + 1) & Left(s2, IIf(InStr(s2, Space(1)) = 0, Len(s2), InStr(s2, Space(1)) - 1))
    Form1.Text2.Text = Form1.Text2.Text & ss
    End Sub
      

  4.   

    其实这个源码我不太懂,space(1)改为space(0)吗?
      

  5.   

    6楼代码已经修改不带空格了。
    昨天那个有带空格。Form1.Text2.Text = Form1.Text2.Text & ss & space(1)'去掉& space(1)
      

  6.   

    我的可以看懂吧,(VB娃娃)的代码分两部分
    Mid(s1, InStrRev(s1, Space(1)) + 1) 和
    Left(s2, IIf(InStr(s2, Space(1)) = 0, Len(s2), InStr(s2, Space(1)) - 1))
    其实我的代码可以看做他的代码的解释。你取词一般也就几个或十几个字符,循环并不慢。
    如果取字符串,他的代码速度快。
      

  7.   

    能否麻烦king把你的稍改一下给哦我呢? 无论如何都非常感谢。
      

  8.   

    呵呵,不知道你现在没有空格了,整段文字选单字的话,给你参考一下。
    Private Sub Text1_Click()
    Dim s$, ss$, n&, s1$, s2$
    s = Form1.Text1.Text
    n = Form1.Text1.SelStart: If n = 0 Then n = 1
    ss = Mid(s, n, 1)
    Form1.Text2.Text = Form1.Text2.Text & ss
    End Sub
      

  9.   

    代码多点,但是看得清楚;
    也可以改一下(VB娃娃)的代码,一样方法
        Dim posR As Integer, posL As Integer
        Dim strTmp As String, blnTmp As Boolean
        posR = Text1.SelStart + 1
        posL = Text1.SelStart
            
        Do Until Mid(Text1.Text, posR, 1) = " "
            If posR > Len(Text1.Text) Then Exit Do
            If (Asc(Mid(Text1.Text, posR, 1)) >= 65 And Asc(Mid(Text1.Text, posR, 1)) <= 90) Or (Asc(Mid(Text1.Text, posR, 1)) >= 97 And Asc(Mid(Text1.Text, posR, 1)) <= 122) Then
                strTmp = strTmp & Mid(Text1.Text, posR, 1)
                posR = posR + 1
            Else
                strTmp = Mid(Text1.Text, posR, 1)
                blnTmp = True
                Exit Do
            End If
        Loop
        
        If posL = 0 Then posL = 1
        Do Until Mid(Text1.Text, posL, 1) = " "
            If (Asc(Mid(Text1.Text, posL, 1)) >= 65 And Asc(Mid(Text1.Text, posL, 1)) <= 90) Or (Asc(Mid(Text1.Text, posL, 1)) >= 97 And Asc(Mid(Text1.Text, posL, 1)) <= 122) Then
                If posL > 0 Then
                    strTmp = Mid(Text1.Text, posL, 1) & strTmp
                    posL = posL - 1
                End If
                If posL = 0 Then Exit Do
            Else
                If blnTmp = False Then'已经取过一个汉字就不用再考虑向左取词了
                    strTmp = Mid(Text1.Text, posL, 1)
                End If
                Exit Do
            End If
        Loop
            
        Text2.Text = Text2.Text & IIf(Text2.Text = "", strTmp, " " & strTmp)
      

  10.   

    ...楼主的意思可能是汉字或英文混合在一起的情况,比如 : "这样的 字 符 is tom name my"