Skip to main content
Email Password   helpLost your password?

Sample Image - CCeListCtrlEx.jpg

Introduction

Some weeks ago I tried to implement an owner drawn list box control for my Pocket PC 2002 application. I wanted to show a little icon at the beginning of each line of the list box, like Davide Calabro in his article CListBoxST, a CListBox derived control. So I decided to do this with a simple owner drawn list box control (CListBox).

I was very frustrated as I found out that the owner drawn style of the list box control is not supported under Windows CE. So I was looking for another solution and I found one. I used a simple owner drawn list control (CListCtrl) in the report style to emulate a single select list box with a little icon at the beginning of each line.

I also added some typical list box functions like GetCurSelItem and SetCurSelItem to get and set the current selected item and some functions to move an item of the list to another position. All this functions are used by the sample application, so for closer information just take a look at the source code of the sample application.

The usage

The usage of the owner drawn list control (CCeListCtrlEx) is very straightforward. Just add a list control to your dialog and add a member variable from the type CCeListCtrlEx, that is assigned to the list control, to your dialog class. Don't forget to include the CeListCtrlEx.h header file.

CCeListCtrlEx m_ctrlList;

In the OnInitDialog function of your dialog, create an image list and assign it to the list control. After that you can add some items (with some little icons at the beginning of each line) to the list control.

BOOL CListCtrlTestDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    ...

    // TODO: Add extra initialization here


    ...

    // Create a image list and assign it to the list control

    VERIFY(m_imageList.Create(IDB_BITMAP1, 16, 1, RGB(255, 0, 255)));
    m_ctrlList.SetImageList(&m_imageList, LVSIL_SMALL);

    // Insert some sample items

    for (int n = 0; n < 10; n++)
    {
        CString str;
        str.Format(_T("Item %d"), n);
        m_ctrlList.InsertItem(n, str, n % 8);
    }

    ...

    return TRUE;  // return TRUE unless you set the focus to a control

}

References

The overwritten DrawItem function I was using for my owner drawn list control is based on the article "Selection Highlighting of an Entire Row", written by Uwe Keim. I used the original DrawItem function from Uwe's article and made some simple changes.

To emulate the desktop version of DrawText with the DT_END_ELLIPSIS flag set, that is not supported under Windows CE, I used the DrawTextEndEllipsis function, originally written by Alexander Shargin. You can found this function at http://www.pocketpcdn.com/qa/ellipsis_flag.html.

Release history

Bugs and comments

If you have any comments or find some bugs, I would love to hear about it and make it better.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionHorizontal scroll- how to lose it? Pin
strelaa
9:38 30 Oct '06  
GeneralProblem with with WM 5.0 Pin
bm_masri
12:40 16 Apr '06  
GeneralSubItems Pin
Shabrawy911
8:20 8 Aug '05  
GeneralArabic Problem Pin
Shabrawy911
22:14 2 Aug '05  
Generalit doesn't work Pin
benahpets
0:15 20 Aug '04  
GeneralMultiline texts? Pin
rozbeh
23:58 12 Mar '04  
GeneralRe: Multiline texts? Pin
Bui Huy Kien
23:41 6 Sep '04  
GeneralMultiselect in a List control Pin
reshmasp
19:53 7 Mar '04  
GeneralRe: Multiselect in a List control Pin
Daniel S.
21:19 7 Mar '04  
GeneralRe: Multiselect in a List control Pin
Daniel S.
21:46 7 Mar '04  
GeneralRe: Multiselect in a List control Pin
reshmasp
22:17 7 Mar '04  
GeneralWhat I want to do with custom list box.. Pin
glenn_ford
5:15 21 Jan '04  
GeneralRe: What I want to do with custom list box.. Pin
Daniel S.
9:11 21 Jan '04  
GeneralDoesn't compile uned eVC++ 3.0 Pin
glenn_ford
5:28 20 Jan '04  
GeneralRe: Doesn't compile uned eVC++ 3.0 Pin
glenn_ford
5:30 20 Jan '04  
GeneralRe: Doesn't compile uned eVC++ 3.0 Pin
Daniel S.
21:20 20 Jan '04  
GeneralRe: Doesn't compile uned eVC++ 3.0 Pin
glenn_ford
5:11 21 Jan '04  
GeneralRe: Doesn't compile uned eVC++ 3.0 Pin
M Varshney
3:48 11 Oct '06  
GeneralSuggestion Pin
João Paulo Figueira
23:04 14 May '03  
GeneralRe: Suggestion Pin
Anonymous
23:21 14 May '03  
GeneralRe: Suggestion Pin
Daniel S.
3:58 16 May '03  


Last Updated 14 May 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009