Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Borderless window. How to add a shadow and remove 1px border?

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.

like image 885
nikitablack Avatar asked Oct 31 '22 04:10

nikitablack


1 Answers

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

like image 159
Eugene Mala Avatar answered Nov 11 '22 22:11

Eugene Mala