ACPAddIn.ThisAddIn.MouseHookProc C# (CSharp) Method

MouseHookProc() private method

private MouseHookProc ( int nCode, IntPtr wParam, IntPtr lParam ) : int
nCode int
wParam IntPtr
lParam IntPtr
return int
        private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            // Per docs, if nCode < 0, the hook procedure must pass the
            // message to CallNextHookEx function without further processing
            // and should return the value returned by CallNextHookEx.
            if (nCode < 0)
            {
                return CallNextHookEx(mouseHookHandle, nCode, wParam, lParam);
            }
            else
            {
                // The lparam that Windows passes us is a pointer to a
                // MouseHookStruct.
                MouseHookStruct mouseHookStruct =
                    (MouseHookStruct)
                    Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));

                // Hide the auto-completion box when a mouse click is detected outside the box.
                if (!isCoordinateWithinForm(mouseHookStruct.pt.x, mouseHookStruct.pt.y, autoCompleteForm))
                {
                    if (autoCompleteForm.Visible && ((WM)wParam.ToInt32() == WM.LBUTTONDOWN || (WM)wParam.ToInt32() == WM.NCLBUTTONDOWN))
                    {
                        autoCompleteForm.Hide();
                    }
                }

                // Hide the auto-completion box when a mouse wheel event is detected.
                if (autoCompleteForm.Visible && (WM)wParam.ToInt32() == WM.MOUSEWHEEL)
                {
                    autoCompleteForm.Hide();
                }

                if (autoCompleteForm.Visible && (WM)wParam.ToInt32() == WM.MOUSEHWHEEL)
                {
                    autoCompleteForm.Hide();
                }

                if (((WM)wParam.ToInt32() == WM.LBUTTONDOWN || (WM)wParam.ToInt32() == WM.NCLBUTTONDOWN))
                {
                    if (extMode.isExtensionMode())
                    {
                        extMode.resetExtensionMode();
                        extendSuggestionForm.fadeOut();
                    }
                }

                // Ensure that we don't break the hook chain.
                return CallNextHookEx(mouseHookHandle, nCode, wParam, lParam);
            }
        }