CListBox with Font and Color can be moved(MoveWindow) as you will.
Code:
pAAList.Create(...|LBS_OWNERDRAWVARIABLE|LBS_HASSTRINGS...);
//Or,it adjusts its size automaticly when moved(MoveWindow) or font-changed.
//It needs an empty MeasureItem
void CAAList::MeasureItem(LPMEASUREITEMSTRUCT)
{
}
void CAAList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
//CRect members to store the position of the items
CRect rItem;
CDC* dcBNJ = CDC::FromHandle(lpDrawItemStruct->hDC);
dcBNJ->SetBkMode(TRANSPARENT);
if ((int)lpDrawItemStruct->itemID < 0)
{
// If there are no elements in the CListBox
// based on whether the list box has Focus or not
// draw the Focus Rect or Erase it,
if ((lpDrawItemStruct->itemAction & ODA_FOCUS) && (lpDrawItemStruct->itemState & ODS_FOCUS))
{
dcBNJ->DrawFocusRect(&lpDrawItemStruct->rcItem);
}
else if ((lpDrawItemStruct->itemAction & ODA_FOCUS) && !(lpDrawItemStruct->itemState & ODS_FOCUS))
{
dcBNJ->DrawFocusRect(&lpDrawItemStruct->rcItem);
}
return;
}
// String to store the text
CString strText;
// Get the item text.
GetText(lpDrawItemStruct->itemID, strText);
//Initialize the CListBox Item's row size
rItem = lpDrawItemStruct->rcItem;
UINT nFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
if (GetStyle() & LBS_USETABSTOPS)
nFormat |= DT_EXPANDTABS;
// If CListBox item selected, draw the highlight rectangle.
// Or if CListBox item deselected, draw the rectangle using the window color.
if ((lpDrawItemStruct->itemState & ODS_SELECTED) &&
(lpDrawItemStruct->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
{
CBrush br(::GetSysColor(COLOR_HIGHLIGHT));
dcBNJ->FillRect(&rItem, &br);
}
else if (!(lpDrawItemStruct->itemState & ODS_SELECTED) && (lpDrawItemStruct->itemAction & ODA_SELECT))
{
CBrush br(m_compBase.GetBkColor());
dcBNJ->FillRect(&rItem, &br);
}
// If the CListBox item has focus, draw the focus rect.
// If the item does not have focus, erase the focus rect.
if ((lpDrawItemStruct->itemAction & ODA_FOCUS) && (lpDrawItemStruct->itemState & ODS_FOCUS))
{
dcBNJ->DrawFocusRect(&rItem);
}
else if ((lpDrawItemStruct->itemAction & ODA_FOCUS) && !(lpDrawItemStruct->itemState & ODS_FOCUS))
{
dcBNJ->DrawFocusRect(&rItem);
}
dcBNJ->SetTextColor(m_compBase.GetFontColor());
CFont *pFont = m_compBase.GetUFont(0,((CUFillerCtrl*)(dynamic_cast<CWnd*>(this)->GetParent()->GetParent()))->m_ihorzScale);
dcBNJ->SelectObject(pFont);
//Draw the Text
dcBNJ->TextOut(rItem.left,rItem.top,strText);
}