示例#1
0
		static extern IntPtr DwmEnableBlurBehindWindow (IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);
 internal static extern void DwmEnableBlurBehindWindow( IntPtr hwnd, ref DWM_BLURBEHIND blurBehind );
示例#3
0
		public static bool BlurBehindWindow (sw.Window window)
		{
			if (!DwmIsCompositionEnabled ())
				return false;

			var windowInteropHelper = new sw.Interop.WindowInteropHelper (window);
			IntPtr myHwnd = windowInteropHelper.Handle;
			var mainWindowSrc = System.Windows.Interop.HwndSource.FromHwnd (myHwnd);

			window.Background = swm.Brushes.Transparent;
			mainWindowSrc.CompositionTarget.BackgroundColor = swm.Colors.Transparent;

			var blurBehindParameters = new DWM_BLURBEHIND ();
			blurBehindParameters.dwFlags = DwmBlurBehindFlags.DWM_BB_ENABLE;
			blurBehindParameters.fEnable = true;
			blurBehindParameters.hRgnBlur = IntPtr.Zero;

			DwmEnableBlurBehindWindow (myHwnd, ref blurBehindParameters);
			int val = 1;
			DwmSetWindowAttribute (myHwnd, DwmWindowAttribute.DWMWA_TRANSITIONS_FORCEDISABLED, ref val, sizeof (int));
			return true;
		}
示例#4
0
        public static void EnableBlurBehindWindow(Border element, Window window)
        {
            if (noBlur) return;
            try
            {
                if (!DwmIsCompositionEnabled())
                    return;
                if (window.Opacity > 0)
                {
                    // Get the window handle
                    IntPtr hwnd = new WindowInteropHelper(window).Handle;
                    if (hwnd == IntPtr.Zero)
                        throw new InvalidOperationException("Window must be shown to blur");

                    window.Background = Brushes.Transparent;
                    HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
                    element.Background = new SolidColorBrush(Color.FromArgb(0x20, 0x35, 0x85, 0xe4));

                    if (_lastRegion != IntPtr.Zero)
                        DeleteObject(_lastRegion);

                    //var region = CreateRoundRectRgn((int)element.Margin.Left, (int)element.Margin.Top,
                    //    (int)(element.ActualWidth + element.Margin.Left), (int)(element.ActualHeight + element.Margin.Top),
                    //    (int)element.CornerRadius.TopLeft, (int)element.CornerRadius.TopLeft);
                    const int padding = 6;
                    //var region = CreateRectRgn(padding, padding, (int)element.ActualWidth + padding, (int)element.ActualHeight + padding);
                    var region = CreateRectRgn(padding, padding, (int)element.ActualWidth + padding, (int)element.ActualHeight + padding);

                    _lastRegion = region;

                    // Set Margins
                    DWM_BLURBEHIND blurBehind = new DWM_BLURBEHIND();
                    blurBehind.fEnable = true;
                    blurBehind.fTransitionOnMaximized = false;
                    blurBehind.hRgnBlur = region;
                    //blurBehind.dwFlags = DWM_BB.BlurRegion | DWM_BB.Enable | DWM_BB.TransitionMaximized;
                    blurBehind.dwFlags = DWM_BB.BlurRegion | DWM_BB.Enable;

                    DwmEnableBlurBehindWindow(hwnd, ref blurBehind);
                }
            }
            catch (DllNotFoundException)
            {
            }
        }
示例#5
0
 public static extern void DwmEnableBlurBehindWindow(
     IntPtr hWnd, DWM_BLURBEHIND pBlurBehind);
示例#6
0
        /// <summary>
        /// Applies glass to the current window
        /// </summary>
        private void ApplyGlass(IntPtr handle)
        {
            if (DwmApi.DwmIsCompositionEnabled())
            {
                this.Background = Brushes.Transparent;
                HwndSource mainWindowSrc = System.Windows.Interop.HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
                mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
                DWM_BLURBEHIND blurBehindParameters = new DWM_BLURBEHIND();
                blurBehindParameters.dwFlags = DwmBlurBehindFlags.DWM_BB_ENABLE;
                blurBehindParameters.fEnable = true;
                blurBehindParameters.hRgnBlur = IntPtr.Zero;

                IntPtr result = DwmEnableBlurBehindWindow(handle, ref blurBehindParameters);
            }
        }
示例#7
0
文件: DwmApi.cs 项目: kyzmitch/Cip
 public static extern int DwmEnableBlurBehindWindow(
     IntPtr hwnd,
     ref DWM_BLURBEHIND bb);
示例#8
0
 private static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind);
示例#9
0
 private static extern int DwmEnableBlurBehindWindow(
             System.IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);
示例#10
0
 private static extern IntPtr DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurFlags);
示例#11
0
 public static extern void DwmEnableBlurBehindWindow(IntPtr hWnd, DWM_BLURBEHIND pBlurBehind);
示例#12
0
 public static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);
 internal static extern int DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind);
示例#14
0
 private static extern int DwmEnableBlurBehindWindow(
     IntPtr hWnd,
     [In] ref DWM_BLURBEHIND pBlurBehind);
示例#15
0
 public static extern HRESULT DwmEnableBlurBehindWindow(IntPtr hWnd, [In] ref DWM_BLURBEHIND pBlurBehind);
示例#16
0
        public bool ForEachWindow(IntPtr hwnd, string op)
        {
            if (IsWindowVisible(hwnd))
            {
                switch (op)
                {
                case "title":
                    SendMessage(hwnd, WM_SETTEXT, 0, sentence);
                    break;

                case "picture":
                    Rectangle rect = new Rectangle();
                    GetClientRect(hwnd, ref rect);
                    Graphics g = Graphics.FromHwnd(hwnd);
                    Bitmap   p = new Bitmap(sentence);
                    try
                    {
                        g.DrawImage(p, rect);
                    }
                    catch
                    {
                    }
                    finally
                    {
                        g.Dispose();
                        p.Dispose();
                    }
                    break;

                case "close":
                    ShowWindow(hwnd, SW_FORCEMINIMIZE);
                    Thread.Sleep(10);
                    break;

                case "glass":
                    MARGINS m = new MARGINS()
                    {
                        cxLeftWidth    = -1,
                        cxRightWidth   = -1,
                        cyBottomHeight = -1,
                        cyTopHeight    = -1
                    };
                    DWM_BLURBEHIND b = new DWM_BLURBEHIND()
                    {
                        dwFlags  = 3,
                        fEnable  = true,
                        hRgnBlur = IntPtr.Zero
                    };
                    DwmEnableComposition(1);
                    uint attr = DWMNCRP_ENABLED;
                    DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, ref attr, Marshal.SizeOf(DWMNCRP_ENABLED));
                    DwmEnableBlurBehindWindow(hwnd, ref b);
                    DwmExtendFrameIntoClientArea(hwnd, ref m);
                    break;

                case "destroy":
                    if (hwnd != GetDesktopWindow())
                    {
                        SendMessage(hwnd, WM_CLOSE, 0, 0);
                        Thread.Sleep(10);
                    }
                    break;

                case "beuncle":
                    if (lhwnd.Contains(hwnd))
                    {
                        if (GetParent(hwnd) != GetDesktopWindow())
                        {
                            break;
                        }
                        else
                        {
                            lhwnd.Clear();
                        }
                    }
                    lhwnd.Add(hwnd);
                    SetParent(hwnd, IntPtr.Zero);
                    break;

                case "disable":
                    EnableWindow(hwnd, false);
                    break;

                case "text":
                    rect = new Rectangle();
                    GetClientRect(hwnd, ref rect);
                    g = Graphics.FromHwnd(hwnd);
                    int h  = rect.Height;
                    int fh = rect.Width / sentence.Length * 2;
                    int ph = 0;
                    try
                    {
                        Font f = new Font(FontFamily.GenericSansSerif, fh, FontStyle.Bold, GraphicsUnit.Pixel);
                        do
                        {
                            g.DrawString(sentence, f, Brushes.Black, 0, ph);
                            ph += fh;
                            h  -= fh;
                        } while (h > 0);
                    }
                    catch
                    {
                    }
                    finally
                    {
                        g.Dispose();
                    }
                    break;

                case "top":
                    ShowWindow(hwnd, SW_SHOWDEFAULT);
                    SetWindowPos(hwnd, new IntPtr(1), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
                    break;

                default:
                    throw new ArgumentException("该功能还未开发");
                }
                EnumChildWindows(hwnd, ForEachWindow, op);
            }
            return(true);
        }