hi,
i found this website to do the listctrol column sorting. for the IP sort, a person pasted something like this,
//********************
Ok here's code to make it sort IP Addresses. Note: this will make the code depend on the winsock libraries for inet_addr, you could re-implement inet_addr yourself if you wanted to avoid this dependencies. To the code...
You need to add these 2 functions to SortListCtrl.cpp:
bool IsIPAddr(LPCSTR pszText)
{
ASSERT_VALID_STRING( pszText );
if (inet_addr(pszText) != INADDR_NONE)
return true;
else
return false;
}
int IPAddrCompare(LPCTSTR pszIP1, LPCTSTR pszIP2)
{
ASSERT_VALID_STRING( pszIP1 );
ASSERT_VALID_STRING( pszIP2 );
long lIP1 = inet_addr(pszIP1);
long lIP2 = inet_addr(pszIP2);
if( lIP1 < lIP2 )
return -1;
if( lIP1 > lIP2 )
return 1;
return 0;
}
then you need to change the CSortListCtrl::CompareFunction function comparison part to:
if( IsNumber( pszText1 ) )
return pListCtrl->m_bSortAscending ? NumberCompare( pszText1, pszText2 ) : NumberCompare( pszText2, pszText1 );
else if (IsIPAddr(pszText1))
return pListCtrl->m_bSortAscending ? IPAddrCompare(pszText1, pszText2) : IPAddrCompare(pszText2, pszText1);
else if( IsDate( pszText1 ) )
return pListCtrl->m_bSortAscending ? DateCompare( pszText1, pszText2 ) : DateCompare( pszText2, pszText1 );
else
// text.
return pListCtrl->m_bSortAscending ? lstrcmp( pszText1, pszText2 ) : lstrcmp( pszText2, pszText1 );
could anyone tell me how to include the winsock library, or give me some sample code to write the inet_address the person suggested?
thanks so much!
regards,
kaya
i found this website to do the listctrol column sorting. for the IP sort, a person pasted something like this,
//********************
Ok here's code to make it sort IP Addresses. Note: this will make the code depend on the winsock libraries for inet_addr, you could re-implement inet_addr yourself if you wanted to avoid this dependencies. To the code...
You need to add these 2 functions to SortListCtrl.cpp:
bool IsIPAddr(LPCSTR pszText)
{
ASSERT_VALID_STRING( pszText );
if (inet_addr(pszText) != INADDR_NONE)
return true;
else
return false;
}
int IPAddrCompare(LPCTSTR pszIP1, LPCTSTR pszIP2)
{
ASSERT_VALID_STRING( pszIP1 );
ASSERT_VALID_STRING( pszIP2 );
long lIP1 = inet_addr(pszIP1);
long lIP2 = inet_addr(pszIP2);
if( lIP1 < lIP2 )
return -1;
if( lIP1 > lIP2 )
return 1;
return 0;
}
then you need to change the CSortListCtrl::CompareFunction function comparison part to:
if( IsNumber( pszText1 ) )
return pListCtrl->m_bSortAscending ? NumberCompare( pszText1, pszText2 ) : NumberCompare( pszText2, pszText1 );
else if (IsIPAddr(pszText1))
return pListCtrl->m_bSortAscending ? IPAddrCompare(pszText1, pszText2) : IPAddrCompare(pszText2, pszText1);
else if( IsDate( pszText1 ) )
return pListCtrl->m_bSortAscending ? DateCompare( pszText1, pszText2 ) : DateCompare( pszText2, pszText1 );
else
// text.
return pListCtrl->m_bSortAscending ? lstrcmp( pszText1, pszText2 ) : lstrcmp( pszText2, pszText1 );
could anyone tell me how to include the winsock library, or give me some sample code to write the inet_address the person suggested?
thanks so much!
regards,
kaya