>>>> It is very easy to mess things up when you begin handling individual events in a tree control.
That is true though it must not happen. In the last years I saw at least 5 implementations of a class derived from CListCtrl which uses the usual way via parent notification for handling the double-click and not doing it in PreTranslateMessage.
The problem (and benefit) of handling events in PreTranslateMessage is that it is a very early time where you would get the trigger (only catching mouse events would be earlier) but - as the name says - where the design only had intended a *translation* and not a handling. If you catch the WM_LBUTTONDBLCLK in PreTranslateMessage the function doesn't know more that a double-click happened somewhere at the list-control. You would need to find out by means of HitTest where the click actually happened and whether it is the situation where you want to prevent the collapsing. If so, you have to do all other actions the tree-control now would do automatically yourself, e. g. high-liting or selecting the current item. All these actions may cause other events to some other items what can produce the same mess of individual handling of events which you wanted to prevent. Also if double-clicking on an item should cause some further actions like showing additional informations or invoke a dialog you now must handle this in a very basic event handler. Of course you can do that calling virtual functions and other high-level and high-logic member function but you should never forget that after all actions you invoked you would return to the very basic PreTranslateMessage where you now stop any further handling of the current double-click by returning HANDLED=TRUE.
Generally, I admit that by overriding PreTranslateMessage you may have fast success where you may experience some more troubles when installing a normal double-click notification handler. But it is similar to virginity. You can loose it only once. If later you or others will derive again from the class and have a normal notification handler, they won't get notifications. And hopefully they will remember or find out that there is a PreTranslateMessage which is responsible for the abnormal behavior.
Main Topics
Browse All Topics





by: DanRollinsPosted on 2009-11-08 at 01:31:08ID: 25769927
If you have derived from CTreeCtrl, then you should add a PreTranslateMessage() function and look for the WM_LBUTTONDBLCLK event. When it comes, return 1 (called "eating the event") to prevent normal handling.
>> but it collapses the node and won't allow it to expand after that!
It is very easy to mess things up when you begin handling individual events in a tree control. I suggest that you back off all changes -- until everything works normally. And then use the PreTranslateMessage trick I described.
An example of adding a PreTranslateMessage handler and eating an event is described in this article:
Use CHtmlEditCtrl to Create a Simple HTML Editor e.com/arti cles/Progr amming/Sys tem/ Window s__Program ming/Use-C HtmlEditCt rl-to-Crea te-a-Simpl e- HTML-Edi tor.html
http://www.experts-exchang