/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainWindow_Loaded(object sender, RoutedEventArgs e) { var c_毛玻璃 = new C_window_AERO(); c_毛玻璃.func_啟用毛玻璃(this); new C_全域按鍵偵測(this); //取得解析度偏差 PresentationSource source = PresentationSource.FromVisual(this); d_解析度比例_x = source.CompositionTarget.TransformToDevice.M11; d_解析度比例_y = source.CompositionTarget.TransformToDevice.M22; }
/// <summary> /// /// </summary> /// <param name="M"></param> /// <returns></returns> public bool func_啟用毛玻璃(Window M) { //win10 啟用毛玻璃特效 if (IsWindows10()) { try { var c_毛玻璃_win10 = new C_window_AERO(); c_毛玻璃_win10.EnableBlur(M); } catch { return(false); } return(true); }//win10 //win7 啟用毛玻璃特效 if (IsWindows7()) { try { //取得最高的螢幕 int h = 0; foreach (var screen in System.Windows.Forms.Screen.AllScreens) //列出所有螢幕資訊 { int xx = screen.Bounds.Y + screen.Bounds.Height; if (xx > h) { h = xx; } } h += 50; // Obtain the window handle for WPF application IntPtr mainWindowPtr = new WindowInteropHelper(M).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = System.Windows.Media.Color.FromArgb(0, 0, 0, 0); // Get System Dpi System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr); float DesktopDpiX = desktop.DpiX; float DesktopDpiY = desktop.DpiY; // Set Margins MARGINS margins = new MARGINS(); // Extend glass frame into client area // Note that the default desktop Dpi is 96dpi. The margins are // adjusted for the system Dpi. margins.cxLeftWidth = Convert.ToInt32(0 * (DesktopDpiX / 96)); margins.cxRightWidth = Convert.ToInt32(0 * (DesktopDpiX / 96)); margins.cyTopHeight = Convert.ToInt32(((int)h) * (DesktopDpiX / 96)); margins.cyBottomHeight = Convert.ToInt32(0 * (DesktopDpiX / 96)); int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); // if (hr < 0) { //DwmExtendFrameIntoClientArea Failed } M.BorderThickness = new Thickness(10, 0, 10, h); } catch { // If not Vista, paint background white. //Application.Current.MainWindow.Background = Brushes.White; return(false); } return(true); }//win7 //win8 return(false); }