INTRODUCTION AND RELEVANT INFORMATION:
I need to implement the following scenario:
1. User expands a node, e.g.
Node 1
;
2. User expands another node, e.g.
Node 2
;
3. Collapse previous node (
Node 1
);
To visually explain what I mean, we shall use the following
example image[
^].
Now when user clicks on
Assembly 1
node or its child node
Components
, I need to collapse every other node. Example of what I mean is illustrated
here[
^].
MY EFFORTS TO IMPLEMENT THIS BEHAVIOR:
Browsing through Internet, and with a little thinking of my own, I was able to write helper function that collapses node and its children :
void CollapseNode( HWND hTree, HTREEITEM hti )
{
if( TreeView_GetChild( hTree, hti ) != NULL )
{
TreeView_Expand( hTree, hti, TVE_COLLAPSE );
hti = TreeView_GetChild( hTree, hti );
do
{
CollapseNode( hTree, hti );
}
while( ( hti = TreeView_GetNextSibling( hTree, hti ) ) != NULL );
}
}
Reading through
MSDN documentation I found
TVN_ITEMEXPANDING
and
TVN_ITEMEXPANDED
messages that might be useful.
I have also found
NM_CLICK
notification that seems interesting since I can use
TVM_HITTEST
message to test if click was on
+/- button.
Also I have found
TVN_KEYDOWN
message that will help me with expanding when user presses
left arrow or
right arrow keys.
PROBLEM:
I can not think of an algorithm for using the above messages to solve my task.
QUESTION:
Can you please suggest me an algorithm for handling the above messages so I can call my
CollapseNode(..)
function ?
Something like this:
Hittest in NM_CLICK
and then call your function or
Store the last expanded item in a variable and collapse it in response to TVN_ITEMEXPANDED
would be good for a start.
Thank you.