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 Long
Private Sub Form_click()
Form2.Show
End Sub
Private 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
这种方法只能获得,本进程内的焦点控件的文本