|
when user click on item of Tree view. for example 3th item: how do i get (3) numeral index this item?
Zo.Naderi-Iran
|
|
|
|
|
You don't. A Tree does not have or use an index. Even if it had, the moment an item gets removed or added, any stored index values would all be invalidated - so you cannot store an index and hope to later retrieve the correct item through that index, because it might no longer be valid!
The HTREEITEM value you get is what is generally called a 'handle'. It serves as a reference to the actual item, and it will remain valid until this child item is removed from the tree. You should use that handle and retrieve the child item, using HTREEITEM GetChildItem(HTREEITEM hItem) const; (see http://msdn.microsoft.com/en-US/library/yk3ystd6%28v=VS.80%29.aspx[^]).
|
|
|
|
|
Why you need the actual "position" (I assume that's what you want) ?
Assuming you want the position in regards with the parent node
parent
- node1
- node2
- node3
- node4
Anyway, a suggestion :
CTreeCtrl::GetParent of selected node and then use CTreeCtrl::GetChildItem and CTreeCtrl::GetNextSiblingItem (or other similar member) in a loop to get the next item; just count.
Watched code never compiles.
|
|
|
|
|
Good idea, and it actually answers the question - but I wonder whether that's what he (or she) actually needs
|
|
|
|
|
Wouldn't calling GetPrevSiblingItem[^] to walk "upwards" until it returns no more items and counting that work?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
probably.
Watched code never compiles.
|
|
|
|
|
zon_cpp wrote: for example: user selects 3th item of CTreeCtrl.
3rd item relative to what?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
One way: you can pass index in LPARAM lParam argument when inserting items
in treeview; then use GetSelectedItem to get handle to selected tree item
and get it index with CTreeCtrl::GetItem .
HTREEITEM hItem = m_treeFeature.GetSelectedItem();
TVITEM tvItem = {0};
tvItem.mask = TVIF_PARAM;
tvItem.hItem = hItem;
m_treeFeature.GetItem(&tvItem);
int nindex = (int)tvItem.lParam;
HTREEITEM GetSelectedItem( )
http://msdn.microsoft.com/en-us/library/xw6h5d91(v=vs.80).aspx[^]
|
|
|
|
|
In my MFC application i am using CRichEdit control for multiline text.
I have set the below properties for the rich edit control.
ES_MULTILINE | ES_NOHIDESEL | ES_READONLY | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,WS_EX_CLIENTEDGE | WS_EX_STATICEDGE
Vertical and Horizontal Scrollbar appears automatically when the text entered is more than the display area. This is working as expected.
I am having one clear button in my application which is to clear the text in rich edit control. But when i click the clear button vertical scrollbar disappears but the horizantal scrollbar is not disappearing.
Can anyone help me out in this? .
|
|
|
|
|
I have already responded to this question here[^]. Please do not post in multiple forums.
|
|
|
|
|
Hi!
how do i select 3th item of a CTreeCtrl?
SelectItem() function needs HTREEITEM of specified item, but i have index of item (for example 3th item)
please help me...
Zo.Naderi-Iran
|
|
|
|
|
It's not possible to access nodes by index. You must know the handle of the node. If you don't have records of the node handles, you can parse the tree:
HTREEITEM hRoot = myTree.GetRootItem();
HTREEITEM hChild1 = myTree.GetChildItem(hRoot);
HTREEITEM hChild2 = myTree.GetNextSiblingItem(hChild1)
HTREEITEM hChild3 = myTree.GetNextSiblingItem(hChild2)
|
|
|
|
|
You could do something like this:
HTREEITEM ItemFromIndex(int index)
{
HTREEITEM item = m_tree.GetRootItem();
while (item != NULL && index > 0)
{
item = NextTreeItem(item);
--index;
}
return item;
}
HTREEITEM NextTreeItem(HTREEITEM hStartItem)
{
HTREEITEM hItem = hStartItem;
if (m_tree.ItemHasChildren(hItem))
{
HTREEITEM hChildItem = m_tree.GetChildItem(hItem);
hItem = hChildItem;
}
else
{
bool foundSibling = false;
while (!foundSibling && hItem != NULL)
{
HTREEITEM hSiblingItem = m_tree.GetNextItem(hItem, TVGN_NEXT);
if (hSiblingItem != NULL)
{
hItem = hSiblingItem;
foundSibling = true;
}
else
{
hItem = m_tree.GetParentItem(hItem);
}
}
}
return hItem;
}
Som eof this was written from memory, other sections are code pasts, so take with a pinch of salt.
If you vote me down, my score will only get lower
|
|
|
|
|
Hi all,
I am looking to work on with PIC/Embedded Systems in C/C++. So I just want to find some resources in two aspect.
1. Books, tutorials where i can take a start
2. Development environment (and simulators, real PICs, etc)
Thanks
I appreciate your help all the time...
CodingLover
|
|
|
|
|
|
Wow, it's awesome. Prettymuch all is their in your post. Thanks.
One more thing here too. I have just start to use MPLAB. Seems ok so far, and I'm writing a sample on it. But seems to me the results deals with the simulated environment. Is there anyway to deals with devices such as real PICs, LEDs and so on.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
|
I think I can take a start with PicSimLab. Last night I tried a sample code with it and works fine.
Once I have confidence with PIC programming I'll buy some stuff.
Thanks for the link too.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
WOW! Someone's done this before...
|
|
|
|
|
|
Thanks for sharing with me all of these.
However since I am new to PIC programming, it is better to move with some emulators. Honestly I cannot spend a lot at this moment for these stuff.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi,
I have a Dialog based application, to transfer a file I am using a thread (say T1).
If I need to abort the T1 I need to press cancel button, for abort process I am using a memeber variable (bStopPushThread ) as a flag. If I set it ture it comes out of T1.
But my application getting hang. Code on Abort button click is below:
if(g_hThreadHandlePush)
{
m_bStopPushThread = true;
WaitForSingleObject(g_hThreadHandlePush,INFINITE);
CloseHandle(g_hThreadHandlePush);
}
But It I dont use WaitForSingleObject(), it wirk fine, T1 treminates.
I can check using debug..
If I use WaitForSingleObject as pointer come on this statement application hangs and I even cant check the T1.
Please suggest me solition.
|
|
|
|
|
Could you also post the code of the thread in which the m_bStopPushThread variable is accessed ?
|
|
|
|
|
Are you completely sure g_hThreadHandlePush is the handle of the thread that checks the flag?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
This is exactly what I was thinking... +5
|
|
|
|