0
votes

I want a dialog to be borderless and yet have a dialog shadow. I came across this solution Borderless Window Using Areo Snap, Shadow, Minimize Animation, and Shake which uses a workaround by making the Dialog having a Margin of 1 px and extending the Client Area to it.

MARGINS borderless = { 1, 1, 1, 1 };
DwmExtendFrameInfoClientArea(this->GetSafeHwnd(), &borderless);

Blank Dialog without a Border but with a Dialog Shadow

The post mentioned that the Client Area is literally being extended and Transparent drawing makes the Dialog edges of 1px each visible again.

Now this is exactly what happened, when I tried to paint a Solid Rectangle onto the whole dialog:

// getting the client area
CRect clientRect;
GetClientRect(&clientRect);

// expanding it to the new margins
clientRect.left -= 1;
clientRect.top -= 1;
clientRect.right += 2;
clientRect.bottom += 2;

// set the Device Context to draw non transparent and with a black background
pDC->SetBkMode(OPAQUE);
pDC->SetBkColor(RGB(0, 0, 0));

// finally draw a rectangle to it
CBrush brush_back_ground(RGB(0, 0, 0));
pDC->FillRect(clientRect, &brush_back_ground);

But the dialog is still drawn with its margins: Blank Dialog with a Border of 1px each

How would it be possible to draw something stretched on the margins? Later I'm going to use pictures as dialog Background which should be drawn on the margins aswell.

1
You cannot use the legacy 24bpp GDI functions to draw in the glass area, output will remain transparent. You need 32bpp rendering, the alpha channel must be included, GDI+ can do this.Hans Passant

1 Answers

0
votes

Thanks to Hans Passant for his comment. The solution is to use GDI+ drawing instead of GDI drawing

// making a Gdi+ graphics object from my CDC*
Graphics g(*pDC);

// getting the client area
CRect clientRect;
GetClientRect(&clientRect);

// making a Gdi+ rect
Rect bkRect(0,0,clientRect.Width(), clientRect.Height());

// making a pen for the Rect Drawing
Pen bkPen(Color(255,0,0,0));

// draw the rectangle over the full dialog
g.DrawRectangle(&bkPen, bkRect);

enter image description here