Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How I can blur everything that is behind window or for example behind grid? The purpose is not to blur the part of the window, but everything that is behind the window on windows xp and higher. I heard about dwmapi, but this is not working on windows xp. How i can do this?
Posted
Comments
Mehdi Gholam 2-Nov-14 15:01pm    
WPF requires some serious graphics to be good, and if you are targeting Windows XP then that would not be the case.
Sergey Alexandrovich Kryukov 2-Nov-14 19:37pm    
Actually, WPF, being based on DirectX, is faster then GDI+ (used in Windows.Forms), so this aspect is not a problem.
The problem is different: OP would need to put many things together.
Nevertheless, this is quite doable. Please see my answer.
—SA
Philippe Mori 2-Nov-14 19:52pm    
As XP is dead, I think a good compromise would be that this feature would only be available on Windows Vista and higher.

By the way, all those effects are not used anymore on Windows 8 and latter. Only the taskbart is partially transparent.

1 solution

This is not going to be easy. You are going to modify the look not of your window, but the whole desktop with the application window which has nothing to do with your application and, hence, nothing to do with WPF.

Nevertheless, there is a work around. You have to copy the whole desktop image and then create your own WPF window which covers all the background and mimic it. This background window should be a separate top-level window with the property WindowStyle set to System.Windows.WindowStyle.None:
http://msdn.microsoft.com/en-us/library/system.windows.window.windowstyle%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.windowstyle%28v=vs.110%29.aspx[^].

It will allow you creating a window without any non-client area, to cover all the current desktop to mimic the desktop appearance. In this window, you need to draw the graphic copied from the "real" desktop, blurred or the way you want.

There are many ways to capture the screen. You can search a solution on the Web.
You can also look at the source code of this open-source project: http://sourceforge.net/projects/screencapturewp[^].

To create some blur effect (there are way to many different kinds of blur, including very realistic but hard to calculate boke), you can use convolution matrix:
http://en.wikipedia.org/wiki/Kernel_%28image_processing%29[^].

The article reference above shows three sample kernels for blur. You can create something else. This kind of transformation can be done in WPF or System.Drawing.Bitmap (which you can obtain from screen copy and will need to transform to a WPF bitmap). You can access bits of any of those bitmaps by yourself and perform the convolution. Only don't use prohibitively slow GetPixel/SetPixel, instead use LockBits (System.Drawing) or, with WPF, the class WriteableBitmap:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28v=vs.110%29.aspx[^].

If it seems to difficult for you, you can use, for example, open-sourse AForge.NET library, its Convolution class, Blur class, in particular, GaussianBlur:
http://www.aforgenet.com/framework/docs/html/3b7d8422-2d79-8019-8933-a0472040c124.htm[^],
http://www.aforgenet.com/framework/docs/html/be5cfa72-caa1-205b-d282-9abe2fc1c19b.htm[^],
http://www.aforgenet.com/framework/docs/html/f074e0dd-865c-fd5f-ba0a-80e336a0eaea.htm[^].

You can also use any matrix of your choice.

On top of this "fake background", you can put the WPF content you need. There are many small things to solve. For example, when you click in the "fake background" window, you need to "get back to normal". You need to remove this window and activate the "real" window behind it. And so on…

Sorry that my solution is a bit schematic. It really takes good deal of knowledge to figure out all the pieces you need. If you don't feel scared by the volume of this work, you can try to start and ask further questions as you go.

—SA
 
Share this answer
 
v2
Comments
Mehdi Gholam 3-Nov-14 1:25am    
5'ed
Sergey Alexandrovich Kryukov 3-Nov-14 10:07am    
Thank you, Mehdi.
—SA
Maciej Los 3-Nov-14 3:00am    
+++5!
Sergey Alexandrovich Kryukov 3-Nov-14 10:08am    
Thank you, Maciej.
—SA
Arlert 3-Nov-14 13:54pm    
i guess this is the best solution for xp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900