|

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();
...
...
VERIFY(m_imageList.Create(IDB_BITMAP1, 16, 1, RGB(255, 0, 255)));
m_ctrlList.SetImageList(&m_imageList, LVSIL_SMALL);
for (int n = 0; n < 10; n++)
{
CString str;
str.Format(_T("Item %d"), n);
m_ctrlList.InsertItem(n, str, n % 8);
}
...
return TRUE;
}
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. |
|
| | Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh) | FirstPrevNext |
|
 |
|
|
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?
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
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 Is there any suggestion why this happend?
Thanks
Love for peace on earth
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 1.75/5 (5 votes) |
|
|
|
 |
|
|
Hi.....
thanks for this source but i am looking for a multiline listviewer...is it possible to change your sources for this or....
Thanks
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
I am very interested in multiline ListCtrl too. If you found a solution, let me know.
Thanks,
-Kien Bui
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
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. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
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)
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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. 
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
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!
|
| Sign In·View Thread·PermaLink | 4.00/5 (2 votes) |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have updated the article!
Daniel  --------------------------- Never change a running system!
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|