NB: THIS IS NOT A QUESTION ABOUT A BORDERLESS WINDOW.
So, I stumbled upon this program while I was exploring my Start menu the other day on Windows 7:
It's a native Windows program, called "Math Input Panel." Now, I'm curious about the window shape. I know that it's not completely drawn by DWM, because the borders and Close button look fishy and the window has no drop shadow (I have drop shadows enabled). My first guess as to how this was made would be using DwmEnableBlurBehindWindow
, but I can't imagine that works on irregular window shapes, does it? (Or is there another way to do this, or is it just completely Microsoft sorcery?)
This is simply two borderless windows attempting to emulate the DWM. This is evidenced with the inconsistencies in the theme with shadows and the "fishy" close button and the break in the gradient of the right "subwindow." A simple query of the DWM would have given the proper hints to render the windows correctly.
There is no "sorcery involved," since both of the windows are perfectly square. The main window has a shape associated with it, causing the insert button to appear while the rest of the bottom appears translucent. The same effect could be achieved using either GDI+ or WPF.
I am purposing a clarification of how the original effect was created, and not a way to duplicate it. That has been successfully demonstrated by previous answers.
So, unbeknownst to me,
hRgn
can take an irregular shape (andDwmEnableBlurBehindWindow
takes anhRgn
, but I knew that). So, here's my solution that's (more or less) compatible with WPF:...and source code:
MainWindow.xaml:
MainWindow.xaml.cs:
I think somebody else beat me to it, but here's how my solution works:
When the window's
SourceInitialized
event is fired, that means that we have a handle for our window. So in the handler of this function, I get the window handle. Then I make a call to a function I imported from dwmapi.dll calledDwmEnableBlurBehindWindow
. This basically turns transparent areas of the window into glass for a certain region. TheDwmBlurBehind
struct I got from pinvoke.net, and it converts a GDI+System.Drawing.Region
into anhRgn
. ThehRgn
is passed toDwmEnableBlurBehindWindow
, and it clips the transparent parts to theRegion
. In this case, I used a circle. Then the XAML is just the accent borders. It's worth noting that, for some reason, settingWindow.Background
toTransparent
doesn't enable hit-testing whenAllowsTransparency
is true here. No idea why, but it probably has something to do with the code-behind.Here's a quickly hacked together WPF solution. It uses the
hRgnBlur
of theDWM_BLURBEHIND
structure, and some interop.This example will apply an ellipse-shaped background blur on the window.
You can easily convert this to an attached property or behavior for MVVM-friendliness. It's also a good idea to listen to the
WM_DWMCOMPOSITIONCHANGED
message and reapply the blur if needed.Used with the following XAML:
The result is: