Exemple #1
0
        /// <summary>
        /// This is a generic wndproc. It is the callback for all hooked
        /// windows. If we get into this function, we look up the hwnd in the
        /// global list of all hooked windows to get its message map. If the
        /// message received is present in the message map, its callback is
        /// invoked with the parameters listed here.
        /// </summary>
        /// <param name="hwnd">The handle to the window that received the
        /// message</param>
        /// <param name="msg">The message</param>
        /// <param name="wParam">The message's parameters (part 1)</param>
        /// <param name="lParam">The messages's parameters (part 2)</param>
        /// <returns>If the callback handled the message, the callback's return
        /// value is returned form this function. If the callback didn't handle
        /// the message, the message is forwarded on to the previous wndproc.
        /// </returns>
        private static int WindowProc(
            IntPtr hwnd, uint msg, uint wParam, int lParam)
        {
            if (hwndDict.ContainsKey(hwnd))
            {
                HookedProcInformation hpi = hwndDict[hwnd];
                if (hpi.messageMap.ContainsKey(msg))
                {
                    WndProcCallback callback = hpi.messageMap[msg];
                    bool            handled  = false;
                    int             retval   = callback(hwnd, msg, wParam, lParam, ref handled);
                    if (handled)
                    {
                        return(retval);
                    }
                }

                // if we didn't hook the message passed or we did, but the
                // callback didn't set the handled property to true, call
                // the original window procedure
                return(hpi.CallOldWindowProc(hwnd, msg, wParam, lParam));
            }

            System.Diagnostics.Debug.Assert(
                false, "WindowProc called for hwnd we don't know about");
            return(Win32.DefWindowProc(hwnd, msg, wParam, lParam));
        }
Exemple #2
0
        private static int WindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam)
        {
            if (!hwndDict.ContainsKey(hwnd))
            {
                return(Win32.DefWindowProc(hwnd, msg, wParam, lParam));
            }
            HookedProcInformation information = hwndDict[hwnd];

            if (information.messageMap.ContainsKey(msg))
            {
                WndProcCallback callback = information.messageMap[msg];
                bool            handled  = false;
                int             num      = callback(hwnd, msg, wParam, lParam, ref handled);
                if (handled)
                {
                    return(num);
                }
            }
            return(information.CallOldWindowProc(hwnd, msg, wParam, lParam));
        }