CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Jan 2012
    Posts
    1

    Exclamation Resizing WPF window with Aero glass

    I have created a borderless window with glass in the client area, upon loading, everything is fine, upon maximizing or enlarging, everything is still fine, upon restoring or making the window smaller, the window sizes fine but the Aero blurred background remains at the larger size.

    The attached images are my window with my own border and title-bar.

    You'll notice in the second image when I resize the window by clicking on the button you'll notice that the blurred background and window resizes but also leaves the top right blurred outside the window.

    Any help would be greatly appreciated!!!
    Here is the code behind:


    //*********************************************************
    namespace WpfApplication3
    {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
    public MainWindow()
    {
    InitializeComponent();
    }


    [Flags]
    private enum DwmBlurBehindFlags : uint
    {
    /// <summary>
    /// Indicates a value for fEnable has been specified.
    /// </summary>
    DWM_BB_ENABLE = 0x00000001,

    /// <summary>
    /// Indicates a value for hRgnBlur has been specified.
    /// </summary>
    DWM_BB_BLURREGION = 0x00000002,

    /// <summary>
    /// Indicates a value for fTransitionOnMaximized has been specified.
    /// </summary>
    DWM_BB_TRANSITIONONMAXIMIZED = 0x00000004
    }

    [StructLayout(LayoutKind.Sequential)]
    private struct DWM_BLURBEHIND
    {
    public DwmBlurBehindFlags dwFlags;
    public bool fEnable;
    public IntPtr hRgnBlur;
    public bool fTransitionOnMaximized;
    }

    [DllImport("dwmapi.dll")]
    private static extern IntPtr DwmEnableBlurBehindWindow(IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
    WindowInteropHelper windowInteropHelper = new WindowInteropHelper(this);
    IntPtr myHwnd = windowInteropHelper.Handle;
    HwndSource mainWindowSrc = System.Windows.Interop.HwndSource.FromHwnd(myHwnd);

    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;

    DwmEnableBlurBehindWindow(myHwnd, ref blurBehindParameters);
    }

    // called whenever window dragged
    protected virtual void OnWindowDragMove(object sender, MouseEventArgs e)
    {
    if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
    this.DragMove();
    }

    private void button2_Click(object sender, RoutedEventArgs e)
    {
    this.Width = 0;
    this.Height = 0;
    MessageBox.Show("has been made tiny");
    this.Width = 650;
    this.Height = 500;
    }
    }
    }
    Attached Images Attached Images   

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured