Example #1
0
        //IntPtr IMdiClientWindow.Handle => base.Handle;

        internal JwMdiClientSubclass(JwMdiManager mdiManager)
        {
            _manager = mdiManager;
            UpdateBorderStyle();
        }
Example #2
0
        protected override void WndProc(ref Message m)
        {
            JwMdiManager ultraTabbedMdiManager = _manager;

            if (ultraTabbedMdiManager == null)
            {
                base.WndProc(ref m);
                return;
            }
            switch (m.Msg)
            {
            case (int)WinApi.Messages.WM_MDIRESTORE:
            case (int)WinApi.Messages.WM_MDIMAXIMIZE:
            case (int)WinApi.Messages.WM_MDITILE:
            case (int)WinApi.Messages.WM_MDICASCADE:
            case (int)WinApi.Messages.WM_MDIICONARRANGE:
                //if (ultraTabbedMdiManager.Enabled)
                //{
                m.Result = IntPtr.Zero;
                return;

            //}
            //break;
            case (int)WinApi.Messages.WM_MDINEXT:
            {
                Form mdiChild = null;
                if (m.WParam == IntPtr.Zero)
                {
                    Control control = Control.FromChildHandle(base.Handle);
                    if (control is Form)
                    {
                        mdiChild = ((Form)control).ActiveMdiChild;
                    }
                }
                else
                {
                    mdiChild = (Control.FromHandle(m.WParam) as Form);
                }
                bool forward    = m.LParam == IntPtr.Zero;
                Form nextWindow = GetNextWindow(mdiChild, forward);
                if (ultraTabbedMdiManager.TabNavigationMode == MdiTabNavigationMode.VisibleOrder)
                {
                    nextWindow?.Activate();
                    m.Result = IntPtr.Zero;
                    return;
                }
                if (!SendActivationNotification(nextWindow))
                {
                    break;
                }
                if (AllowMdiChildActivate(nextWindow))
                {
                    ultraTabbedMdiManager.SubclasserActivatingMdiChild = true;
                    try
                    {
                        base.WndProc(ref m);
                    }
                    finally
                    {
                        ultraTabbedMdiManager.SubclasserActivatingMdiChild = false;
                        ultraTabbedMdiManager.AfterSubclasserFormActivation(nextWindow);
                    }
                }
                else
                {
                    m.Result = IntPtr.Zero;
                }
                return;
            }

            case (int)WinApi.Messages.WM_MDIACTIVATE:
            {
                Form form = Control.FromHandle(m.WParam) as Form;
                if (!SendActivationNotification(form))
                {
                    break;
                }
                if (AllowMdiChildActivate(form))
                {
                    ultraTabbedMdiManager.SubclasserActivatingMdiChild = true;
                    try
                    {
                        base.WndProc(ref m);
                    }
                    finally
                    {
                        ultraTabbedMdiManager.SubclasserActivatingMdiChild = false;
                        ultraTabbedMdiManager.AfterSubclasserFormActivation(form);
                    }
                }
                else
                {
                    m.Result = IntPtr.Zero;
                }
                return;
            }

            case (int)WinApi.Messages.WM_NCPAINT:
            {
                base.WndProc(ref m);
                if (!IsManagerEnabled)
                {
                    return;
                }
                IntPtr   intPtr   = IntPtr.Zero;
                Graphics graphics = null;
                IntPtr   hWnd     = m.HWnd;
                try
                {
                    Rectangle rectangle = new Rectangle(Point.Empty, DisplayRectangle.Size);
                    if (m.WParam == IntPtr.Zero || m.WParam.ToInt64() == 1)
                    {
                        intPtr = WinApi.GetWindowDC(hWnd);
                    }
                    else
                    {
                        intPtr = WinApi.GetDCEx(hWnd, m.WParam, 129);
                        if (intPtr == IntPtr.Zero)
                        {
                            intPtr = WinApi.GetWindowDC(m.HWnd);
                        }
                    }
                    if (intPtr != IntPtr.Zero)
                    {
                        SecurityPermission securityPermission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
                        securityPermission.Assert();
                        graphics = Graphics.FromHdc(intPtr);
                        CodeAccessPermission.RevertAssert();
                        DrawBorder(graphics, rectangle, rectangle);
                        m.Result = IntPtr.Zero;
                    }
                }
                finally
                {
                    graphics?.Dispose();
                    if (intPtr != IntPtr.Zero)
                    {
                        WinApi.ReleaseDC(hWnd, intPtr);
                    }
                }
                return;
            }

            case (int)WinApi.Messages.WM_NCCALCSIZE:
                if (IsManagerEnabled && m.WParam.ToInt64() == 1)
                {
                    NativeWindowMethods.NCCALCSIZE_PARAMS nCCALCSIZE_PARAMS = (NativeWindowMethods.NCCALCSIZE_PARAMS)m.GetLParam(typeof(NativeWindowMethods.NCCALCSIZE_PARAMS));
                    UIElementBorderWidths borderWidth = GetBorderWidth();
                    displayRect = nCCALCSIZE_PARAMS.rectProposed.Rect;
                    nCCALCSIZE_PARAMS.rectProposed.left   += borderWidth.Left;
                    nCCALCSIZE_PARAMS.rectProposed.right  -= borderWidth.Right;
                    nCCALCSIZE_PARAMS.rectProposed.top    += borderWidth.Top;
                    nCCALCSIZE_PARAMS.rectProposed.bottom -= borderWidth.Bottom;
                    Marshal.StructureToPtr(nCCALCSIZE_PARAMS, m.LParam, fDeleteOld: false);
                }
                break;

            case (int)WinApi.Messages.WM_ERASEBKGND:
                base.WndProc(ref m);
                if (IsManagerEnabled)
                {
                    m.Result = new IntPtr(1);
                }
                return;

            case (int)WinApi.Messages.WM_PARENTNOTIFY:
                if ((m.WParam.ToInt32() & 0xFFFF) == 1)
                {
                    _manager.MdiClientCreateNotification();
                }
                break;
            }
            base.WndProc(ref m);
        }
Example #3
0
 private void Unhook()
 {
     _manager = null;
     UpdateBorderStyle();
 }