コード例 #1
0
    protected override void OnParentChanged(EventArgs e)
    {
        if (prevParent != null)
        {
            WndProcHooker.UnhookWndProc(prevParent, WM_LBUTTONDOWN);
            WndProcHooker.UnhookWndProc(prevParent, WM_LBUTTONUP);
        }
        prevParent = Parent;

        if (Parent != null)
        {
            WndProcHooker.HookWndProc(Parent, WM_LBUTTONDOWN_Handler, WM_LBUTTONDOWN);
            WndProcHooker.HookWndProc(Parent, WM_LBUTTONUP_Handler, WM_LBUTTONUP);
        }
        base.OnParentChanged(e);
    }
コード例 #2
0
        /// <summary>
        /// Called when the control's parent is changed. Here we hook into that
        /// parent's WndProc and spy on the WM_NOTIFY message. When the parent
        /// changes, we unhook the old parent's WndProc and hook into the new one.
        /// </summary>
        /// <param name="e">The arguments for this event</param>
        protected override void OnParentChanged(EventArgs e)
        {
            // unhook the old parent
            if (this.prevParent != null)
            {
                WndProcHooker.UnhookWndProc(prevParent, WinApi.WM_NOTIFY);
            }
            // update the previous parent
            prevParent = this.Parent;

            // hook up the new parent
            if (this.Parent != null)
            {
                WndProcHooker.HookWndProc(this.Parent,
                                          new WndProcHooker.WndProcCallback(this.WM_Notify_Handler),
                                          WinApi.WM_NOTIFY);
            }

            base.OnParentChanged(e);
        }