Click here to Skip to main content
Click here to Skip to main content

CCeListCtrlEx for Pocket PC 2002

By , 14 May 2003
 

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)

About the Author

Daniel Strigl
Austria Austria
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHorizontal scroll- how to lose it?memberstrelaa30 Oct '06 - 8:38 
When I give more items, the vertical scrool appera and that is good, but also appers horizontal scrool and i dont want it.
 
Can someone help, please?

GeneralProblem with with WM 5.0memberbm_masri16 Apr '06 - 11:40 
The list control works great under 2003. when i compile it under ev4.0 and run under WM 5.0. I create the list but then if I close the list and open it again, it does not display the items correctly Confused | :confused: Is there any suggestion why this happend?
 
Thanks
 
Love for peace on earth
GeneralSubItemsmemberShabrawy9118 Aug '05 - 7:20 
What about subitems
it does not display subitems
 
Shabrawy
Programmer from egypt

GeneralArabic ProblemmemberShabrawy9112 Aug '05 - 21:14 
hi
i want to reverse the scrollbar position
i want to put it on the left and align the items text to the right
how can such thing can b done?
thanks
 
Shabrawy
Programmer from egypt

Generalit doesn't workmemberbenahpets19 Aug '04 - 23:15 
When i try to open the ressourceView in your sources files, an error occurs : fatal error RC1015 : cannot open include file 'afxres.h'.
 
Could you help me with that
 

Stéphane
QuestionMultiline texts?memberrozbeh12 Mar '04 - 22:58 
Hi.....
 
thanks for this source but i am looking for a multiline listviewer...is it possible to change your sources for this or....
 
Thanks
AnswerRe: Multiline texts?memberBui Huy Kien6 Sep '04 - 22:41 
I am very interested in multiline ListCtrl too.
If you found a solution, let me know.
 
Thanks,
 
-Kien Bui
GeneralMultiselect in a List controlmemberreshmasp7 Mar '04 - 18:53 
Hi,
 
I am trying to use a list control in which I want to
select multiple entries at the same time. This is possible by using a LISTBOX.
But how can I get this using a LISTCONTROL?
 
Could you please help me with this.
 
Thanks in advance,
Reshma
GeneralRe: Multiselect in a List controlmemberDaniel S.7 Mar '04 - 20:19 
Just take a look at the following part in the CeListCtrlEx.cpp file:
// Should the item be highlighted
BOOL bHighlight = /*((lvi.state & LVIS_DROPHILITED)
    || ( (lvi.state & LVIS_SELECTED)
    && ((GetFocus() == this)
    || (GetStyle() & LVS_SHOWSELALWAYS)
    )
    )
    )*/ lvi.state & LVIS_FOCUSED;
When you look at the LVIS_SELECTED flag you can see that you can use it to select more than one entries.
 
You can also take a look at the following article Selection Highlighting of an Entire Row. It will show you how to make it!
 
Regards,
Daniel.
--
FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. Wink | ;)
GeneralRe: Multiselect in a List controlmemberDaniel S.7 Mar '04 - 20:46 
Here are the changes you have to make to enable multiple selection entries:
// Change the style of the control
VERIFY(ModifyStyle(LVS_TYPEMASK       | // this styles are removed
                   LVS_EDITLABELS     |
                   LVS_SINGLESEL,
                   LVS_REPORT         | // this styles are added
                   LVS_OWNERDRAWFIXED |
                   LVS_SHOWSELALWAYS  |
                   LVS_NOCOLUMNHEADER));

 
                   
// Should the item be highlighted
BOOL bHighlight = /*((lvi.state & LVIS_DROPHILITED)
    || ( (lvi.state & LVIS_SELECTED)
    && ((GetFocus() == this)
    || (GetStyle() & LVS_SHOWSELALWAYS)
    )
    )
    )*/ lvi.state & LVIS_SELECTED;                   

 
// Invalidate selected items depending on LVS_SHOWSELALWAYS
//  if(!(GetStyle() & LVS_SHOWSELALWAYS))
    {
        for(nItem = GetNextItem(-1, LVNI_SELECTED);
        nItem != -1; nItem = GetNextItem(nItem, LVNI_SELECTED))
        {
            GetItemRect(nItem, rcBounds, LVIR_BOUNDS);
            GetItemRect(nItem, rcLabel, LVIR_LABEL);
            rcBounds.left = rcLabel.left;
 
            InvalidateRect(rcBounds, FALSE);
        }
    }
//#ifdef _DEBUG
//    else
//        ASSERT(FALSE);
//#endif    

 
Regards,
Daniel.
--
FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. Wink | ;)
GeneralRe: Multiselect in a List controlmemberreshmasp7 Mar '04 - 21:17 
Hi Daniel,
 
I made the modification as suggested but I don't see any change. I am not able to select multiple entries. Could you please help me on this.
 
Thanks in advance,
Reshma
QuestionWhat I want to do with custom list box..memberglenn_ford21 Jan '04 - 4:15 
Dear Daniel,
 
While I have your attention. I am trying to modify your class to paint each character/word
in a specified color. I want "keywords" to be of a certain color (say blue).
 
I also want 2-4 lines of text per entry of the list box. Humm..is this the right control to try and do this with? Your thoughts..?
 
To get an idea of what I am trying to do, I wrote a PALM application (do you have a palm or palm emulator?) and that can be downloaded at: http://archive.nlm.nih.gov/proj/pmot/pmot.php
 
The "results" tab is a custom grid control (for Palm) and I am trying to make a PocketPC version..
 
Thanks for your time,
 
Glenn
AnswerRe: What I want to do with custom list box..memberDaniel S.21 Jan '04 - 8:11 
Hi Glenn!
 
Yeah, I would use it to create some control, because the owner drawn style of the list box control is not supported under Windows CE. So I think it will be the only way to emulate it!
 
Regards,
Daniel.
--
FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. Wink | ;)
GeneralDoesn't compile uned eVC++ 3.0memberglenn_ford20 Jan '04 - 4:28 
I get the following errors when trying to compile your project, please help:
GeneralRe: Doesn't compile uned eVC++ 3.0memberglenn_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.0memberDaniel S.20 Jan '04 - 20:20 
Hi Glenn!
 
I have downloaded the source code from my article and compiled it. And it worked fine!
 
Here is the output:
Deleting intermediate files and output files for project 'ListCtrlTest - Win32 (WCE ARM) Debug'.
E:\Dokumente und Einstellungen\dast\Desktop\CCeListCtrlExSrc\WinXPButtonST.h(43): Could not find the file BtnST.h.
E:\Dokumente und Einstellungen\dast\Desktop\CCeListCtrlExSrc\WinXPButtonST.h(43): Could not find the file BtnST.h.
E:\Dokumente und Einstellungen\dast\Desktop\CCeListCtrlExSrc\WinXPButtonST.h(43): Could not find the file BtnST.h.
--------------------Configuration: ListCtrlTest - Win32 (WCE ARM) Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
CeBtnST.cpp
CeListCtrlEx.cpp
ListCtrlTest.cpp
ListCtrlTestDlg.cpp
NewItemDlg.cpp
WinXPButtonST.cpp
Generating Code...
Linking...
 
ListCtrlTest.exe - 0 error(s), 0 warning(s)
 
What kind of system do you use? Pocket PC 2002?
 
Regards,
Daniel.
--
FIND A JOB YOU LOVE, AND YOU'LL NEVER HAVE TO WORK A DAY OF YOUR LIFE. Wink | ;)
GeneralRe: Doesn't compile uned eVC++ 3.0memberglenn_ford21 Jan '04 - 4:11 
Ahh,
 
I see my problem.
 
I had it set (default in download of project) to
Active WCE Configuration=H/PC Ver. 2.00
 
I switched this to PocketPC and it works fine! Thanks!
 
Sincerely,
 
Glenn
GeneralRe: Doesn't compile uned eVC++ 3.0memberM Varshney11 Oct '06 - 2:48 
Hi
I also compiled it on eVC++ 3 but it always taking Standard SDK even i have installed POCKET PC 2003. It is not selecting updated SDK.. Could you tell me the solution. I have compiled it but after runnin it is not producing the result.
 
Manika Varshney
GeneralSuggestionmemberJoão Paulo Figueira14 May '03 - 22:04 
This is an interesting thing: I never thought that the old faithful listbox would not support ownerdraw... Well, CE development is full of surprises.
 
Here is the suggestion. If you are emulating a listbox, why should the user of your class have to insert the column in the OnInitDialog? You can do this upon creation of the list, but beware that dialog boxes do not send WM_CREATE messages to their children, you must use PreSubclassWindow. My approach is to declare both message and virtual method, and have them call one private method where everything happens (control initialization). This way, you cover all cases: when the control is a child of a dialog (PreSubclassWindow), and when the control is a child of another non-dialog window (OnCreate).
 
Good work!
GeneralRe: SuggestionsussAnonymous14 May '03 - 22:21 
João Paulo Figueira wrote:
Good work!
 
Thanks!
 
João Paulo Figueira wrote:
If you are emulating a listbox, why should the user of your class have to insert the column in the OnInitDialog? You can do this upon creation of the list ...
 
Yes, that's possible and I also do it in my own project at home, where I use this code. But I found out that in some cases it looks very nice (or nessesary) if the header is shown or there are more than one column. But I think I will add it to the sample application! Thanks!
 
Cheers, Daniel.
GeneralRe: SuggestionmemberDaniel S.16 May '03 - 2:58 
I have updated the article! Wink | ;)
 
Daniel Wink | ;)
---------------------------
Never change a running system!

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 15 May 2003
Article Copyright 2003 by Daniel Strigl
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid