Click here to Skip to main content
13,260,181 members (52,063 online)
Click here to Skip to main content


31 bookmarked
Posted 2 Dec 2003

Introduces RSS Reader by AgileInfoSoftware

, 2 Dec 2003
This article introduces an application to consume RSS Feed from Internet.
// ListCtrlSortClass.cpp: implementation of the CListCtrlSortClass class.

#include "stdafx.h"
#include "ListCtrlSortClass.h"
#include "NTHelper.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW

// Construction/Destruction

CListCtrlSortClass::CListCtrlSortClass(CListCtrl *pList, const int nCol)
	m_pList = pList;
	int totItems = m_pList->GetItemCount();

	// Replace All Item Data with pointer to CSortItem class
	for (int i = 0; i < totItems; i++)
		DWORD dw = m_pList->GetItemData(i);
		CString txt = m_pList->GetItemText(i, nCol);
		m_pList->SetItemData(i, (DWORD) new CSortItem(dw, txt));

	// Reset Data value for All item and delete CSortItem pointer
	int totItems = m_pList->GetItemCount();
	for (int i = 0; i < totItems; i++)
		CSortItem *pItem = (CSortItem*)(m_pList->GetItemData(i));
		m_pList->SetItemData(i, pItem->m_dw);
		delete pItem;

void CListCtrlSortClass::Sort(BOOL bAsc, SortDataType dtType)
	// Prepare lParamSort: value == dtType, 
	//         with sign positive for ascending sort order, negative - descending
	long lParamSort = bAsc ? dtType : -dtType;
	m_pList->SortItems(Compare, lParamSort);

int CALLBACK CListCtrlSortClass::Compare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
	CSortItem *pItem1 = (CSortItem*)lParam1;
	CSortItem *pItem2 = (CSortItem*)lParam2;
	ASSERT(pItem1 && pItem2);

	int nOrder = (lParamSort < 0) ? -1 : 1;
	SortDataType dtType = (SortDataType) (lParamSort * nOrder); // get rid of sign

	switch (dtType)
	case SortDataType::dtINT:
		return ( _ttol(pItem1->m_txt) - _ttol(pItem2->m_txt)) * nOrder;
	case SortDataType::dtDEC:
		return (int) ((CNTHelper::_ttof(pItem1->m_txt) - CNTHelper::_ttof(pItem2->m_txt)) * nOrder);
	case SortDataType::dtSTRING:
		return pItem1->m_txt.Compare(pItem2->m_txt) * nOrder;
	case SortDataType::dtSTRINGNOCASE:
		return pItem1->m_txt.CompareNoCase(pItem2->m_txt) * nOrder;
	case SortDataType::dtDATETIME:
			COleDateTime time1, time2;
			if (time1.ParseDateTime(pItem1->m_txt) && time2.ParseDateTime(pItem2->m_txt))
				return ((time1 == time2) ? 0 : (time1 < time2 ? -1 : 1)) * nOrder;
		ASSERT("Error: attempt to sort a column without type.");
		return 0;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author
Web Developer
United States United States
LI is a architect of several database-centric tools and technologies. He has been programming since 1995. He is a Microsoft Certified Solution Developer (MCSD), MCSD.NET, SCJP, SCJD and OCDBA.

His programming experience includes C/C++, C#, MFC, ASP, VB and Perl. He has worked on Solaris, AIX, HPUX and various Windows, and found Windows is the easiest one to work with.

He has over 8 years of database experiences in Oracle, SQL Server, DB2 and other DBMS.

LI co-founded AgileInfoSoftware LLC ( in 2003. He is responsible for the overall vision and development strategy of the company.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 3 Dec 2003
Article Copyright 2003 by
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid