Click here to Skip to main content
15,886,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Struct issue Pin
Alexander M.,2-Apr-04 7:36
Alexander M.,2-Apr-04 7:36 
GeneralRe: Struct issue Pin
Maxwell Chen2-Apr-04 7:49
Maxwell Chen2-Apr-04 7:49 
GeneralRe: Struct issue Pin
Anonymous2-Apr-04 11:15
Anonymous2-Apr-04 11:15 
GeneralWrite a matrix to a txt file Pin
dairiseky2-Apr-04 3:15
dairiseky2-Apr-04 3:15 
GeneralRe: Write a matrix to a txt file Pin
David Crow2-Apr-04 4:01
David Crow2-Apr-04 4:01 
GeneralRe: Write a matrix to a txt file Pin
dairiseky2-Apr-04 4:26
dairiseky2-Apr-04 4:26 
GeneralRe: Write a matrix to a txt file Pin
David Crow2-Apr-04 4:56
David Crow2-Apr-04 4:56 
GeneralCTreeCtrl sort parameters getting corrupted Pin
roybrew2-Apr-04 2:17
roybrew2-Apr-04 2:17 
I am seeing an interesting problem using the SortChildrenCB
functionality in the CTreeCtrl class. When I add items to my
treectrl, I set the item data correctly with SetItem, along with some
other things, like the state, statemask. For my "private" item data I
am storing the HTREEITEM that I got back from the
CTreeCtrl::InsertItem call. I correctly cast it to an LPARAM from an
HTREEITEM.

The item gets added correctly and the SetItem also seems to work ok.

So, if I added two nodes to the tree the following values are used:

name1: "apples"
itemdata1: 713A8 (the HTREEITEM of the first node)

name2: "model"
itemdata2: 74008 (the HTREEITEM of the second node)

After adding each node, I fill the appropriate TVSORTCB structure as
follows:

tvs.hParent = parentH; // HTREEITEM of parent node
tvs.lpfnCompare = CompareItems; // address of my compare callback
routine
tvs.lParam = (LPARAM) &ctlTree; // pointer to my treectrl
ctlTree.SortChildrenCB(&tvs);


Now, when my callback routine gets called after adding the second item
to determine which way to sort the items, it gets called with the
itemdata of the first item, itemdata of the second item, and the "sort
parameter. I cast these accordingly:

CTreeCtrl* pMyTreeCtrl = (CTreeCtrl*) lParamSort;

// the lParam of an item is just it's handle
HTREEITEM hTreeItem1 = (HTREEITEM) lParam1;
HTREEITEM hTreeItem2 = (HTREEITEM) lParam2;


The problem is as follows:

the HTREEITEM of the first item gets munged -- by 2. So what I see
in the callback routine for HTREEITEMS is as follows:

hTreeItem1: 713AA (the HTREEITEM of the first node)
hTreeItem2: 74008 (the HTREEITEM of the second node)


Notice the difference in the value of the first handle. It should be
713A8, which is the correct node handle. This fouling up my sorting.

My question is this, to node handles persist? Do they live as long as
the tree node exists? Or, do they get reassigned during
expansion/contraction? In the past, I have hung pointers of more
complex "item data" on tree nodes without trouble. Of course I had to
be responsible for deallocating them when appropriate. But in this
case I thought I was safe using the HTREEITEM as item data, since
given that I could query the tree node for the sorting information I
needed.

Anyone have any ideas on this or have seen this behavior before?

Thanks in advance.

Roy Berger
roybrew@att.net


Regards,

Roy

_____________
Roy H. Berger
roybrew@att.net


GeneralLoadLibrary Error Pin
JeabJB2-Apr-04 2:07
JeabJB2-Apr-04 2:07 
GeneralRe: LoadLibrary Error Pin
Alexander M.,2-Apr-04 2:13
Alexander M.,2-Apr-04 2:13 
GeneralRe: LoadLibrary Error Pin
JeabJB2-Apr-04 2:29
JeabJB2-Apr-04 2:29 
GeneralRe: LoadLibrary Error Pin
David Crow2-Apr-04 2:56
David Crow2-Apr-04 2:56 
GeneralRe: LoadLibrary Error Pin
JeabJB2-Apr-04 3:10
JeabJB2-Apr-04 3:10 
GeneralRe: LoadLibrary Error Pin
David Crow2-Apr-04 3:23
David Crow2-Apr-04 3:23 
GeneralRe: LoadLibrary Error Pin
JeabJB2-Apr-04 3:34
JeabJB2-Apr-04 3:34 
GeneralRe: LoadLibrary Error Pin
David Crow2-Apr-04 3:38
David Crow2-Apr-04 3:38 
GeneralRe: LoadLibrary Error Pin
JeabJB2-Apr-04 3:49
JeabJB2-Apr-04 3:49 
GeneralRe: LoadLibrary Error Pin
David Crow2-Apr-04 4:05
David Crow2-Apr-04 4:05 
Generaliterator Pin
Jerome Conus2-Apr-04 1:53
Jerome Conus2-Apr-04 1:53 
GeneralRe: iterator Pin
Jonas Larsson2-Apr-04 2:12
Jonas Larsson2-Apr-04 2:12 
GeneralRe: iterator Pin
Maxwell Chen2-Apr-04 2:14
Maxwell Chen2-Apr-04 2:14 
GeneralRe: iterator Pin
monrobot132-Apr-04 6:30
monrobot132-Apr-04 6:30 
GeneralCDialogBar problem Pin
Krugger4042-Apr-04 1:53
Krugger4042-Apr-04 1:53 
GeneralCDialogBar problem Pin
Krugger4042-Apr-04 1:52
Krugger4042-Apr-04 1:52 
Generalcout Pin
Oriented2-Apr-04 0:59
Oriented2-Apr-04 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.