5
votes

I need to create a borderless window with specified background color. I know how to remove a non client area and get something like this:

enter image description here

It's cool but not truly what I want. If you take a closer look at any aero window - there's a shadow around it (actually this is not a shadow but some glow). I found somewhere that I can use this code to add a shadow:

const MARGINS shadow_on = { 1, 1, 1, 1 };
DwmExtendFrameIntoClientArea(hwnd, &shadow_on);

It's almost do it's job (thought this is absolutely not clear to me - documentation says nothing about relationship of shadow and this function). Almost. There's a thin border appeared around the window. It looks like it's semitransparent and it breaks the look and feel of the window:

enter image description here

I know that it's possible - the visual studio even change the color of this border somehow!

Update: as IInspectable noticed in comments I can use negative margins in DwmExtendFrameIntoClientArea(). I set -1 value and got this result:

enter image description here

As you can see - it's even weirder. I tried to fill a background with color, but without luck.

1
You can clip the window area to remove the glow. Did You try to clip it already in order to remove the glow ? It might be, that You cannot get rid of the glow and use shadow at the same time.icbytes
@icbytes no, you didn't understand - I need a glow - I don't need a border which appears when I'm adding a glow.nikitablack
DwmExtendFrameIntoClientArea: "Use negative margin values to create the "sheet of glass" effect where the client area is rendered as a solid surface with no window border."IInspectable
Why not use CS_DROPSHADOW in class style?Barmak Shemirani
All right then. Glad to see you've found how to do it; good luck from here on out!andlabs

1 Answers

2
votes

To remove one pixel border after calling this function:

const MARGINS shadow_on = { 1, 1, 1, 1 };
DwmExtendFrameIntoClientArea(hwnd, &shadow_on);

You need to override WndProc WM_NCCALCSIZE message, and return 0 as the result. Also you need to create window using WS_CAPTION style. (On Windows XP this code won't produce rectangular window, but there is no shadow on WinXP, so on Windows XP you should fallback to WS_POPUP window style)
By the way, to add shadow it is enough to use this margins:
const MARGINS shadow_on = { 1, 0, 0, 0 };

Here is clean windows API code example how to create such window, it is written on Delphi: https://stackoverflow.com/a/44489430/877099