Solved

How get a checked/unchecked message from CTreeCtrl?

Posted on 2004-03-25
6
788 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now