Exemple #1
0
        /// <summary>
        /// Function to process the messages through the installed message filters.
        /// </summary>
        /// <param name="hwnd">Window handle receiving the message.</param>
        /// <param name="msg">Message being received.</param>
        /// <param name="wParam">Window parameter 1.</param>
        /// <param name="lParam">Window parameter 2.</param>
        /// <returns>The result of a call to the previous window procedure if the message was not processed, or <see cref="IntPtr.Zero"/> if the message was processed.</returns>
        private IntPtr NewWndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
        {
            if (!_hooked)
            {
                UninstallWindowProcedure();
                return(UserApi.CallWindowProc(_defaultWndProc, hwnd, msg, wParam, lParam));
            }

            var windowMessage = new Message
            {
                HWnd   = hwnd,
                Msg    = msg,
                WParam = wParam,
                LParam = lParam
            };

            // Send a copy of the message to any installed filters.
            // ReSharper disable once LoopCanBeConvertedToQuery
            // ReSharper disable once ForCanBeConvertedToForeach
            for (int i = 0; i < _messageFilters.Count; i++)
            {
                // ReSharper disable once InconsistentlySynchronizedField
                IMessageFilter filter = _messageFilters[i];

                if (filter.PreFilterMessage(ref windowMessage))
                {
                    return(windowMessage.Result);
                }
            }

            return(UserApi.CallWindowProc(_defaultWndProc, hwnd, msg, wParam, lParam));
        }