|
Thanks for your prompt reply.
I am seeking an easier solution for this.
Regards,
Paresh.
|
|
|
|
|
Paresh Chitte wrote: I am seeking an easier solution for this.
What's hard about that? It seemed easy and straight forward to me.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
See Here[^]
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thanks for your prompt reply.
Regards,
Paresh.
|
|
|
|
|
Found solution here[^].
Thank you all for your replies.
Regards,
Paresh.
|
|
|
|
|
The function ItemHasChildren (TreeItem) returns true for a perticular node but GetChildItem (TreeItem) doesnot return a valid node without expanding the node TreeItem . This expanding and shrinking is causing flicker in the tree. Could anyone provide a better solution ?
The sample code is following -
if (ItemHasChildren (TreeItem))
{
HTREEITEM tmpTreeItem = TreeItem;
Expand (tmpTreeItem, TVE_TOGGLE);
TreeItem = GetChildItem (TreeItem);
Expand (tmpTreeItem, TVE_TOGGLE);
}
|
|
|
|
|
NishantB++ wrote: expanding and shrinking is causing flicker in the tree.
Stop the tree from redrawing while you are tampering with it.
From my CTreeView I do:
GetTreeCtrl().SetRedraw( FALSE);<br />
...<br />
GetTreeCtrl().SetRedraw( TRUE);
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Thanks for your reply.
I have already tried this option, and it is not working.
By the way, have you seen this kind of behaviour that you have to expand the tree first to get the child node, or I am doing something wrong?
|
|
|
|
|
NishantB++ wrote: expand the tree first to get the child node
I have.
But then I use CWaitingTreeCtrl from Codeproject[^], and there things are much more complicated.
It might really be that the item does not know that it has children and how many of them.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
The below code is from MSDN. While their samples can be lacking sometimes, they're not usually wrong.
if (pmyTreeCtrl->ItemHasChildren(hmyItem))
{
HTREEITEM hNextItem;
HTREEITEM hChildItem = pmyTreeCtrl->GetChildItem(hmyItem);
while (hChildItem != NULL)
{
hNextItem = pmyTreeCtrl->GetNextItem(hChildItem, TVGN_NEXT);
pmyTreeCtrl->DeleteItem(hChildItem);
hChildItem = hNextItem;
}
}
The only thing I can think of that may mess it up is if your parent item does not actually have children in it, but you've manually set its item.cChildren to I_CHILDRENCALLBACK.
Can you check the return value from ItemHasChildren to make sure it's 0 or 1?
Iain.
|
|
|
|
|
hi i am new to c programming.
currently i am trying to do dynamic memory allocation to my struct so that i dont have to use a set number of array:
struct person ptr[10];//i dont want this
i have come up to this:
struct person ptr*;
could anyone show me how to do a dynamic memory allocation on struct which can free me of having to state the array size?
i read some ebook saying i could use malloc but so far they used malloc on the string instead of struct.
thanks.
|
|
|
|
|
...define person...
struct person *pPerson;
unsigned int count = 10;
pPerson = malloc( count * sizeof( person));
if( pPersion = NULL) {
printf( "Insufficient memory available\n" );
exit(0);
}
...use pPerson...
free( pPerson);
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
i see where the code is going however could you show me how i shoudl go if i wanted to append to the pointer?
i am thinking if i should create a temp space and reallocated the memory againa dn stores it back in.
how do you think i should do it? and again i would like to say i am doing c programming.
thx
|
|
|
|
|
neodeaths wrote: i am thinking if i should create a temp space and reallocated the memory againa dn stores it back in.
yes, that is the way to go. But there is a function to do that for you:
Use realloc()
To double the size use
pPerson = realloc( pPerson, 2*count);
pPerson would be changed - be sure to not hold any pointers to the old location.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
so reallocate would do the work of allocating the new memory i want to use for me? what about the old one do i need to free the memory myself?
also would the reallocated memory contain my old infomation or do i still have to store it away into a temp and put it back?
|
|
|
|
|
Hey, you definitely need to read a book on C ("Brian W. Kernighan, Dennis Ritchie: The C programming language" comes to mind) and MSDN!
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
i read some tutorial on c programming but i wanted to apply dynamic memory allocation on struct rather then string array as i think it is more useful that way.
i guess that dynamic memory array is eassier to learn and maybe i should not jump stright into learning how to do dynamic memory allocation on struct so soon.
|
|
|
|
|
neodeaths wrote: maybe i should not jump stright into dynamic memory allocation
Maybe.
But in the meantime, just using the information at your fingertips (MS ad in the nineties, shortly after Bill Gates had invented the internet) would suffice:
Look up what MSDN[^] says about realloc[^].
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
thanks for your help and all those who bothered to read my question i think it will really helpme in my progress of learning
|
|
|
|
|
neodeaths wrote: so reallocate would do the work of allocating the new memory i want to use for me?
Yes.
neodeaths wrote: what about the old one do i need to free the memory myself?
No.
neodeaths wrote: also would the reallocated memory contain my old infomation...
Yes.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i was just wondering this:
if i wanted to find the size of the array which is pointed by the pointer for my struct.
how should i go about it?
as you see i tryed the .lenght and sizeof() how ever it keep returning the size of the pointer instead of the array.
the purpose i am trying to do this is because i figured that if i am gonna manipulate the memory during runtime, finding out the size of the array while Only the array infomation would be useful.
please help with this question thx.
|
|
|
|
|
neodeaths wrote: if i wanted to find the size of the array which is pointed by the pointer for my struct.
how should i go about it?
Keep that number in a global variable of some sort.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
yes i know that but i am just checking if there is a way to find the memory size of the whole array pointer?
if i could i could probably do a array_mem_size/sizeof(struct people)
|
|
|
|
|
neodeaths wrote: if i could i could probably do a array_mem_size/sizeof(struct people)
This would only work for stack-based memory, not heap-based memory allocated with malloc() .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
by the way i realise something wielrd when i i malloc to make the array have a size of 10.
and i try to access the 15th array by hardcoding the program still works do you know y?
|
|
|
|