Files
jlibwinapi/native/MsgHook/MsgHook.cpp
Edward Jakubowski 1721d2a130 Fixed highlighting around WPF and Silverlight, fixed windows commands to use WPF runtimeIds,Adding Windows Message hook feature
When targeting WPF and silverlight applications synthuse will now target
each object with a red rectangle, just like it does with native win 32
applications.
Windows commands like setfocus and such are now supported with UIA
objects like (WPF, WinForm, Silverlight).
Adding support for hooking in to the Message Queue of a target window to
see what Messages are being sent, this will allow one to possible resend
the messages back for automation purposes.  This feature is not fully
working yet, but is close.
2014-05-21 08:12:11 -04:00

64 lines
1.7 KiB
C++

/*
* Copyright 2014, Synthuse.org
* Released under the Apache Version 2.0 License.
*
* last modified by ejakubowski7@gmail.com
*/
// MsgHook.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
COPYDATASTRUCT CDS;
HEVENT Event;
CDS.dwData = 0;
CDS.cbData = sizeof(Event);
CDS.lpData = &Event;
if (nCode == HC_ACTION) {
//For WH_CALLWNDPROC hook a pointer to a CWPSTRUCT structure that contains details about the message.
CWPSTRUCT *cwps = (CWPSTRUCT *)lParam;
Event.lParam = cwps->lParam;
Event.wParam = cwps->wParam;
Event.nCode = cwps->message;
Event.dwHookType = WH_CALLWNDPROC;
BOOL bRes = SendMessage(pData->g_hWnd, WM_COPYDATA, 0, (LPARAM)(VOID*)&CDS); // ask the controlling program if the hook should be passed
}
return CallNextHookEx(pData->g_hHook, nCode, wParam, lParam); // pass hook to next handler
//return bRes; // Don't tell the other hooks about this message.
}
extern "C" __declspec(dllexport) BOOL SetHook(HWND callerHWnd, DWORD threadId)
{
if(bStartingProcess) // if we're just starting the DLL for the first time,
{
pData->g_hWnd = callerHWnd; // remember the windows and hook handle for further instances
pData->g_hHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)HookProc, (HINSTANCE)pData->g_hInstance, threadId);
return (pData->g_hHook != NULL);
}
else
return false;
}
extern "C" __declspec(dllexport) BOOL RemoveHook()
{
if (pData == NULL)
return false;
if(pData->g_hHook) // if the hook is defined
{
bool ret = UnhookWindowsHookEx(pData->g_hHook);
pData->g_hWnd = NULL; // reset data
pData->g_hHook = NULL;
return ret;
}
return false;
}