アットウィキロゴ
Neroli
掲示板 掲示板 ページ検索 ページ検索 メニュー メニュー

Neroli

ガラスウィンドウ

最終更新:

kitay

- view
管理者のみ編集可
2011/04/07 00:18 Thu

ガラスウィンドウ

  1. [StructLayout(LayoutKind.Sequential)]
  2. public struct MARGINS
  3. {
  4. /// <summary>
  5. ///
  6. /// </summary>
  7. public int cxLeftWidth; // width of left border that retains its size
  8. /// <summary>
  9. ///
  10. /// </summary>
  11. public int cxRightWidth; // width of right border that retains its size
  12. /// <summary>
  13. ///
  14. /// </summary>
  15. public int cyTopHeight; // height of top border that retains its size
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. public int cyBottomHeight; // height of bottom border that retains its size
  20. };
  21.  
  22. [DllImport("DwmApi.dll")]
  23. public static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref MARGINS pMarInset);
  24.  
  25. /// <summary>
  26. /// ガラスウィンドウ
  27. /// </summary>
  28. /// <param name="window"></param>
  29. static public void SetGlassWindowStyle( Window window )
  30. {
  31. try
  32. {
  33. // Obtain the window handle for WPF application
  34. IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle;
  35. HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
  36. mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
  37.  
  38. // Get System Dpi
  39. System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr);
  40. float DesktopDpiX = desktop.DpiX;
  41. float DesktopDpiY = desktop.DpiY;
  42.  
  43. // Set Margins
  44. WindowUtility.MARGINS margins = new WindowUtility.MARGINS();
  45.  
  46. // Extend glass frame into client area
  47. // Note that the default desktop Dpi is 96dpi. The margins are
  48. // adjusted for the system Dpi.
  49. /*
  50. margins.cxLeftWidth = Convert.ToInt32(15 * (DesktopDpiX / 96));
  51. margins.cxRightWidth = Convert.ToInt32(35 * (DesktopDpiX / 96));
  52. margins.cyTopHeight = Convert.ToInt32(((int)50 + 5) * (DesktopDpiX / 96));
  53. margins.cyBottomHeight = Convert.ToInt32(5 * (DesktopDpiX / 96));
  54. */
  55. margins.cxLeftWidth = -1;
  56. margins.cxRightWidth = -1;
  57. margins.cyTopHeight = -1;
  58. margins.cyBottomHeight = -1;
  59.  
  60.  
  61. int hr = WindowUtility.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
  62. //
  63. if (hr < 0)
  64. {
  65. //DwmExtendFrameIntoClientArea Failed
  66. }
  67. }
  68. // If not Vista, paint background white.
  69. catch (DllNotFoundException)
  70. {
  71. System.Windows.Application.Current.MainWindow.Background = Brushes.White;
  72. }
  73. }
  74.  


記事メニュー
最近更新されたスレッド
ウィキ募集バナー