Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Anybody using DwmExtendFrameIntoClientArea?

Anybody using DwmExtendFrameIntoClientArea?

Scheduled Pinned Locked Moved WPF
graphicscsharptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SledgeHammer01
    wrote on last edited by
    #1

    Just using the stock example from Microsoft:

    	void MainWindow\_Loaded(object sender, RoutedEventArgs e)
    	{
    		IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle;
    		HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
    
    		//mainWindowSrc.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;          //  <=== UNCOMMENT THIS LINE
    
    		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
    		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(5 \* (DesktopDpiX / 96));
    		margins.cxRightWidth = Convert.ToInt32(5 \* (DesktopDpiX / 96));
    		margins.cyTopHeight = Convert.ToInt32(((int)90) \* (DesktopDpiX / 96));
    		margins.cyBottomHeight = Convert.ToInt32(5 \* (DesktopDpiX / 96));
    
    		int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
    		// 
    		if (hr < 0)
    		{
    			//DwmExtendFrameIntoClientArea Failed
    		}
    	}
    

    On my machine, I get a white rectangle over the entire window for about 1 second and then the window redraws properly. This code works on .NET 4.5.1, but this seems to have cropped up in .NET 4.5.2.

    Richard DeemingR 1 Reply Last reply
    0
    • S SledgeHammer01

      Just using the stock example from Microsoft:

      	void MainWindow\_Loaded(object sender, RoutedEventArgs e)
      	{
      		IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle;
      		HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
      
      		//mainWindowSrc.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;          //  <=== UNCOMMENT THIS LINE
      
      		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
      		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(5 \* (DesktopDpiX / 96));
      		margins.cxRightWidth = Convert.ToInt32(5 \* (DesktopDpiX / 96));
      		margins.cyTopHeight = Convert.ToInt32(((int)90) \* (DesktopDpiX / 96));
      		margins.cyBottomHeight = Convert.ToInt32(5 \* (DesktopDpiX / 96));
      
      		int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
      		// 
      		if (hr < 0)
      		{
      			//DwmExtendFrameIntoClientArea Failed
      		}
      	}
      

      On my machine, I get a white rectangle over the entire window for about 1 second and then the window redraws properly. This code works on .NET 4.5.1, but this seems to have cropped up in .NET 4.5.2.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Try calling the code from the window's SourceInitialized event[^], which should fire earlier than the Loaded event. You might also need to call DwmEnableBlurBehindWindow to reset the blur effect for the window. Here's the code I use: https://gist.github.com/RichardD2/ef4ee339ce3dcc10264b[^] That lets you enable the glass effect and set up the thickness using two attached properties. There's an additional real-only attached property which indicates whether the glass effect has been applied, which you can use to adapt your styles where necessary.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Try calling the code from the window's SourceInitialized event[^], which should fire earlier than the Loaded event. You might also need to call DwmEnableBlurBehindWindow to reset the blur effect for the window. Here's the code I use: https://gist.github.com/RichardD2/ef4ee339ce3dcc10264b[^] That lets you enable the glass effect and set up the thickness using two attached properties. There's an additional real-only attached property which indicates whether the glass effect has been applied, which you can use to adapt your styles where necessary.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        S Offline
        S Offline
        SledgeHammer01
        wrote on last edited by
        #3

        Tried moving it to SourceInitialized and get the same result. 4.5.1 works perfectly and 4.5.2 has the 1 - 2 second start up lag. This isn't even a question of framework targeting, just if you have > 4.5.1 installed on the machine, it happens.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups