Solved

Determining which hTreeItem's check box was clicked in CTreeCtrl

Posted on 2002-06-04
5
986 Views
Last Modified: 2013-11-20
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
Comment
Question by:Claude050897
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:mblat
ID: 7054355
Did you try to use HitTest after OnClick() ?
0
 
LVL 4

Accepted Solution

by:
mblat earned 200 total points
ID: 7054421
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
 
LVL 2

Expert Comment

by:venkaiah
ID: 7055666
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
 
LVL 2

Expert Comment

by:venkaiah
ID: 7055679
Hi Friend,
Write the following code in OnClick()
{
  HTREEITEM hItem = pmyTreeCtrl->GetSelectedItem();
}

0
 

Author Comment

by:Claude050897
ID: 7055727
Thanks! Did not know about GetMessagePos()

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

Thanks again!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 92
countEvens challenge 2 100
pre4 challenge 19 100
Problem to App 4 81
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question