我的一个程序,需要获得系统即时状态下焦点所在的文本框里的内容,用什么样的方法呢?

解决方案 »

  1.   

    请问hhjjhjhj(大头),“ActiveControl.Text”是什么意思呀?
      

  2.   

    Private Declare Function GetFocus Lib "user32" () As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPrivate Sub Form_click()
        Form2.Show
    End SubPrivate Sub Timer1_Timer()
        Dim lnghWnd As Long
        Dim strText As String * 1000
        Dim lngLenth As Long
        Dim lngReturn As Long
        lnghWnd = GetFocus()
        lngLenth = 1000
        lngLenth = GetWindowText(lnghWnd, strText, lngLenth)
        Text1.Text = lnghWnd
        Text2.Text = Left(strText, lngLenth)
    End Sub
    这种方法只能获得,本进程内的焦点控件的文本
      

  3.   

    窗体中放一个Text1,timer1,Command1,点击Command1后马上把焦点移到Text1,试试
    Private Sub Command1_Click()
    Timer1.Enabled = True
    End SubPrivate Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 2000
    End SubPrivate Sub Timer1_Timer()
    MsgBox ActiveControl.Text
    Timer1.Enabled = False
    End Sub
      

  4.   

    谢谢你们了,可是我想要的是获得系统焦点的文本内容,不是程序本身的呀。有没有相关api的呢?
      

  5.   

    各位大虾,小第刚学VB(才半个月),但我有一个建议,你可以用一个查找当前系统中获得焦点的窗口的API函数,然后再用楼上houwei(飞浪)给出的那个获得问本的API获取文本就可以了,不知是不是对的,请高手指教.
      

  6.   

    windowformpoint取得MOUSE所在处的句柄,getWindowlong看是不是TEXTBOX,是的话,getwindowtext
      

  7.   

    当前窗口名称.文本框名称.Text