I tested this in one of my sandbox MFC apps and confirmed this result.
If an item is selected in an editable combobox, the next time the combobox recieves a windowsposchanging message, it sends out a select text windows message which selects all the text.
Getting and selecting window text from edit in an editable combobox is unreliable, so we instead add an item and select it to change the combobox's text, which reacts the same way as the user selecting an item. Next time everything is recalculated on a move, SetWindowPos causes the edit text to be selected.
Overriding WindowPosChanging message has weird results, because combobox actually ignores setting it's height. What it does with the height value is subtract what it calculates its height should be开发者_开发知识库 (based on font size), and uses the remainder for the dropdown listbox's height. Why there isn't a set dropdown height method is beyond me.
So the only thing I can think of is have a member flag that overrides the seltext message and does nothing if the flag is set, but that's a horrible solution.
Any advice on how to prevent the text selection?
This is easy to do. You need to subclass the Edit box owned by the combo box, not the combo box itself. As Mark said, you can get this by calling GetComboBoxInfo and using the hwndItem field. Then you can intercept EM_SETSEL.
精彩评论