コード例 #1
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            // Ignore clicks if desktop composition isn't enabled
            case DwmApiInterop.WM_NCHITTEST:
                if (DwmApiInterop.IsCompositionEnabled() &&
                    DwmApiInterop.IsOnClientArea(hwnd, msg, wParam, lParam) &&
                    IsOnExtendedFrame(lParam.ToInt32()))
                {
                    handled = true;
                    return(new IntPtr(DwmApiInterop.HTCAPTION));
                }

                return(IntPtr.Zero);

            // Also toggle window frame painting on this window when desktop composition is toggled
            case DwmApiInterop.WM_DWMCOMPOSITIONCHANGED:
                try
                {
                    AdjustWindowFrame();
                }
                catch (InvalidOperationException)
                {
                    FallbackPaint();
                }
                return(IntPtr.Zero);

            default:
                return(IntPtr.Zero);
            }
        }
コード例 #2
0
 private void AdjustWindowFrame()
 {
     if (DwmApiInterop.IsCompositionEnabled())
     {
         ExtendFrameIntoClientArea(0, 0, 32, 35);
     }
     else
     {
         FallbackPaint();
     }
 }
コード例 #3
0
        private void ExtendFrameIntoClientArea(int left, int right, int top, int bottom)
        {
            var margins = new MARGINS {
                cxLeftWidth = left, cxRightWidth = right, cyTopHeight = top, cyBottomHeight = bottom
            };
            int hresult = DwmApiInterop.ExtendFrameIntoClientArea(hwnd, ref margins);

            if (hresult == 0)
            {
                hsource.CompositionTarget.BackgroundColor = Colors.Transparent;
                Background = Brushes.Transparent;
            }
            else
            {
                throw new InvalidOperationException("Could not extend window frames in the main window.");
            }
        }