在MFC对话框中绘制对话框边距

温兹

我希望对话框是无边界的,但要有对话框阴影。我遇到了一个使用Areo Snap,Shadow,Minimize Animation和Shake的无边界窗口解决方案,该解决方案通过使Dialog的边距为1 px并将客户区扩展到它来使用一种解决方法。

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

空白对话框无边框但带有对话框阴影

帖子提到客户区在字面上被扩展了,透明图形使每个1px的D​​ialog边缘再次可见。

当我尝试在整个对话框上绘制实体矩形时,这正是发生的情况:

// 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);

但是对话框仍然以其边距绘制: 边框各为1px的空白对话框

怎么可能在边缘上画一些东西呢?稍后,我将使用图片作为对话框背景,该背景也应绘制在边距上。

温兹

感谢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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章