Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture the events of a window in another thread 1

Status
Not open for further replies.

aitor

Programmer
May 15, 2001
18
ES
I want to "hook" into a window`s events using the API SetWindowLong (with GWL_WNDPROC index to replace the window procedure) and overloading the WindowProc callback function. There is no problem if the window belongs to the same process as the calling thread, but if the window we want to hook into belongs to another thread the SetWindowLong function fails. I thought that the solution could be related to the use of AttachThreadInput API, but although the return value of this function is OK, the SetWindowLong keeps failing. Any idea? The goal is to flash a parent window when its child window becomes active (the problem is that the child window belongs to another process (Active X EXE)

/CODE
lngChildThreadId = GetCurrentThreadId
lngServiceThreadId = GetWindowThreadProcessId(MyServicelngWndHandle, lngServiceProcessId)
lngSuccess = AttachThreadInput(lngServiceThreadId, lngChildThreadId, True)

Call ActivateHook(MyServicelngWndHandle, Me.hwnd)

Public Sub ActivateHook(ByVal hwnd As Long, ByVal ChildWnd As Long)
lngPrevProcAdress = SetWindowLong(hwnd, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub

Public Sub DeActivateHook(ByVal hwnd As Long)
Dim lngTemp as long
lngTemp = SetWindowLong(hwnd, GWL_WNDPROC, lngPrevProcAdress)
End Sub

Function WindowProc(ByVal hw As Long, ByVal uMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Dim test1 As clsTest
Set test1 = m_colHandles(CStr(hw))
If uMsg = WM_ACTIVATE Then
Call FlashWindow(test1.Child, 1)
If wParam = WA_CLICKACTIVE Then
Call SetForegroundWindow(test1.Child)
End If
End If
WindowProc = CallWindowProc(test1.Handle, hw, _
uMsg, wParam, lParam)
End Function

/END CODE
 
You may want to look at the SetWindowsHookEx API. However, in order to hook into the OS event queue of another process with this API, the callback MUST be in a standard Win32 DLL so placing the callback in a Bas module will not work. Additionally, since the callback must reside in a standard Win32 DLL, a VB ActiveX DLL will not work (or if it will, I have not seen how to do it).
To make this work, you must create a basic C++ Win32 DLL and place the callback in there. - Jeff Marler B-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top