示例#1
0
        private static void OnCopyBitsBehaviorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            HwndHost hwndHost = d as HwndHost;

            if (hwndHost != null)
            {
                CopyBitsBehavior newValue = (CopyBitsBehavior)e.NewValue;
                if (newValue != CopyBitsBehavior.Default)
                {
                    AddWndProcUsage(hwndHost);
                }
                else
                {
                    RemoveWndProcUsage(hwndHost);
                }
            }
        }
示例#2
0
            protected override IntPtr WndProcOverride(HWND hwnd, WM msg, IntPtr wParam, IntPtr lParam, IntPtr id, IntPtr data)
            {
                IntPtr?result = null;

                if (msg == WM.WINDOWPOSCHANGING)
                {
                    unsafe
                    {
                        WINDOWPOS *pWindowPos = (WINDOWPOS *)lParam;

                        CopyBitsBehavior copyBitsBehavior = _hwndHost.GetCopyBitsBehavior();

                        switch (copyBitsBehavior)
                        {
                        case CopyBitsBehavior.AlwaysCopyBits:
                            pWindowPos->flags &= ~SWP.NOCOPYBITS;
                            break;

                        case CopyBitsBehavior.CopyBitsAndRepaint:
                            pWindowPos->flags &= ~SWP.NOCOPYBITS;
                            if (!_redrawMessagePosted)
                            {
                                NativeMethods.PostMessage(hwnd, _redrawMessage, IntPtr.Zero, IntPtr.Zero);
                                _redrawMessagePosted = true;
                            }
                            break;

                        case CopyBitsBehavior.NeverCopyBits:
                            pWindowPos->flags |= SWP.NOCOPYBITS;
                            break;

                        case CopyBitsBehavior.Default:
                        default:
                            // do nothing.
                            break;
                        }
                    }
                }
                else if (msg == _redrawMessage)
                {
                    _redrawMessagePosted = false;

                    // Invalidate the window that moved, because it might have copied garbage
                    // due to WPF rendering through DX on a different thread.
                    NativeMethods.RedrawWindow(hwnd, IntPtr.Zero, IntPtr.Zero, RDW.INVALIDATE | RDW.ALLCHILDREN);

                    // Then immediately redraw all invalid regions within the top-level window.
                    HWND hwndRoot = NativeMethods.GetAncestor(hwnd, GA.ROOT);
                    NativeMethods.RedrawWindow(hwndRoot, IntPtr.Zero, IntPtr.Zero, RDW.UPDATENOW | RDW.ALLCHILDREN);
                }
                else if (msg == WM.MOUSEACTIVATE)
                {
                    bool raiseMouseActivateCommand = _hwndHost.GetRaiseMouseActivateCommand();
                    if (raiseMouseActivateCommand)
                    {
                        // Raise the HwndHostCommands.MouseActivate command.
                        MouseActivateParameter parameter = new MouseActivateParameter();
                        HwndHostCommands.MouseActivate.Execute(parameter, _hwndHost);

                        if (parameter.HandleMessage)
                        {
                            if (parameter.Activate == false && parameter.EatMessage == false)
                            {
                                result = new IntPtr((int)MA.NOACTIVATE);
                            }
                            else if (parameter.Activate == false && parameter.EatMessage == true)
                            {
                                result = new IntPtr((int)MA.NOACTIVATEANDEAT);
                            }
                            else if (parameter.Activate == true && parameter.EatMessage == false)
                            {
                                result = new IntPtr((int)MA.ACTIVATE);
                            }
                            else   // if(parameter.Activate == true && parameter.EatMessage == true)
                            {
                                result = new IntPtr((int)MA.ACTIVATEANDEAT);
                            }
                        }
                    }
                }

                return(result ?? base.WndProcOverride(hwnd, msg, wParam, lParam, id, data));
            }
示例#3
0
 /// <summary>
 ///     Attached property setter for the CopyBitsBehavior property.
 /// </summary>
 public static void SetCopyBitsBehavior(this HwndHost @this, CopyBitsBehavior value)
 {
     @this.SetValue(CopyBitsBehaviorProperty, value);
 }
 /// <summary>
 ///     Attached property setter for the CopyBitsBehavior property.
 /// </summary>
 public static void SetCopyBitsBehavior(this HwndHost @this, CopyBitsBehavior value)
 {
     @this.SetValue(CopyBitsBehaviorProperty, value);
 }