Beispiel #1
0
        public static void UnhookWndProc(Control ctl, bool disposing)
        {
            HookedProcInformation information = null;

            if (ctlDict.ContainsKey(ctl))
            {
                information = ctlDict[ctl];
            }
            else if (hwndDict.ContainsKey(ctl.Handle))
            {
                information = hwndDict[ctl.Handle];
            }
            if (information == null)
            {
                throw new ArgumentException("No hook exists for this control");
            }
            if (ctlDict.ContainsKey(ctl) && disposing)
            {
                ctlDict.Remove(ctl);
            }
            if (hwndDict.ContainsKey(ctl.Handle))
            {
                information.Unhook();
                hwndDict.Remove(ctl.Handle);
                if (!disposing)
                {
                    ctlDict[ctl] = information;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Restores the previous wndproc for the specified window.
        /// </summary>
        /// <param name="ctl">The control whose wndproc we no longer want to
        /// hook</param>
        /// <param name="disposing">if true we remove don't readd the
        /// HookedProcInformation
        /// back into ctlDict</param>
        public static void UnhookWndProc(Control ctl, bool disposing)
        {
            HookedProcInformation hpi = null;

            if (ctlDict.ContainsKey(ctl))
            {
                hpi = ctlDict[ctl];
            }
            else if (hwndDict.ContainsKey(ctl.Handle))
            {
                hpi = hwndDict[ctl.Handle];
            }

            if (hpi == null)
            {
                throw new ArgumentException("No hook exists for this control");
            }

            // If we found our HookedProcInformation in ctlDict and we are
            // disposing remove it from ctlDict
            if (ctlDict.ContainsKey(ctl) && disposing)
            {
                ctlDict.Remove(ctl);
            }

            // If we found our HookedProcInformation in hwndDict, remove it
            // and if we are not disposing stick it in ctlDict
            if (hwndDict.ContainsKey(ctl.Handle))
            {
                hpi.Unhook();
                hwndDict.Remove(ctl.Handle);
                if (!disposing)
                {
                    ctlDict[ctl] = hpi;
                }
            }
        }