Esempio n. 1
0
            public void OnMessage(ref Message m)
            {
                // We want these messages to go through the designer's WndProc method, and we want people to be able
                // to do default processing with the designer's DefWndProc.  So, we stuff ourselves into the designers
                // window target and call their WndProc.
                ControlDesigner currentDesigner = _designer;

                if (currentDesigner != null)
                {
                    IDesignerTarget designerTarget = currentDesigner.DesignerTarget;
                    currentDesigner.DesignerTarget = this;
                    try
                    {
                        currentDesigner.WndProc(ref m);
                    }
                    catch (Exception ex)
                    {
                        currentDesigner.SetUnhandledException(currentDesigner.Control, ex);
                    }
                    finally
                    {
                        currentDesigner.DesignerTarget = designerTarget;
                    }
                }
                else
                {
                    DefWndProc(ref m);
                }
            }
            public void OnMessage(ref Message m)
            {
                // If the designer has jumped ship, the continue partying on messages, but send them back to the original control.
                if (_designer.Component is null)
                {
                    OldWindowTarget.OnMessage(ref m);
                    return;
                }

                // We want these messages to go through the designer's WndProc method, and we want people to be able
                // to do default processing with the designer's DefWndProc.  So, we stuff the old window target into
                // the designer's target and then call their WndProc.
                IDesignerTarget designerTarget = _designer.DesignerTarget;

                _designer.DesignerTarget = this;

                try
                {
                    _designer.WndProc(ref m);
                }
                catch (Exception ex)
                {
                    _designer.SetUnhandledException(_childControl, ex);
                }
                finally
                {
                    // If the designer disposed us, then we should follow suit.
                    if (_designer.DesignerTarget is null)
                    {
                        designerTarget.Dispose();
                    }
                    else
                    {
                        _designer.DesignerTarget = designerTarget;
                    }

                    // Controls (primarily RichEdit) will register themselves as drag-drop source/targets when they
                    // are instantiated. Normally, when they are being designed, we will RevokeDragDrop() in their
                    // designers. The problem occurs when these controls are inside a UserControl. At that time, we
                    // do not have a designer for these controls, and they prevent the ParentControlDesigner's
                    // drag-drop from working. What we do is to loop through all child controls that do not have a
                    // designer (in HookChildControls()), and RevokeDragDrop() after their handles have been created.
                    if (m.Msg == (int)User32.WM.CREATE)
                    {
                        Debug.Assert(_handle != IntPtr.Zero, "Handle for control not created");
                        Ole32.RevokeDragDrop(_handle);
                    }
                }
            }
            protected override void WndProc(ref Message m)
            {
                if (_designer is null)
                {
                    DefWndProc(ref m);
                    return;
                }

                if (m.Msg == (int)User32.WM.DESTROY)
                {
                    _designer.RemoveSubclassedWindow(m.HWnd);
                }

                if (m.Msg == (int)User32.WM.PARENTNOTIFY && PARAM.LOWORD(m.WParam) == (short)User32.WM.CREATE)
                {
                    _designer.HookChildHandles(m.LParam); // they will get removed from the collection just above
                }

                // We want these messages to go through the designer's WndProc method, and we want people to be able
                // to do default processing with the designer's DefWndProc.  So, we stuff ourselves into the designers
                // window target and call their WndProc.
                IDesignerTarget designerTarget = _designer.DesignerTarget;

                _designer.DesignerTarget = this;
                Debug.Assert(m.HWnd == Handle, "Message handle differs from target handle");

                try
                {
                    _designer.WndProc(ref m);
                }
                catch (Exception ex)
                {
                    _designer.SetUnhandledException(Control.FromChildHandle(m.HWnd), ex);
                }
                finally
                {
                    // make sure the designer wasn't destroyed
                    if (_designer != null && _designer.Component != null)
                    {
                        _designer.DesignerTarget = designerTarget;
                    }
                }
            }