我希望对话框是无边界的,但要有对话框阴影。我遇到了一个使用Areo Snap,Shadow,Minimize Animation和Shake的无边界窗口解决方案,该解决方案通过使Dialog的边距为1 px并将客户区扩展到它来使用一种解决方法。
MARGINS borderless = { 1, 1, 1, 1 };
DwmExtendFrameInfoClientArea(this->GetSafeHwnd(), &borderless);
帖子提到客户区在字面上被扩展了,透明图形使每个1px的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);
但是对话框仍然以其边距绘制:
怎么可能在边缘上画一些东西呢?稍后,我将使用图片作为对话框背景,该背景也应绘制在边距上。
感谢Hans Passant的评论。解决方案是使用GDI +绘图而不是GDI绘图
// 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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句