• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1017
  • Last Modified:

Determining which hTreeItem's check box was clicked in CTreeCtrl

It seems that the only way to "catch" a check box click in a CTreeCtrl is to override the OnClick() method. The only problem is that it does not give you any info back as to whick hTree item's check box was clicked on.

Does anybody have an idea how this can be done?

I've read about the CCheckListBox control, which could probably also work, but it seems like such an effert to get it going.
0
Claude050897
Asked:
Claude050897
  • 2
  • 2
1 Solution
 
mblatCommented:
Did you try to use HitTest after OnClick() ?
0
 
mblatCommented:
This code seems to work:

#include "windowssx.h"

// handler of NM_CLICK message
CMyDlg::OnClickTree(......)
{
  DWORD dw = GetMessagePos();
  CPoint pt(GET_X_LPARAM(dw),GET_Y_LPARAM(dw));
  m_Tree.ScreenToClient(&pt);
 
  UINT flags;
  HTREEITEM hItem = m_Tree.HitTest(pt,&flags);
 
  if(hItem)
    TRACE("%s\n",m_Tree.GetItemText(hItem));

  *pResult = 0;
}

Couple notes:  m_Tree member var. represents tree in your dialog.
I didn't copy/paste, so typos is possible...

Hope it helps...
0
 
venkaiahCommented:
Hi Friend,
Write the following code in OnClick()
{
    POSITION pos=GetFirstSelectedItemPos();
    if(pos != NULL)
    {
    int nIndex=GetNextSelectedItem(pos);
    //This Index will tell u.which item u click
    }
}
0
 
venkaiahCommented:
Hi Friend,
Write the following code in OnClick()
{
  HTREEITEM hItem = pmyTreeCtrl->GetSelectedItem();
}

0
 
Claude050897Author Commented:
Thanks! Did not know about GetMessagePos()

The only typo in here is #include "windowsx.h" not #include "windowssx.h"

Thanks again!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now