public Hook(IMessageHandlerClient client) { m_Client=client; m_mouseHook = new MouseProc(OnMouseHook); m_keyboardHook=new KeyboardProc(OnKeyboardHook); m_hMouseHook = SetWindowsHookEx(WH_MOUSE, m_mouseHook, IntPtr.Zero, GetCurrentThreadId()); m_hKeyboardHook=SetWindowsHookExKeyboard(WH_KEYBOARD,m_keyboardHook,IntPtr.Zero,GetCurrentThreadId()); if (m_hMouseHook == IntPtr.Zero || m_hKeyboardHook==IntPtr.Zero) { throw new Win32Exception(); } }
public static void UnregisterMessageClient(IMessageHandlerClient client) { if (m_Clients.Contains(client)) { LockCookie cookie1 = new LockCookie(); bool readerLockHeld = MessageHandler.rwClientsListLock.IsReaderLockHeld; if (readerLockHeld) { cookie1 = MessageHandler.rwClientsListLock.UpgradeToWriterLock(-1); } else { MessageHandler.rwClientsListLock.AcquireWriterLock(-1); } bool unregister = false; try { m_Clients.Remove(client); unregister = m_Clients.Count == 0; } finally { if (readerLockHeld) { MessageHandler.rwClientsListLock.DowngradeFromWriterLock(ref cookie1); } else { MessageHandler.rwClientsListLock.ReleaseWriterLock(); } } if (BarUtilities.AutoRemoveMessageFilter && unregister && m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode())) UninstallMessageFilter(); } }
public static void RegisterMessageClient(IMessageHandlerClient client) { if(m_Clients.Contains(client)) return; if(!m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode())) InstallMessageFilter(); LockCookie cookie1 = new LockCookie(); bool readerLockHeld = MessageHandler.rwClientsListLock.IsReaderLockHeld; if (readerLockHeld) { cookie1 = MessageHandler.rwClientsListLock.UpgradeToWriterLock(-1); } else { MessageHandler.rwClientsListLock.AcquireWriterLock(-1); } try { m_Clients.Add(client); } finally { if (readerLockHeld) { MessageHandler.rwClientsListLock.DowngradeFromWriterLock(ref cookie1); } else { MessageHandler.rwClientsListLock.ReleaseWriterLock(); } } }
private static bool IsInvokeRequired(IMessageHandlerClient client) { DotNetBarManager manager = client as DotNetBarManager; if (manager != null && manager.ParentForm != null && manager.ParentForm.InvokeRequired) return true; else if (client is Control && ((Control)client).InvokeRequired) return true; return false; }