Solved

How get a checked/unchecked message from CTreeCtrl?

Posted on 2004-03-25
6
795 Views
Last Modified: 2013-11-20
How do I determine when the user is un/cheking a check box in a
 tree. What  notification message is sent?

0
Comment
Question by:robter_x
6 Comments
 
LVL 16

Accepted Solution

by:
nonubik earned 50 total points
ID: 10686858
I presume you use a CTreeCtrl with TVS_CHECKBOXES.
I couldn't find any standard notification message, but I have an workarround: you may wait NM_CLICK and verify wether the checkbos is checked or not  (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/treeview/treeview.asp ,the last example in "Working with state image indexes") .
0
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 14541570
I know it must be way too late now, but anyway, for the knowledgebase:
There is a better way - derive a class from CTreeCtrl and override with this one:

void CTreeCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
{
      UINT uFlags=0;
      HTREEITEM hItem = HitTest(point,&uFlags);

      if( uFlags & TVHT_ONITEMSTATEICON )
      {
            AfxMessageBox("Checked/unchecked");
            // determine by using GetCheck(hItem)
            // you can send a custom message if you want.
            return;
      }

      CTreeCtrl::OnLButtonDown(nFlags, point);
}

Stilgar.
0
 
LVL 1

Expert Comment

by:thready
ID: 21309279
Hi Stilgar,

I was just looking over these responses - it's been a long time, but maybe you can remember...  I subclassed CTreeCtrl and provided the virtual function to override OnLButtonDown as you said to do, but my function is not being called.  Do I absolutely need a message map so that it is called?  I'm not sure what to use as a message map if that's the case - how do you determine which dialog ID to use and still have a generic class?

Thanks for your help,
Mike
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 14

Expert Comment

by:_Stilgar_
ID: 21316759
Hi,

Its been a while since I touched MFC GUI controls... AFAIR just overriding the function should do, but I may as well be wrong. Try creating the OnLButtonDown function in your sub-class using the MFC wizards - this should create whatever is needed for this function to work. Also, make sure you're not overriding this message elsewhere (for example in PreTranslateMessage).

Stilgar.
0
 
LVL 1

Expert Comment

by:thready
ID: 21318011
Thanks Stilgar, I'll give that a try..
0
 
LVL 1

Expert Comment

by:rkursem
ID: 33074356
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 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