Introduction
In my opinion the worst things in programming are really useful interface making. Therefore the using of existing
solutions is preferable. But sometimes we need to realize our own one because found solutions can't achieve
desirable results. I hope that this application allows people to simplify his or
her life and work.
Background
In my work I have needed to use banner control. In Code Project I quickly found solutions of
PaulWendt and
Peter Mares
and decided
to combine their solutions.
Using the code
This application demonstrates banner control with docked possibility and font orientation according
to docked position. By form controls we may to change scrolling speed and manipulate banner database with
text attributes changing and banner positioning.
I have made orientation addition in class CMultiColorStatic
int CMultiColorStatic::GetOrientation()
{ return m_iOrientation;}
void CMultiColorStatic::SetOrientation(int iOrientation)
{ m_iOrientation = iOrientation; Invalidate(); }
Also I have added consequent insertions in Paint function in CBannerStatic
class.
void CBannerStatic::OnPaint()
{
CPaintDC dc(this);
CRect rcBounds = m_rcBounds;
if(GetOrientation()==ORIENTATION_HORIZONTAL)
rcBounds.left = m_nTextOut;
if(GetOrientation()==ORIENTATION_VERTICAL_LEFT)
rcBounds.bottom = m_rcBounds.Height()-m_nTextOut;
if(GetOrientation()==ORIENTATION_VERTICAL_RIGHT)
rcBounds.top = m_nTextOut;
dc.FillRect(m_rcBounds, &m_brBackGround);
dc.IntersectClipRect(m_rcBounds);
m_nTextLength = 0;
for (int i = 0; i < m_astrData.GetSize(); i++)
{
CColorString* pstrCurrent =
reinterpret_cast<CColorString*>(m_astrData.GetAt(i));
TEXTMETRIC stFontMetrics;
SIZE stSize;
DetermineFont(pstrCurrent);
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);
if(GetOrientation()==ORIENTATION_VERTICAL_LEFT)
{
dc.MoveTo(rcBounds.left, rcBounds.Height());
dc.SetTextAlign( TA_UPDATECP);
}
if(GetOrientation()==ORIENTATION_VERTICAL_RIGHT)
{
dc.MoveTo(rcBounds.Width(),rcBounds.top);
dc.SetTextAlign( TA_UPDATECP);
}
dc.DrawText(*pstrCurrent, rcBounds, DT_LEFT);
if(GetOrientation()==ORIENTATION_HORIZONTAL)
rcBounds.left += stSize.cx + stFontMetrics.tmOverhang;
if(GetOrientation()==ORIENTATION_VERTICAL_LEFT)
rcBounds.bottom -= stSize.cx + stFontMetrics.tmOverhang;
if(GetOrientation()==ORIENTATION_VERTICAL_RIGHT)
rcBounds.top += stSize.cx + stFontMetrics.tmOverhang;
m_nTextLength += stSize.cx + stFontMetrics.tmOverhang;
}
}
Points of Interest
I don't understand why system font has not changed according to given orientation.
I had no time to clear this situation and I had used other fonts.
void CMultiColorStatic::DetermineFont(const CColorString* const pstrData)
{
LOGFONT stFont;
m_ftText.DeleteObject();
CFont font;
font.CreatePointFont(110, _T("Tahoma Bold"));
font.GetLogFont(&stFont);
font.DeleteObject();
stFont.lfWidth = ((stFont.lfHeight * 12) / 16);
stFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
if (m_fAutoSize)
{
if(GetOrientation()==ORIENTATION_HORIZONTAL) stFont.lfHeight =
m_rcBounds.Height();
if(GetOrientation()==ORIENTATION_VERTICAL_LEFT) stFont.lfHeight =
m_rcBounds.Width();
if(GetOrientation()==ORIENTATION_VERTICAL_RIGHT) stFont.lfHeight =
m_rcBounds.Width();
}
if(GetOrientation()==ORIENTATION_HORIZONTAL)
stFont.lfEscapement = stFont.lfOrientation = 0;
if(GetOrientation()==ORIENTATION_VERTICAL_LEFT)
stFont.lfEscapement = stFont.lfOrientation = 900;
if(GetOrientation()==ORIENTATION_VERTICAL_RIGHT)
stFont.lfEscapement = stFont.lfOrientation = -900;
stFont.lfWeight = (pstrData->GetBold() ? FW_HEAVY : FW_NORMAL);
stFont.lfUnderline = pstrData->GetUnderlined();
stFont.lfItalic = pstrData->GetItalic();
stFont.lfQuality = PROOF_QUALITY;
m_ftText.CreateFontIndirect(&stFont);
}
History
I think it is the first contribution to CodeProject on my banner theme.