【问题标题】:Draw over Dialog Margins in an MFC Dialog在 MFC 对话框中绘制对话框边距
【发布时间】: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


【解决方案1】:

感谢 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    相关资源
    最近更新 更多