Ejemplo n.º 1
0
        public static void HookWndProc(Control ctl, WndProcCallback callback, uint msg)
        {
            HookedProcInformation information = null;

            if (ctlDict.ContainsKey(ctl))
            {
                information = ctlDict[ctl];
            }
            else if (hwndDict.ContainsKey(ctl.Handle))
            {
                information = hwndDict[ctl.Handle];
            }
            if (information == null)
            {
                information          = new HookedProcInformation(ctl, new Win32.WndProc(WndProcHooker.WindowProc));
                ctl.HandleCreated   += new EventHandler(WndProcHooker.ctl_HandleCreated);
                ctl.HandleDestroyed += new EventHandler(WndProcHooker.ctl_HandleDestroyed);
                ctl.Disposed        += new EventHandler(WndProcHooker.ctl_Disposed);
                if (ctl.Handle != IntPtr.Zero)
                {
                    information.SetHook();
                }
            }
            if (ctl.Handle == IntPtr.Zero)
            {
                ctlDict[ctl] = information;
            }
            else
            {
                hwndDict[ctl.Handle] = information;
            }
            information.messageMap[msg] = callback;
        }
Ejemplo n.º 2
0
        private static void ctl_HandleCreated(object sender, EventArgs e)
        {
            Control key = sender as Control;

            if (ctlDict.ContainsKey(key))
            {
                HookedProcInformation information = ctlDict[key];
                hwndDict[key.Handle] = information;
                ctlDict.Remove(key);
                information.SetHook();
            }
        }
Ejemplo n.º 3
0
        // Makes a connection between a message on a specified window handle
        // and the callback to be called when that message is received. If the
        // window was not previously hooked it is added to the global list of
        // all the window procedures hooked.
        // Parameters:
        // ctl - The control whose wndproc we are hooking.
        // callback - The method to call when the specified.
        // message is received for the specified window.
        // msg - The message being hooked.
        public static void HookWndProc(
            Control ctl,
            WndProcCallback callback,
            uint msg)
        {
            HookedProcInformation hpi = null;

            if (CtlDict.ContainsKey(ctl))
            {
                hpi = CtlDict[ctl];
            }
            else if (HwndDict.ContainsKey(ctl.Handle))
            {
                hpi = HwndDict[ctl.Handle];
            }
            if (hpi == null)
            {
                // If new control, create a new
                // HookedProcInformation for it.
                hpi = new HookedProcInformation(
                    ctl,
                    WindowProc);
                ctl.HandleCreated   += ctl_HandleCreated;
                ctl.HandleDestroyed += ctl_HandleDestroyed;
                ctl.Disposed        += ctl_Disposed;

                // If the handle has already been created set the hook. If it
                // hasn't been created yet, the hook will get set in the
                // ctl_HandleCreated event handler.
                if (ctl.Handle != IntPtr.Zero)
                {
                    hpi.SetHook();
                }
            }

            // Stick hpi into the correct dictionary.
            if (ctl.Handle == IntPtr.Zero)
            {
                CtlDict[ctl] = hpi;
            }
            else
            {
                HwndDict[ctl.Handle] = hpi;
            }

            // Add the message/callback into the message map.
            hpi.MessageMap[msg] = callback;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The event handler called when a control's handle is created. We
        /// call SetHook() on the associated HookedProcInformation object and
        /// move it from <see>ctlDict</see> to <see>hwndDict</see>.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void ctl_HandleCreated(object sender, EventArgs e)
        {
            Control ctl = sender as Control;

            if (ctlDict.ContainsKey(ctl))
            {
                HookedProcInformation hpi = ctlDict[ctl];
                hwndDict[ctl.Handle] = hpi;
                ctlDict.Remove(ctl);
                hpi.SetHook();
            }
            else
            {
                System.Diagnostics.Debug.Assert(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Makes a connection between a message on a specified window handle
        /// and the callback to be called when that message is received. If the
        /// window was not previously hooked it is added to the global list of
        /// all the window procedures hooked.
        /// </summary>
        /// <param name="ctl">The control whose wndproc we are hooking</param>
        /// <param name="callback">The method to call when the specified
        /// message is received for the specified window</param>
        /// <param name="msg">The message we are hooking.</param>
        public static void HookWndProc(
            Control ctl, WndProcCallback callback, uint msg)
        {
            HookedProcInformation hpi = null;

            if (ctlDict.ContainsKey(ctl))
            {
                hpi = ctlDict[ctl];
            }
            else if (hwndDict.ContainsKey(ctl.Handle))
            {
                hpi = hwndDict[ctl.Handle];
            }
            if (hpi == null)
            {
                // We havne't seen this control before. Create a new
                // HookedProcInformation for it
                hpi = new HookedProcInformation(ctl,
                                                new Win32.WndProc(WndProcHooker.WindowProc));
                ctl.HandleCreated   += new EventHandler(ctl_HandleCreated);
                ctl.HandleDestroyed += new EventHandler(ctl_HandleDestroyed);
                ctl.Disposed        += new EventHandler(ctl_Disposed);

                // If the handle has already been created set the hook. If it
                // hasn't been created yet, the hook will get set in the
                // ctl_HandleCreated event handler
                if (ctl.Handle != IntPtr.Zero)
                {
                    hpi.SetHook();
                }
            }

            // stick hpi into the correct dictionary
            if (ctl.Handle == IntPtr.Zero)
            {
                ctlDict[ctl] = hpi;
            }
            else
            {
                hwndDict[ctl.Handle] = hpi;
            }

            // add the message/callback into the message map
            hpi.messageMap[msg] = callback;
        }
Ejemplo n.º 6
0
        // Makes a connection between a message on a specified window handle
        // and the callback to be called when that message is received. If the
        // window was not previously hooked it is added to the global list of
        // all the window procedures hooked.
        // Parameters:
        // ctl - The control whose wndproc we are hooking.
        // callback - The method to call when the specified.
        // message is received for the specified window.
        // msg - The message being hooked.
        public static void HookWndProc(
            Control ctl, WndProcCallback callback, uint msg)
        {
            HookedProcInformation hpi = null;
            if (ctlDict.ContainsKey(ctl))
                hpi = ctlDict[ctl];
            else if (hwndDict.ContainsKey(ctl.Handle))
                hpi = hwndDict[ctl.Handle];
            if (hpi == null) {
                // If new control, create a new
                // HookedProcInformation for it.
                hpi = new HookedProcInformation(ctl,
                    new Win32.WndProc(WndProcHooker.WindowProc));
                ctl.HandleCreated += new EventHandler(ctl_HandleCreated);
                ctl.HandleDestroyed += new EventHandler(ctl_HandleDestroyed);
                ctl.Disposed += new EventHandler(ctl_Disposed);

                // If the handle has already been created set the hook. If it
                // hasn't been created yet, the hook will get set in the
                // ctl_HandleCreated event handler.
                if (ctl.Handle != IntPtr.Zero)
                    hpi.SetHook();
            }

            // Stick hpi into the correct dictionary.
            if (ctl.Handle == IntPtr.Zero)
                ctlDict[ctl] = hpi;
            else
                hwndDict[ctl.Handle] = hpi;

            // Add the message/callback into the message map.
            hpi.messageMap[msg] = callback;
        }