jokerjokerer
asked on
SortChildrenCB invalidity
I'm having a problem when dealing with CTreeCtrl's SortChildrenCB function, when the function is executed the first two parameters are always equal to 0. However, the final parameter passed is the correct address for my CTreeCtrl derived class variable.Here is the implementation of my callback function:
int CALLBACK lxEditTreeCtrlEx::MyCompar eProc( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort )
{
// lParamSort contains a pointer to the tree control.
// The lParam of an item is just its handle,
// as specified with <A HREF="_mfc_ctreectrl.3a3a. setitemdat a.htm">Set ItemData</ A>
lxEditTreeCtrlEx* pmyTreeCtrl = (lxEditTreeCtrlEx*) lParamSort;
CString strItem1 = pmyTreeCtrl->GetItemText(( HTREEITEM) lParam1);
CString strItem2 = pmyTreeCtrl->GetItemText(( HTREEITEM) lParam2);
if (!strItem1.Compare(strItem 2))
{
return 0;
}
}
void lxEditTreeCtrlEx::SortChil drenX( HTREEITEM hItem)
{
// The pointer to my tree control.
TVSORTCB tvs;
tvs.hParent = hItem;
CString at = this->GetItemText(hItem);
tvs.lpfnCompare = lxEditTreeCtrlEx::MyCompar eProc;
tvs.lParam = (LPARAM) this;
this->SortChildrenCB(&tvs) ;
}
And in pictures the problem:
http://www.picamatic.com/view/800209_pict_2/
http://www.picamatic.com/view/800210_Pict_p1/
What am I doing wrong... And yes they are items in the three. What better proof than the picture after the sor that frankly does nothing this way:
http://www.picamatic.com/view/800234_pict_3/
int CALLBACK lxEditTreeCtrlEx::MyCompar
{
// lParamSort contains a pointer to the tree control.
// The lParam of an item is just its handle,
// as specified with <A HREF="_mfc_ctreectrl.3a3a.
lxEditTreeCtrlEx* pmyTreeCtrl = (lxEditTreeCtrlEx*) lParamSort;
CString strItem1 = pmyTreeCtrl->GetItemText((
CString strItem2 = pmyTreeCtrl->GetItemText((
if (!strItem1.Compare(strItem
{
return 0;
}
}
void lxEditTreeCtrlEx::SortChil
{
// The pointer to my tree control.
TVSORTCB tvs;
tvs.hParent = hItem;
CString at = this->GetItemText(hItem);
tvs.lpfnCompare = lxEditTreeCtrlEx::MyCompar
tvs.lParam = (LPARAM) this;
this->SortChildrenCB(&tvs)
}
And in pictures the problem:
http://www.picamatic.com/view/800209_pict_2/
http://www.picamatic.com/view/800210_Pict_p1/
What am I doing wrong... And yes they are items in the three. What better proof than the picture after the sor that frankly does nothing this way:
http://www.picamatic.com/view/800234_pict_3/
According to the first picture lParam1 and lParam2 are both 0 - hence the equality when comparing the strings. (Item at zero does equal item at zero !)
ASKER
You don't get it. My problem is why those are 0. Not the rest. They should have a concrete pointer adress as they represent the child items.
Aha, misunderstood your problem.
Maybe have the sort proc (MyCompareProc) a function that is not a member function of the class
Maybe have the sort proc (MyCompareProc) a function that is not a member function of the class
ASKER
I Initially started like that, but the result in the end is the same with the both methods. Any other ideas ?
The calll is made for each item but the first two parameters ar all 0. Tried with a bigger tree also with many-many members ( around 60 MB) and the calls are made but in each case those are 0. If those are zero then comparing is pointless as we don't know what to compare.
The calll is made for each item but the first two parameters ar all 0. Tried with a bigger tree also with many-many members ( around 60 MB) and the calls are made but in each case those are 0. If those are zero then comparing is pointless as we don't know what to compare.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
The function should sort only the child of the item given.
But as said previously regardless on which item is called the parameters are 0. By calling for the' XXXX' also. I have a greater sort ( that sorts all levels by iterating thorugh them) and from there is called this function ( SortChildX). I also have a internal tree container binded to the tree (co-exist) that has a specific sorting function and I need to match the two containers ( the one on the screen and inside the db).
If you have other sorting options for a CTreeCtrl I'm opened for suggestions.
But as said previously regardless on which item is called the parameters are 0. By calling for the' XXXX' also. I have a greater sort ( that sorts all levels by iterating thorugh them) and from there is called this function ( SortChildX). I also have a internal tree container binded to the tree (co-exist) that has a specific sorting function and I need to match the two containers ( the one on the screen and inside the db).
If you have other sorting options for a CTreeCtrl I'm opened for suggestions.
Sorting - no.
If I understand your last comment you are maintaining a sorted structure separate to the tree - so why not use callbacks for the text to display in the tree instead of sorting that also?
TVITEM Structure
...
pszText
Pointer to a null-terminated string that contains the item text if the structure specifies item attributes. If this member is the LPSTR_TEXTCALLBACK value, the parent window is responsible for storing the name.....
If I understand your last comment you are maintaining a sorted structure separate to the tree - so why not use callbacks for the text to display in the tree instead of sorting that also?
TVITEM Structure
...
pszText
Pointer to a null-terminated string that contains the item text if the structure specifies item attributes. If this member is the LPSTR_TEXTCALLBACK value, the parent window is responsible for storing the name.....
ASKER
I'm not sure if I understood properly your suggestion but wouldn't that mean that I need to send the text for each item whenever its requested on the draw procedure fo the tree control ? For this if I'm correct I do need to point to windows when I request the messages and also offer data offering function (like in the case of a virtual list).
The reason for having a separate sorted structure is that only a fragmentoff that is displayed. The internal tree has many data that isn't displayed. But I think yes it can be a option to extract on request the ones needed and display it. But this seams a troublsome problem and the pure sorting seams more eleganat.
If I go made I'll write myself the sort function with some copy,paste,delete combination but that seams an odd way to resolve it and certainly not efficient.
The reason for having a separate sorted structure is that only a fragmentoff that is displayed. The internal tree has many data that isn't displayed. But I think yes it can be a option to extract on request the ones needed and display it. But this seams a troublsome problem and the pure sorting seams more eleganat.
If I go made I'll write myself the sort function with some copy,paste,delete combination but that seams an odd way to resolve it and certainly not efficient.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
It's a great solution altough not answered the question I made. But still a great workaround