Click here to Skip to main content
Click here to Skip to main content
Go to top

CCeListCtrlEx for Pocket PC 2002

, 14 May 2003
Rate this:
Please Sign up or sign in to vote.
A owner drawn list control to emulate a single select list box with a little icon at the beginning of each line.

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.

  • int GetCurSelItem() const;
  • BOOL SetCurSelItem(int nIndex);
  • BOOL MoveItem(int nOldIndex, int nNewIndex);
  • BOOL MoveItemUp(int nIndex);
  • BOOL MoveItemDown(int nIndex);
  • BOOL MoveItemTop(int nIndex);
  • BOOL MoveItemBottom(int nIndex);

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

  • 16 May 2003

    The needed column for the list control is now created automatically (thanks to João Paulo Figueira).

  • 15 May 2003

    First release in CodeProject.

Bugs and comments

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Daniel Strigl

Austria Austria
No Biography provided

Comments and Discussions

 
QuestionHorizontal scroll- how to lose it? Pinmemberstrelaa30-Oct-06 8:38 
GeneralProblem with with WM 5.0 Pinmemberbm_masri16-Apr-06 11:40 
GeneralSubItems PinmemberShabrawy9118-Aug-05 7:20 
GeneralArabic Problem PinmemberShabrawy9112-Aug-05 21:14 
Generalit doesn't work Pinmemberbenahpets19-Aug-04 23:15 
QuestionMultiline texts? Pinmemberrozbeh12-Mar-04 22:58 
AnswerRe: Multiline texts? PinmemberBui Huy Kien6-Sep-04 22:41 
GeneralMultiselect in a List control Pinmemberreshmasp7-Mar-04 18:53 
GeneralRe: Multiselect in a List control PinmemberDaniel S.7-Mar-04 20:19 
GeneralRe: Multiselect in a List control PinmemberDaniel S.7-Mar-04 20:46 
GeneralRe: Multiselect in a List control Pinmemberreshmasp7-Mar-04 21:17 
QuestionWhat I want to do with custom list box.. Pinmemberglenn_ford21-Jan-04 4:15 
AnswerRe: What I want to do with custom list box.. PinmemberDaniel S.21-Jan-04 8:11 
GeneralDoesn't compile uned eVC++ 3.0 Pinmemberglenn_ford20-Jan-04 4:28 
GeneralRe: Doesn't compile uned eVC++ 3.0 Pinmemberglenn_ford20-Jan-04 4:30 
Sorry, it terminated my message before I could post the errors which are:
-------------------Configuration: ListCtrlTest - Win32 (WCE MIPS) Debug--------------------
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\WinXPButtonST.h(43): Could not find the file BtnST.h.
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\WinXPButtonST.h(43): Could not find the file BtnST.h.
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\WinXPButtonST.h(43): Could not find the file BtnST.h.
Compiling...
CeBtnST.cpp
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\CeBtnST.cpp(98) : error C2065: 'ON_WM_SETCURSOR' : undeclared identifier
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\CeBtnST.cpp(99) : error C2059: syntax error : '{'
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\CeBtnST.cpp(357) : error C2065: 'SEE_MASK_FLAG_NO_UI' : undeclared identifier
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\CeBtnST.cpp(360) : error C2065: 'SW_SHOWMAXIMIZED' : undeclared identifier
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\CeBtnST.cpp(928) : error C2065: 'IMAGE_CURSOR' : undeclared identifier
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\CeBtnST.cpp(1148) : error C2039: 'GetCursorPos' : is not a member of '`global namespace''
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\CeBtnST.cpp(1148) : error C2065: 'GetCursorPos' : undeclared identifier
CeListCtrlEx.cpp
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\CeListCtrlEx.cpp(29) : error C2065: 'NM_RECOGNIZEGESTURE' : undeclared identifier
ListCtrlTestDlg.cpp
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\ListCtrlTestDlg.cpp(48) : error C2065: 'NM_RECOGNIZEGESTURE' : undeclared identifier
NewItemDlg.cpp
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\NewItemDlg.cpp(27) : error C2065: 'm_bFullScreen' : undeclared identifier
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\NewItemDlg.cpp(45) : error C2065: 'NM_RECOGNIZEGESTURE' : undeclared identifier
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\NewItemDlg.cpp(47) : error C2065: 'ON_WM_SETTINGCHANGE' : undeclared identifier
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\NewItemDlg.cpp(49) : error C2059: syntax error : '{'
C:\Program Files\Microsoft eMbedded Tools\Common\EVC\MyProjects\CCeListCtrlExSrc\NewItemDlg.cpp(96) : error C2039: 'OnSettingChange' : is not a member of 'CWnd'
Generating Code...
Error executing clmips.exe.
 
ListCtrlTest.exe - 14 error(s), 0 warning(s)

GeneralRe: Doesn't compile uned eVC++ 3.0 PinmemberDaniel S.20-Jan-04 20:20 
GeneralRe: Doesn't compile uned eVC++ 3.0 Pinmemberglenn_ford21-Jan-04 4:11 
GeneralRe: Doesn't compile uned eVC++ 3.0 PinmemberM Varshney11-Oct-06 2:48 
GeneralSuggestion PinmemberJoão Paulo Figueira14-May-03 22:04 
GeneralRe: Suggestion PinsussAnonymous14-May-03 22:21 
GeneralRe: Suggestion PinmemberDaniel S.16-May-03 2:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 15 May 2003
Article Copyright 2003 by Daniel Strigl
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid