简体   繁体   English

如何绘制圆角矩形而不填充它(在MFC中)?

[英]How do I draw a rounded rectangle without filling it (in MFC)?

Another drawing question for you MFC/GDI gurus out there... :-) 另外一个绘图问题MFC / GDI大师那里...... :-)

I'm using MFC, and I'm doing some drawing with a CDC object. 我正在使用MFC,我正在使用CDC对象进行绘图。 That works fine. 这很好。

But now I want to draw a rectangle with rounded corners, the line being a couple of pixels wide. 但是现在我想绘制一个带圆角的矩形,这条线宽几个像素。 But I dont want any filling to occur! 但我不希望任何填充发生! There is a method CDC::RoundRect - I just set the pen I want and get a beautiful rounded rectangle with that pen. 有一种方法CDC :: RoundRect - 我只是设置了我想要的笔,并用这支笔得到一个漂亮的圆角矩形。 But CDC::RoundRect also fills the rectangle with the current brush. 但CDC :: RoundRect也用当前画笔填充矩形。

Is there any way to draw just the line, with no filling? 有没有办法画线,没有填充? Any other method I haven't found? 我还没找到任何其他方法? Or can I create some sort of "null brush" that doesn't alter what's in the middle of the rectangle? 或者我可以创建某种“空刷”,它不会改变矩形中间的内容吗?

I'd be very grateful for some good advice! 我非常感谢你的一些好建议!

/Anders from Sweden /来自瑞典的安德斯

Just select a NULL brush before drawing the rounded rectangle, like 只需在绘制圆角矩形之前选择NULL画笔,例如

CPen pen;
CBrush* pOldBrush;
CPen* pOldPen;
if (!pen.CreatePenIndirect(&m_logpen))
    return;
pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
pOldPen = pDC->SelectObject(&pen);
pDC->RoundRect(m_rect, m_roundness);
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM