Neroli
ガラスウィンドウ
最終更新:
kitay
-
view
2011/04/07 00:18 Thu
ガラスウィンドウ
- [StructLayout(LayoutKind.Sequential)]
- public struct MARGINS
- {
- /// <summary>
- ///
- /// </summary>
- public int cxLeftWidth; // width of left border that retains its size
- /// <summary>
- ///
- /// </summary>
- public int cxRightWidth; // width of right border that retains its size
- /// <summary>
- ///
- /// </summary>
- public int cyTopHeight; // height of top border that retains its size
- /// <summary>
- ///
- /// </summary>
- public int cyBottomHeight; // height of bottom border that retains its size
- };
-
- [DllImport("DwmApi.dll")]
- public static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref MARGINS pMarInset);
-
- /// <summary>
- /// ガラスウィンドウ
- /// </summary>
- /// <param name="window"></param>
- static public void SetGlassWindowStyle( Window window )
- {
- try
- {
- // Obtain the window handle for WPF application
- IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle;
- HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
- mainWindowSrc.CompositionTarget.BackgroundColor = 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
- WindowUtility.MARGINS margins = new WindowUtility.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(15 * (DesktopDpiX / 96));
- margins.cxRightWidth = Convert.ToInt32(35 * (DesktopDpiX / 96));
- margins.cyTopHeight = Convert.ToInt32(((int)50 + 5) * (DesktopDpiX / 96));
- margins.cyBottomHeight = Convert.ToInt32(5 * (DesktopDpiX / 96));
- */
- margins.cxLeftWidth = -1;
- margins.cxRightWidth = -1;
- margins.cyTopHeight = -1;
- margins.cyBottomHeight = -1;
-
-
- int hr = WindowUtility.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
- //
- if (hr < 0)
- {
- //DwmExtendFrameIntoClientArea Failed
- }
- }
- // If not Vista, paint background white.
- catch (DllNotFoundException)
- {
- System.Windows.Application.Current.MainWindow.Background = Brushes.White;
- }
- }
-