// ************************************************************************
        // ************************************************************************
        // 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);
        }
 protected void OnHookInvoked(HookEventArgs e)
 {
     if (HookInvoked != null)
         HookInvoked(this, e);
 }
        /// <summary>
        /// Handle messages for context menu
        /// </summary>
        private void WindowsHookInvoked(object sender, HookEventArgs e)
        {
            CWPSTRUCT cwp = (CWPSTRUCT)Marshal.PtrToStructure(e.lParam, typeof(CWPSTRUCT));

            if (_oContextMenu2 != null &&
                (cwp.message == (int)WM.INITMENUPOPUP ||
                 cwp.message == (int)WM.MEASUREITEM ||
                 cwp.message == (int)WM.DRAWITEM))
            {
                if (_oContextMenu2.HandleMenuMsg((uint)cwp.message, cwp.wparam, cwp.lparam) == S_OK)
                {
                    return;
                }
            }

            if (_oContextMenu3 != null && cwp.message == (int)WM.MENUCHAR)
            {
                if (_oContextMenu3.HandleMenuMsg2((uint)cwp.message, cwp.wparam, cwp.lparam, IntPtr.Zero) == S_OK)
                {
                    return;
                }
            }

            return;
        }