/// Handle messages for context menu void WindowsHookInvoked(object sender, HookEventArgs e) { CWPSTRUCT cwp = (CWPSTRUCT)Marshal.PtrToStructure(e.lParam, typeof(CWPSTRUCT)); if (_ContextMenu2 != null && (cwp.message == (int)WM.INITMENUPOPUP || cwp.message == (int)WM.MEASUREITEM || cwp.message == (int)WM.DRAWITEM)) { if (_ContextMenu2.HandleMenuMsg((uint)cwp.message, cwp.wparam, cwp.lparam) == S_OK) { return; } } if (_ContextMenu3 != null && cwp.message == (int)WM.MENUCHAR) { if (_ContextMenu3.HandleMenuMsg2((uint)cwp.message, cwp.wparam, cwp.lparam, IntPtr.Zero) == S_OK) { return; } } return; }
protected void OnHookInvoked(HookEventArgs e) { if (HookInvoked != null) { HookInvoked(this, e); } }
// Default filter function protected int CoreHookProc(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) { return(CallNextHookEx(m_hhook, code, wParam, lParam)); } // Let clients determine what to do HookEventArgs e = new HookEventArgs(); e.HookCode = code; e.wParam = wParam; e.lParam = lParam; OnHookInvoked(e); // Yield to the next hook in the chain return(CallNextHookEx(m_hhook, code, wParam, lParam)); }