| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 985 人关注过本帖
标题:一个CListBox类的应用问题
只看楼主 加入收藏
Lyone
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:99
专家分:195
注 册:2010-12-7
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
一个CListBox类的应用问题
想要实现CListBox里的字体颜色不同,是不是做一个CListBox派生类,然后覆盖掉DrawItem这个方法就可以?
搜索更多相关主题的帖子: 应用 
2010-12-30 13:14
pbreak
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:83
专家分:558
注 册:2007-5-10
收藏
得分:20 
派生CListBox,为CListBox添加一个私有成员map<UINT,COLORREF> m_itemTextColor;
重载AddString 方法 如下:
int AddString(LPCTSTR lpszItem,COLORREF clf)
{
    int iRet = CListBox::AddString(lpszItem);
    if (iRet >= 0)
        m_itemTextColor[iRet] = clf;
    return iRet;
}
在DrawItem中:
    COLORREF textColor = RGB(0,0,0);
    map<UINT,COLORREF>::iterator it = m_itemTextColor.find(lpDIS->itemID);
    if (it != m_itemTextColor.end())
        textColor = m_itemTextColor[lpDIS->itemID];
    pDC->SetTextColor(textColor);
这样就能设置每行的颜色了。   
2010-12-30 16:08
Lyone
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:99
专家分:195
注 册:2010-12-7
收藏
得分:0 
以下是引用pbreak在2010-12-30 16:08:37的发言:

派生CListBox,为CListBox添加一个私有成员map m_itemTextColor;
重载AddString 方法 如下:
int AddString(LPCTSTR lpszItem,COLORREF clf)
{
    int iRet = CListBox::AddString(lpszItem);
    if (iRet >= 0)
        m_itemTextColor = clf;
    return iRet;
}
在DrawItem中:
    COLORREF textColor = RGB(0,0,0);
    map::iterator it = m_itemTextColor.find(lpDIS->itemID);
    if (it != m_itemTextColor.end())
        textColor = m_itemTextColor[lpDIS->itemID];
    pDC->SetTextColor(textColor);
这样就能设置每行的颜色了。   
请问蓝色标记的这里属于哪方面的知识?我第一次见到。我还需要继续找资料学习一下。
2010-12-31 09:30
Lyone
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:99
专家分:195
注 册:2010-12-7
收藏
得分:0 
好像在msdn中找到了

template<class Key, class T, class Pred = less<Key>, class A = allocator<T> >
    class map {
public:
    typedef Key key_type;
    typedef T referent_type;
    typedef Pred key_compare;
    typedef A allocator_type;
    typedef pair<const Key, T> value_type;
    class value_compare;
    typedef A::size_type size_type;
    typedef A::difference_type difference_type;
    typedef A::rebind<value_type>::other::reference reference;
    typedef A::rebind<value_type>::other::const_reference const_reference;
    typedef T0 iterator;
    typedef T1 const_iterator;
    typedef reverse_bidirectional_iterator<iterator,
        value_type, reference, A::pointer,
            difference_type> reverse_iterator;
    typedef reverse_bidirectional_iterator<const_iterator,
        value_type, const_reference, A::const_pointer,
            difference_type> const_reverse_iterator;
    explicit map(const Pred& comp = Pred(), const A& al = A());
    map(const map& x);
    map(const value_type *first, const value_type *last,
        const Pred& comp = Pred(),
            const A& al = A());
    iterator begin();
    const_iterator begin() const;
    iterator end();
    iterator end() const;
    reverse_iterator rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator rend();
    const_reverse_iterator rend() const;
    size_type size() const;
    size_type max_size() const;
    bool empty() const;
    A get_allocator() const;
    A::reference operator[](const Key& key);
    pair<iterator, bool> insert(const value_type& x);
    iterator insert(iterator it, const value_type& x);
    void insert(const value_type *first, const value_type *last);
    iterator erase(iterator it);
    iterator erase(iterator first, iterator last);
    size_type erase(const Key& key);
    void clear();
    void swap(map x);
    key_compare key_comp() const;
    value_compare value_comp() const;
    iterator find(const Key& key);
    const_iterator find(const Key& key) const;
    size_type count(const Key& key) const;
    iterator lower_bound(const Key& key);
    const_iterator lower_bound(const Key& key) const;
    iterator upper_bound(const Key& key);
    const_iterator upper_bound(const Key& key) const;
    pair<iterator, iterator> equal_range(const Key& key);
    pair<const_iterator, const_iterator>
        equal_range(const Key& key) const;
protected:
    A allocator;
    };

The template class describes an object that controls a varying-length sequence of elements of type pair<const Key, T>. The first element of each pair is the sort key and the second is its associated value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element with a number of operations proportional to the logarithm of the number of elements in the sequence (logarithmic time). Moreover, inserting an element invalidates no iterators, and removing an element invalidates only those iterators that point at the removed element.
2010-12-31 09:50
Lyone
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:99
专家分:195
注 册:2010-12-7
收藏
得分:0 
map::iterator
typedef T0 iterator;
The type describes an object that can serve as a bidirectional iterator for the controlled sequence. It is described here as a synonym for the unspecified type T0.

map::find
iterator find(const Key& key);
const_iterator find(const Key& key) const;
The member function returns an iterator that designates the earliest element in the controlled sequence whose sort key equals key. If no such element exists, the iterator equals end().


map::end
const_iterator end() const;
iterator end();
The member function returns a bidirectional iterator that points just beyond the end of the sequence.


[ 本帖最后由 Lyone 于 2010-12-31 09:58 编辑 ]
2010-12-31 09:51
快速回复:一个CListBox类的应用问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045652 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved