Trapping for checkbox events in CTreeCtrl's
I found an article on MSDN about this and was wondering if any of you know of a better way.
I have a CTreeCtrl with checkboxes for each node. The idea is to trap for the checkbox click event. MSDN makes it sound as if I must trap for this in the main message handler for the window. They show code that traps the WM_NOTIFY message, hit tests the mouse position and verifies the message came from the tree control. Then they test the flags of the TVHITTESTINFO structure to see if the TVHT_ONITEMSTATEICON bit is set. Once it is they post a user defined message to the window indicating a click on the checkbox. The window then has code to handle the user message and acts accordingly.
What a mess eh?
Is there a better way? Based on the pure Win32 example from MS I will have quite a bit of work to do in order to get this to work in MFC. I would have to make use of PreTranslateMessage to trap for the WM_NOTIFY and then verify the message came from my tree control. I would then need code in the same function to then call the handler for the user defined message. I've attached a screenshot of my app so you can understand what I'm using this control for. I used to use a simple list box but checking which layers are visible and which ones are not seems a lot more intuitive than a simple list of the layers. Ideally the check event would enable or disable the desired layer in my view on the right.