CListBox with Font and Color can be moved(MoveWindow) as you will.

This is a discussion on CListBox with Font and Color can be moved(MoveWindow) as you will. within the Windows Programming forums, part of the Platform Specific Boards category; 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) { } ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    爱国者同盟 Chinese Patriot League
    Posts
    1

    Lightbulb 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);
    }

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    And your question is?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21