CTreeCtrl is not doing the business 
Author Message
 CTreeCtrl is not doing the business

All,

I'm using a tree control stuck in a CDialogBar docked to the edge of my
frame window, and I'm intercepting two notifications: TVN_SELCHANGE and
NM_RCLICK. My problem is as follows:

Upon intercepting the NM_RCLICK notification, which I intend to use to
display a popup context menu for individual tree items, I find that the
control's perception of the selected item has not changed, even though the
selection has changed on screen. Thus, when I attempt to retrieve the item
rectangle so that I can display the menu at the right position, I get the
previous item, not the new one (and don't even ask me how {*filter*}GetItemRect()
seems to be). My questions are therefore:

1. How do I get a right click selection change to register a TVN_SELCHANGE
BEFORE a NM_RCLICK comes in?

2. Does CTreeCtrl->GetItemRect() work properly (it seems to always return a
rect.left of 0)?

3. Are there better ways of doing this?



Sun, 18 Mar 2001 03:00:00 GMT  
 CTreeCtrl is not doing the business
No probs, found the solution further down the messages using HitTest().
Cheers!


Sun, 18 Mar 2001 03:00:00 GMT  
 CTreeCtrl is not doing the business
I've done the same thing in the following way, and it works fine:

void CAlsTreeDlg::OnRclickAlstree(NMHDR* pNMHDR, LRESULT* pResult)
{
 *pResult = 0;
 // TODO: Add your control notification handler code here
   UINT      nFlags;
   CPoint    curPoint;
   HTREEITEM  rightButtonItemP;

   GetCursorPos (&curPoint);
   // alsTree is a member varibale of the class containing a pointer to
   // the tree control
   alsTree->ScreenToClient (&curPoint);
   rightButtonItemP = alsTree->HitTest (curPoint, &nFlags);

   if (rightButtonItemP != NULL)
   {
      RECT itemRect;
      if (alsTree->GetItemRect (rightButtonItemP, &itemRect, TRUE))
      {
         CMenu treePopup;
         alsTree->ClientToScreen (&itemRect);
         treePopup.LoadMenu (IDR_TREEPOPUP);
         treePopup.GetSubMenu(0)->TrackPopupMenu (TPM_LEFTALIGN,
itemRect.right, itemRect.top, this);
         treePopup.DestroyMenu ();
      }
   }

Quote:
}

The problem is, that the selection changes AFTER processing the right mouse
click.
I've found this suggestion somewhere in the online help.

Hope this helps.
--
Dirk Bohnemeyer
p.s. For e-mail remove one of the 'o's from my address.
-------------------------------------------------------

Quote:
>All,

>I'm using a tree control stuck in a CDialogBar docked to the edge of my
>frame window, and I'm intercepting two notifications: TVN_SELCHANGE and
>NM_RCLICK. My problem is as follows:

>Upon intercepting the NM_RCLICK notification, which I intend to use to
>display a popup context menu for individual tree items, I find that the
>control's perception of the selected item has not changed, even though the
>selection has changed on screen. Thus, when I attempt to retrieve the item
>rectangle so that I can display the menu at the right position, I get the
>previous item, not the new one (and don't even ask me how {*filter*}
GetItemRect()
>seems to be). My questions are therefore:

>1. How do I get a right click selection change to register a TVN_SELCHANGE
>BEFORE a NM_RCLICK comes in?

>2. Does CTreeCtrl->GetItemRect() work properly (it seems to always return a
>rect.left of 0)?

>3. Are there better ways of doing this?



Sun, 18 Mar 2001 03:00:00 GMT  
 CTreeCtrl is not doing the business

Quote:
>The problem is, that the selection changes AFTER processing the right mouse
>click.
>I've found this suggestion somewhere in the online help.

Yes that is the only remaining problem now. Anybody got any solutions?

Thanks Dirk.



Sun, 18 Mar 2001 03:00:00 GMT  
 CTreeCtrl is not doing the business
You can change the selection yourself to the entry pre-selected by the right
mouse button.
Taking the code of my last example you only have to add
   alsTree->SelectItem (rightButtonItemP);

--
Dirk Bohnemeyer
p.s. For e-mail remove one of the 'o's from my address.
-------------------------------------------------------

Quote:
>>The problem is, that the selection changes AFTER processing the right
mouse
>>click.
>>I've found this suggestion somewhere in the online help.

>Yes that is the only remaining problem now. Anybody got any solutions?

>Thanks Dirk.



Sun, 18 Mar 2001 03:00:00 GMT  
 CTreeCtrl is not doing the business
As you've noticed, but apparently not accepted, right clicking on an item in
a tree control does not change the selection.  You should display the
context menu for the item you got back from the hit test, not the item that
is selected.

Quote:

>>The problem is, that the selection changes AFTER processing the right
mouse
>>click.
>>I've found this suggestion somewhere in the online help.

>Yes that is the only remaining problem now. Anybody got any solutions?



Sun, 18 Mar 2001 03:00:00 GMT  
 CTreeCtrl is not doing the business
Thanks all - all problems resolved with a mixture of things from different
people.

Cheerio.



Mon, 19 Mar 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Business To Business

2. System.Threading.Timer , am I doing this correctly ?

3. Wot am I doing rong??

4. Am I doing this right?

5. what am i doing wrong?

6. what am I doing wrong here?

7. What am I doing wrong?

8. What am I doing wrong?

9. WHAT AM I DOING WRONG?

10. what am i doing wrong!

11. What am I doing wrong (part 2)

12. What am i doing wrong?

 

 
Powered by phpBB® Forum Software