日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁(yè)編程開(kāi)發(fā)其它知識(shí) → WPF 中編寫(xiě)具有玻璃效果主題的程序技巧(Aero Glass)

      WPF 中編寫(xiě)具有玻璃效果主題的程序技巧(Aero Glass)

      相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來(lái)源:西西整理時(shí)間:2011/4/24 7:50:02字體大。A-A+

      作者:西西點(diǎn)擊:427次評(píng)論:0次標(biāo)簽: Aero

      3D快速啟動(dòng)Aero QLaunch1.2.22英文官方安裝版
      • 類型:系統(tǒng)其它大小:1.2M語(yǔ)言:英文 評(píng)分:5.0
      • 標(biāo)簽:
      立即下載

      Windows 7 操作系統(tǒng)默認(rèn)具有一款玻璃效果主題(Aero Glass)。如果選擇了該款主題,所有的應(yīng)用程序標(biāo)題欄都會(huì)處于玻璃透明效果(如下圖)。這個(gè)功能是由Desktop Window Manager(DWM)服務(wù)支持的。

        默認(rèn)情況下,我們編寫(xiě)的應(yīng)用程序在Windows 7 中也只有標(biāo)題欄和窗口框架會(huì)具備玻璃效果,其他區(qū)域仍是不透明狀態(tài)(如下圖)。如果想將程序整體都改為上圖IE 窗口的效果,可以使用DWM API 將玻璃區(qū)域進(jìn)行擴(kuò)展。

      首先,從dwmapi.dll 中調(diào)取DwmExtendFrameIntoClientArea 方法。

      [StructLayout(LayoutKind.Sequential)]
      public struct MARGINS
      {
      public int cxLeftWidth;
      public int cxRightWidth;
      public int cyTopHeight;
      public int cyBottomHeight;
      };

      [DllImport("DwmApi.dll")]
      public static extern int DwmExtendFrameIntoClientArea(
      IntPtr hwnd,
      ref MARGINS pMarInset);

        創(chuàng)建方法ExtendAeroGlass 方法,可將WPF Window窗口的Aero Glass 區(qū)域擴(kuò)展。

      private void ExtendAeroGlass(Window window)
      {
      try
      {
      // 為WPF程序獲取窗口句柄
      IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle;
      HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
      mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;

      // 設(shè)置Margins
      MARGINS margins = new MARGINS();

      // 擴(kuò)展Aero Glass
      margins.cxLeftWidth = -1;
      margins.cxRightWidth = -1;
      margins.cyTopHeight = -1;
      margins.cyBottomHeight = -1;

      int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
      if (hr < 0)
      {
      MessageBox.Show("DwmExtendFrameIntoClientArea Failed");
      }
      }
      catch (DllNotFoundException)
      {
      Application.Current.MainWindow.Background = Brushes.White;
      }
      }

        簡(jiǎn)單制作一個(gè)WPF 界面。

      <Window x:Class="WpfAeroGlass.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525">
      <Grid x:Name="layout">
      <Button x:Name="btn" Content="Button" Margin="191,66,202,211" />
      <CheckBox x:Name="checkBox" Content="Extend AeroGlass"
      Click="CheckBox_Checked" Height="24" Width="121" />
      </Grid>
      </Window>

        補(bǔ)充CheckBox 點(diǎn)擊事件,在其中啟用ExtendAeroGlass 方法。

      private void CheckBox_Checked(object sender, RoutedEventArgs e)
      {
      if (checkBox.IsChecked.Value)
      {
      this.Background = Brushes.Transparent;
      ExtendAeroGlass(this);
      }
      else
      {
      this.Background = Brushes.White;
      }
      }

      演示效果

        運(yùn)行程序后,默認(rèn)界面狀態(tài)。

        點(diǎn)擊"Extend AeroGlass" 選框,界面中<Grid> 也將呈現(xiàn)玻璃效果。

        Windows API

        通過(guò)Windows API Code Pack 可以對(duì)Aero Glass 效果進(jìn)行開(kāi)啟或關(guān)閉。在程序中加入Microsoft.WindowsAPICodePack.Shell 命名空間,調(diào)整AeroGlassCompositioinEnabled 完成開(kāi)/關(guān)Aero Glass的效果。

      GlassWindow.AeroGlassCompositionEnabled = checkBox.IsChecked.Value;

        相關(guān)評(píng)論

        閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過(guò)難過(guò)
        • 5 囧
        • 3 圍觀圍觀
        • 2 無(wú)聊無(wú)聊

        熱門評(píng)論

        最新評(píng)論

        發(fā)表評(píng)論 查看所有評(píng)論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過(guò)審核才能顯示)