thanks for the reply, in MSDN in SetWindowsHookEx function its fourth parameter takes the Id of the thread my problem is there
============================================= qoute MSDN
HHOOK SetWindowsHookEx( int idHook, // hook type HOOKPROC lpfn, // hook procedure HINSTANCE hMod, // handle to application instance DWORD dwThreadId // thread identifier ); lpfn [in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process. hMod [in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process. dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread. ========================================= in this pice of my code private void hook() { int a=0; foreach(Process p in Process.GetProcesses()) if(p.MainWindowTitle=="Windows Media Player") a=p.Threads[0].Id;//???? hookDelegate=new HookEventHandler(hey); Form1.SetWindowsHookEx(WH_MOUSE,hookDelegate, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),a); //here instead of *a* if I send 0 as the fourth parameter it hooks //mouse event from the entire desktop not just media player window } I think I should find the id of media player thread and send it as fourth parameter but it doesn't work I try to find it when I find its process foreach(Process p in Process.GetProcesses()) if(p.MainWindowTitle=="Windows Media Player") a=p.Threads[0].Id;//????but I don't know where I am wrong? |