here is partial solution for VB6.
it sample work only with textbox but don't work with document of IE.
if you wan't pay u$s 100 I dedicate more time for this solution.
bye
Option Explicit
Private Declare Function AttachThreadInput Lib "user32" (ByVal
idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As
Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hWnd As Long, lpdwProcessId As Long) As Long
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_GETSEL = &HB0
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private mLngCurrThread As Long
Private Sub Form_Load()
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If SetWindowInput = True Then
Me.Caption = GetWindowTextSel(GetFocus)
End If
End Sub
Private Function GetHiLoWord(ByVal lParam As Long, LOWORD As Long,
HIWORD As Long) As Boolean
LOWORD = lParam And &HFFFF&
HIWORD = lParam \ &H10000 And &HFFFF&
GetHiLoWord = True
End Function
Private Function GetWindowText(ByVal hWnd As Long) As String
Dim strBuff As String, lngLen As Long
lngLen = SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0)
If lngLen > 0 Then
lngLen = lngLen + 1
strBuff = Space$(lngLen)
lngLen = SendMessage(hWnd, WM_GETTEXT, lngLen, ByVal strBuff$)
If lngLen > 0 Then
GetWindowText = Left$(strBuff, lngLen)
End If
End If
End Function
Private Function GetWindowTextSel(ByVal hWnd As Long) As String
Dim lngRet As Long, lngLo As Long, lngHi As Long, strSel As String
lngRet = SendMessage(hWnd, EM_GETSEL, 0, ByVal 0&)
If lngRet <> -1 Then
Call GetHiLoWord(lngRet, lngLo, lngHi)
strSel = GetWindowText(hWnd)
strSel = Mid$(strSel, lngLo + 1, lngHi - lngLo)
GetWindowTextSel = strSel
End If
End Function
Private Function SetWindowInput() As Boolean
Dim hWnd1 As Long, lngThread1 As Long
Dim hWnd2 As Long, lngThread2 As Long
hWnd1 = Me.hWnd
hWnd2 = GetForegroundWindow
lngThread1 = GetWindowThreadProcessId(hWnd1, 0)
lngThread2 = GetWindowThreadProcessId(hWnd2, 0)
If (lngThread1 <> 0) And (lngThread2 <> 0) Then
If lngThread1 = lngThread2 Then
SetWindowInput = True
Exit Function
End If
If mLngCurrThread <> lngThread2 Then
Call AttachThreadInput(lngThread1, mLngCurrThread, False)
End If
If AttachThreadInput(lngThread1, lngThread2, True) <> 0 Then
mLngCurrThread = lngThread2
End If
SetWindowInput = True
End If
End Function |