|
Hi...
The control is nice, but there are a few bugs when using it in a view:
1) The control does not show scrollbars (vertical and horizontal)
2) The header control is not correctly updated when the user resizes the view window (ie, in a SDI view).
Thanks.
MaxPayne.
|
|
|
|
|
Hi,
In View, I am unable to successfully create an instance of CSortListCtrl in View.
The statement CSortListCtrl m_ListCtrl; returns a NULL for m_ListCtrl.
-Pete
Pete
|
|
|
|
|
Although this does work fine, I didn't want the container to know about the HeaderCtrl inside the ListCtrl, so what I did was:
a) safegaurd the PreSubclassWindow call with a check to make sure that the GetHeaderCtrl() returned a valid pointer (althought this may not be needed at all any more).
b) override both the create and createex in the listctrl class and add the subclassing there.
So the three functions should look like:
void FCListCtrl::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CListCtrl::PreSubclassWindow();
if(GetHeaderCtrl()) // Works for placed controls (non-dynamic creation)
VERIFY( m_ctlHeader.SubclassWindow( GetHeaderCtrl()->GetSafeHwnd() ) );
}
BOOL FCListCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
// TODO: Add your specialized code here and/or call the base class
BOOL bReturn = CListCtrl::Create(dwStyle, rect, pParentWnd, nID);
VERIFY( m_ctlHeader.SubclassWindow( GetHeaderCtrl()->GetSafeHwnd() ) );
return bReturn;
}
BOOL FCListCtrl::CreateEx(DWORD dwExStyle, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
// TODO: Add your specialized code here and/or call the base class
BOOL bReturn = CListCtrl::CreateEx(dwExStyle, dwStyle, rect, pParentWnd, nID);
VERIFY( m_ctlHeader.SubclassWindow( GetHeaderCtrl()->GetSafeHwnd() ) );
return bReturn;
}
Now anyone else can use the list control in any manner they like, and all they have to do is include the 4 files (two headerctrl and two listctrl files).
Works for me anyhow, hopefuly you'll find it usefull.
Thanks very much for the submission, I was just looking for the header control, this saved me time! The header ctrl is used as is but I noticed the web site listed in the header no longer exists, let me know if you want this updated.
Regards,
Adam
Adam Bialowas
Systems Engineer
Fugro Chance Inc.
|
|
|
|
|
If you create listctrl within WS_VISIBLE, the headerctrl haven't create.
so, you must notice it.
// the safe create
BOOL CListCtrlForFlatTab::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
bool show = dwStyle&WS_VISIBLE;
BOOL ret = __super::Create(dwStyle|WS_VISIBLE, rect, pParentWnd, nID);
subclass_header();
if (!show)
ShowWindow(SW_HIDE);
return ret;
}
|
|
|
|
|
I find it work well,thanks.
When I click on the header, the sort button will display, but the text on the header will move.
How can I solve the problem.
|
|
|
|
|
inline bool IsNumber( LPCTSTR pszText )
{
ASSERT_VALID_STRING( pszText );
register int iBegin, length = lstrlen( pszText );
if ( length && pszText[0] == '-' ) iBegin = 1; else iBegin = 0;
for( register i = iBegin; i < length; i++ )
if( !_istdigit( pszText[ i ] ) && (pszText[ i ] != _T( '.' )) )
return false;
return true;
}
|
|
|
|
|
Hi,
The code has sort routines for sorting numbers, text, and date, but when I use it with IP addresses, it doesn't seem to work. For example, if I have the following IP addresses in the list:
10.10.10.1
10.10.10.2
10.10.10.3
and I enter a new address value, for example: 10.10.10.10, I get the following result:
10.10.10.1
10.10.10.10 <---new value
10.10.10.2
10.10.10.3
The current sorting routine for sorting the date is close to what I would like to do, but the difference is that, the number of digits in the 4 octets of the IP address is not of a fixed length like the date (99/99/9999), because the user can enter different values like: 1.1.1.1 or 192.254.100.244, which would change the position of the indices if we are to implement a similar routine.
How can I implement this? Any help is much appreciated.
CS
|
|
|
|
|
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 );
|
|
|
|
|
Hi VS.NOT,
Here's a small modification to help if you have a UNICODE project.
Jeff
INT SortIPAddress( LPCTSTR pszOne, LPCTSTR pszTwo, INT nOrder )
{
INT nReturn = 0;
ULONG lIP1, lIP2;
#ifdef UNICODE
{
USES_CONVERSION;
lIP1 = inet_addr( T2A( pszOne ) );
lIP2 = inet_addr( T2A( pszTwo ) );
}
#else
{
lIP1 = inet_addr( pszOne );
lIP2 = inet_addr( pszTwo );
}
#endif
if( lIP1 < lIP2 ) {
nReturn = -1;
} else if ( lIP1 > lIP2 ) {
nReturn = 1;
} else {
nReturn = 0;
}
return nOrder == SORT_ASCENDING ? nReturn : nReturn * -1;
}
|
|
|
|
|
I found that the above sort does not work as expected! It sorts on the 4th octet, then the 1st and 2nd - disregarding the 3rd octet.
Here's something I used to work around (I did not feel like Googling for a solution). It assumes a well formed IP address of the form a.b.c.d:
INT SortIPAddress( LPCTSTR pszOne, LPCTSTR pszTwo, INT nOrder )
{
const INT NOT_FOUND = -1;
INT nReturn = 0, nPos, nShift;
CString szIP1 = pszOne, szIP2 = pszTwo;
ULONG lIP1 = 0, lIP2 = 0;
nShift = 24;
while( NOT_FOUND != ( nPos = szIP1.Find( _T(".") ) ) ) {
lIP1 += _ttoi( szIP1.Left( nPos ) ) << nShift;
szIP1 = szIP1.Right( szIP1.GetLength() - nPos - 1 );
nShift -= 8;
}
lIP1 += _ttoi( szIP1 );
nShift = 24;
while( NOT_FOUND != ( nPos = szIP2.Find( _T(".") ) ) ) {
lIP2 += _ttoi( szIP2.Left( nPos ) ) << nShift;
szIP2 = szIP2.Right( szIP2.GetLength() - nPos - 1 );
nShift -= 8;
}
lIP2 += _ttoi( szIP2 );
nReturn = lIP1 - lIP2;
return nOrder == SORT_ASCENDING ? nReturn : nReturn * -1;
}
|
|
|
|
|
if pszIP1 is host byte order, should to change to:
long lIP1 = htonl(inet_addr(pszIP1));
long lIP2 = htonl(inet_addr(pszIP2));
|
|
|
|
|
beautiful..
|
|
|
|
|
Hello,
How about sorting, when style set to Icon. Is it supported by standart CListCtrl? Or there will be no other way, but to implement it's handling myself?
Any ideas?
Thank you.
Rimantas
|
|
|
|
|
I use the sort method of CListCtrl,but the following code
is not work,Why?
static int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
CString strItem2 = pListCtrl->GetItemText(lParam2, 0);
return strcmp(strItem2, strItem1);
}
void SortItems()
{
extern CListCtrl* pmyListCtrl;
pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
}
Thanks in advance!
Best Regards!
|
|
|
|
|
first, the second parameter of "SortItems" must be DWORD type, but in your code, the second parameter is "LPARAM" type.
second, check if the "pmyListCtrl" points to the right CListCtrl object. it's possible that "pmyListCtrl" is null.
only my opinion, it can be wrong...
|
|
|
|
|
you have to use SetItemData() to set the sort index first.
|
|
|
|
|
In order for floating point sorting to be done properly, a couple of simple changes need to be made. (Great coding, btw!):
Before:
bool IsNumber( LPCTSTR pszText )
{
ASSERT_VALID_STRING( pszText );
register int i, length = lstrlen( pszText );
for( i = 0; i < length; i++ )
if( !_istdigit( pszText[ i ] ) )
return false;
return true;
}
After:
bool IsNumber( LPCTSTR pszText )
{
ASSERT_VALID_STRING( pszText );
register int i, length = lstrlen( pszText );
for( i = 0; i < length; i++ )
if( !_istdigit( pszText[ i ] ) && (pszText[ i ] != _T( '.' )) )
return false;
return true;
}
and Before:
int NumberCompare( LPCTSTR pszNumber1, LPCTSTR pszNumber2 )
{
ASSERT_VALID_STRING( pszNumber1 );
ASSERT_VALID_STRING( pszNumber2 );
const int iNumber1 = atoi( pszNumber1 );
const int iNumber2 = atoi( pszNumber2 );
if( iNumber1 < iNumber2 )
return -1;
if( iNumber1 > iNumber2 )
return 1;
return 0;
}
After:
int NumberCompare( LPCTSTR pszNumber1, LPCTSTR pszNumber2 )
{
ASSERT_VALID_STRING( pszNumber1 );
ASSERT_VALID_STRING( pszNumber2 );
const float iNumber1 = atof( pszNumber1 );
const float iNumber2 = atof( pszNumber2 );
if( iNumber1 < iNumber2 )
return -1;
if( iNumber1 > iNumber2 )
return 1;
return 0;
}
|
|
|
|
|
I want to use this contorl in a SDI project, but when I creat this control in the view, the program got an "unknown software exception(0x800000003)". I use create function in the OnInitialUpdate(), and the code like this:
...
m_list = new CSortListCtrl;
if (!m_list) return;
CRect rect;
GetClientRect(rect);
m_list->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,rect, this, 100);
...
Can someone help me? Is there any SDI or MDI demo about this control?
|
|
|
|
|
I have the same problem too.
I need some advice.
help us.
|
|
|
|
|
I didn't see any responses to your request on the SDI example for the sort list control. Did you ever get it figured out? I'm trying to do the same thing.
Mike Ellertson
|
|
|
|
|
First place the listctrl onto a dialog, and then put the dialog into a view.
______________
Anything, I Can.
|
|
|
|
|
|
Hi,
In View, I am unable to successfully create an instance of CSortListCtrl.
The statement CSortListCtrl m_ListCtrl; or CSortListCtrl = new m_ListCtrl; returns a NULL for m_ListCtrl. So am not able to reference any of its functions in View. I wish someone could show me how!!
mad:
Pete
|
|
|
|
|
Some folks had been complaining about how horrendous the header control looked in Win XP w/ Visual Styles. I believe I have fixed this issue. I changed the function SetSortArrow in SortHeaderCtrl.cpp to the following:
<br />
void CSortHeaderCtrl::SetSortArrow(const int iSortColumn, const BOOL bSortAscending)<br />
{<br />
DWORD dwHigh, dwLow;<br />
<br />
GetCommonControlVersion(dwHigh, dwLow);<br />
<br />
if (dwHigh < 6)<br />
{<br />
HD_ITEM hditem;<br />
<br />
hditem.mask = HDI_FORMAT;<br />
VERIFY(GetItem(iSortColumn, &hditem));<br />
hditem.fmt |= HDF_OWNERDRAW;<br />
VERIFY(SetItem(iSortColumn, &hditem));<br />
<br />
Invalidate();<br />
}<br />
else<br />
{<br />
HD_ITEM hditem;<br />
<br />
hditem.mask = HDI_FORMAT;<br />
VERIFY(GetItem(iSortColumn, &hditem));<br />
<br />
if (bSortAscending)<br />
{<br />
hditem.fmt &= ~HDF_SORTDOWN;<br />
hditem.fmt |= HDF_SORTUP;<br />
}<br />
else<br />
{<br />
hditem.fmt &= ~HDF_SORTUP;<br />
hditem.fmt |= HDF_SORTDOWN;<br />
}<br />
<br />
VERIFY(SetItem(iSortColumn, &hditem));<br />
<br />
if ((m_iSortColumn > -1) && (m_iSortColumn != iSortColumn))<br />
{<br />
hditem.mask = HDI_FORMAT;<br />
VERIFY(GetItem(m_iSortColumn, &hditem));<br />
<br />
hditem.fmt &= ~HDF_SORTUP;<br />
hditem.fmt &= ~HDF_SORTDOWN;<br />
VERIFY(SetItem(m_iSortColumn, &hditem));<br />
}<br />
}<br />
<br />
m_iSortColumn = iSortColumn;<br />
m_bSortAscending = bSortAscending;<br />
}<br />
and my little function to get the common control version is also in this class (although it doesn't need to be).
<br />
bool CSortHeaderCtrl::GetCommonControlVersion(DWORD &dwHigh, DWORD &dwLow)<br />
{<br />
bool bRet = false;<br />
<br />
HMODULE hMod = LoadLibrary("COMCTL32.DLL");<br />
<br />
if (hMod != NULL)<br />
{<br />
DLLGETVERSIONPROC pDllGetVersion;<br />
pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hMod, "DllGetVersion");<br />
<br />
if (pDllGetVersion)<br />
{<br />
DLLVERSIONINFO dvi;<br />
HRESULT hr;<br />
<br />
ZeroMemory(&dvi, sizeof(dvi));<br />
dvi.cbSize = sizeof(dvi);<br />
<br />
hr = (*pDllGetVersion)(&dvi);<br />
<br />
if (SUCCEEDED(hr))<br />
{<br />
memcpy(&dwHigh, &dvi.dwMajorVersion, sizeof(DWORD));<br />
memcpy(&dwLow, &dvi.dwMinorVersion, sizeof(DWORD));<br />
}<br />
}<br />
<br />
FreeLibrary(hMod);<br />
}<br />
else<br />
{<br />
bRet = false;<br />
}<br />
<br />
return bRet;<br />
}<br />
Hope this helps.
Give me one more medicated peaceful moment
|
|
|
|
|
Thanks for the fix. It works for me with VS6SP5, but I am using an old version of the SDK.
So I added:
#ifndef HDF_SORTUP
#define HDF_SORTUP 0x0400
#endif
#ifndef HDF_SORTDOWN
#define HDF_SORTDOWN 0x0200
#endif
|
|
|
|
|