【发布时间】:2014-10-03 11:16:55
【问题描述】:
我希望对话框无边框但有对话框阴影。我遇到了这个解决方案Borderless Window Using Areo Snap, Shadow, Minimize Animation, and Shake,它使用了一种解决方法,使对话框的边距为 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);
但对话框仍以边距绘制:
如何在边缘绘制一些拉伸的东西?稍后我将使用图片作为对话框背景,该背景也应绘制在边缘。
【问题讨论】:
-
您不能使用传统的 24bpp GDI 函数在玻璃区域中绘制,输出将保持透明。你需要32bpp的渲染,alpha通道必须包含在内,GDI+可以做到。
标签: c++ mfc dialog border shadow