Thanks for the excellent suggestions. Works great now
User 1492767
Posts
-
Hooks (WH_CALLWNDPROC) -
Hooks (WH_CALLWNDPROC)Hi guys, I'm writing a program that should monitor the "active" application's copying and pasting.I decided on using use a system-wide WH_CBTPROC hook and a thread-specific WH_CALLWNDPROC hook to capture the WM_PASTE and WM_COPY messages. The hooking works OK, the problem is that the WH_CALLWNDPROC causes the menus in "Microsoft Word" not to display. Am i using the hook wrong? (Maybe not passing the messages along). And it makes the programs realllllyy slowww. I'm running a Duron 800mhz, should it have such a big influence on performance? Any Ideas? Thanks The base code looks like this.
HINSTANCE hins; HHOOK hmsg = NULL; HHOOK hcbt = NULL; BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { hins=(HINSTANCE)hModule; switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } //--------------------------------------------------------------------------- LRESULT CALLBACK MsgProc(int nCode, WPARAM wParam, LPARAM lParam) { char *file = new char[100]; file = "c:\\test.txt"; fstream out(file,ios::out | ios::app); if (nCode < 0) { LRESULT RetVal = CallNextHookEx( hmsg, nCode, wParam, lParam ); return RetVal; } if (HC_ACTION==nCode) { CWPSTRUCT *msgInfo = (CWPSTRUCT*)lParam; switch (msgInfo->message) { case WM_COPY: out << "COPY" << endl; break; case WM_PASTE: out << "PASTE" << endl; break; } } LRESULT RetVal = CallNextHookEx( hmsg, nCode, wParam, lParam ); return RetVal; } //--------------------------------------------------------------------------- LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) { char *file = new char[100]; file = "c:\\test.txt"; fstream out(file,ios::out | ios::app); DWORD ProcessId; char szModName[MAX_PATH]; HWND current_window; HANDLE hProcess; SYSTEMTIME SystemTime; if (nCode == HCBT_ACTIVATE) { current_window = (HWND)wParam; GetWindowThreadProcessId( current_window,&ProcessId); hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessId ); int length = GetModuleFileNameEx( hProcess, NULL, szModName,sizeof(szModName)); out << szModName << endl; if (hmsg == NULL) { hms