Static自绘控件导致控件上的其他控件不可见了
我用CStatic魏基类,参照网上的办法做了一个可以滚动显示字幕的自绘控件。控件效果是实现了,但是一直存在一个问题,就是控件放上去后,我想放个其他控件在其上,比如按钮,或者其他文本控件。但现在的问题来了,控件放上去后,总是被自绘控件所覆盖挡住了,无论如何改变Z order也没有用。
CStatic自绘控件实现了OnPaint事件,实现如下
void CBannerStatic::OnPaint()
{
CPaintDC dc(this);
CRect rcBounds = m_rcBounds;
rcBounds.left = m_nTextOut;
//------------------------------------------------------
// do the background and make sure that we don't
// paint outside of our client area
//
dc.FillRect(m_rcBounds, &m_brBackGround);
dc.IntersectClipRect(m_rcBounds);
m_nTextLength = 0;
m_vnStrings.clear();
//------------------------------------------------------
// draw each string with its own font
//
for (int i = 0; i < m_astrData.GetSize(); i++)
{
CColorString* pstrCurrent = reinterpret_cast<CColorString*>(m_astrData.GetAt(i));
TEXTMETRIC stFontMetrics;
SIZE stSize;
DetermineFont(pstrCurrent);
//---------------------------------------------------
// set up the drawing attributes
//
dc.SelectObject(&m_ftText)->DeleteObject();
if (pstrCurrent->GetBackColor() == ::GetSysColor(COLOR_BTNFACE))
{
dc.SetBkColor(m_crBackColor);
}
else
{
dc.SetBkColor(pstrCurrent->GetBackColor());
}
dc.SetTextColor(pstrCurrent->GetColor());
dc.GetOutputTextMetrics(&stFontMetrics);
GetTextExtentPoint32(dc.GetSafeHdc(), *pstrCurrent, pstrCurrent->GetLength(), &stSize);
//---------------------------------------------------
// do the drawing and update the position-dependent
// stuff
//
dc.DrawText(*pstrCurrent, rcBounds, DT_LEFT);
rcBounds.left += stSize.cx + stFontMetrics.tmOverhang;
m_vnStrings.push_back(m_nTextOut + m_nTextLength);
m_nTextLength += stSize.cx + stFontMetrics.tmOverhang;
}
}