0

Is there any notification message for WinAPI combo box controls we can use to know when the current item is changed while moving the mouse pointer over the drop-down list box?

My expectation is that the CBN_SELCHANGE notification should work for the mouse too, but unfortunately it is sent only when we change the selection using the keyboard or click an item with the mouse.

TecMan
  • 2,743
  • 2
  • 30
  • 64
  • 1
    `CBN_SELCHANGE` is only posted, when a selection really changed. Moving the mouse over the drop-down list box merely changes transient state, to render items in the list. Why would you need to know about this implementation detail? (You can subclass a standard combo box control and handle mouse messages yourself, if you really, really, want to.). – IInspectable Sep 09 '15 at 08:53
  • @IInspectable, in the project I'm working on our combo boxes implement incremental search. And we need to cancel the search when the selection is changed while the pointer is moving over the drop-down list box. Currently we have a routine that processes WM_MOUSEMOVE and use CB_GETTOPINDEX to find the index of the item under the mouse pointer. But apparently there should be an easier way as the combo box control does that itself. – TecMan Sep 09 '15 at 09:44
  • Are you about to re-invent [Autocomplete](https://msdn.microsoft.com/en-us/library/windows/desktop/bb776884.aspx)? If so, consider using the system-provided implementation. – IInspectable Sep 09 '15 at 10:16
  • @IInspectable, we do not have the edit part of the combo box in our project. We exploit the drop-down part of the WinAPI combo to implement our customized editors for other controls like ListView. – TecMan Sep 09 '15 at 10:27
  • You don't need a combo box control to implement the Autocomplete feature. You only need an edit control. Don't you have an edit control overlay when entering edit mode in a ListView, for example? – IInspectable Sep 09 '15 at 10:31
  • @IInspectable, no. It works like a combo box in drop-down list mode only. This drop-down part is opened when the combo button is pressed in the parent control, and the user can select an item only from the list. – TecMan Sep 09 '15 at 10:39
  • 2
    The answer to your question is "no, there is no notification message for that". The solution is to sub-class and work it out yourself. – Jonathan Potter Sep 09 '15 at 23:08
  • @JonathanPotter, if you definitely know that there is no way to make it work as expected, then your comment should be an answer. I also came to a conclusion, that we should "do it ourselves". Thank you for your comment! – TecMan Sep 10 '15 at 05:41

1 Answers1

2

Listen for WM_DRAWITEM in your WndProc, and use the DRAWITEMSTRUCT to determine the selection.

theB
  • 6,450
  • 1
  • 28
  • 38
  • An interesting idea. In the general case it would work, but we need this only for the mouse-move event (see also my comment to IInspectable's comment). WM_DRAWITEM occurs every time when the corresponding items should be redrawn, but we don't need this logic for some keyboard commands. I doubt whether implementing this approach gets a benefit compared to our current technique based on WM_MOUSEMOVE/CB_GETTOPINDEX. – TecMan Sep 09 '15 at 09:55
  • @TecMan - You may want to add that information to your question. The question implies that you're currently using `CBN_SELCHANGE`, which is apparently not the case. – theB Sep 09 '15 at 11:40