2

I want to implement auto-complete in ComboBox. As the first step, when a user clicks on the edit box and before typing anything, it should show the drop-down list with all available choices.

void ...::OnCbnSetfocus()
{
    if (!GetDroppedState())
    {
        ShowDropDown(TRUE);
    }
}

One issue is that if user clicks the drop-down button, the drop-down list appears and quickly disappears. To address that I think I need to subclass ComboBox to intercept the "click drop-down button" event and not pass it along the chain. But after some searching, I don't seem to find what event it is.

Filburt
  • 17,626
  • 12
  • 64
  • 115
user180574
  • 5,681
  • 13
  • 53
  • 94
  • 3
    FYI, Windows has built-in support for auto-complete in a ComboBox, you don't need to implement it manually. Look at [Using Autocomplete](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/bb776884(v%3Dvs.85)) on MSDN. That being said, to solve your particular issue, you might consider using `PostMessage()` to delay your call to `ShowDropDown()` until after the focus change has fully completed and the control has processed the drop-down button click, if there is one. – Remy Lebeau Feb 03 '20 at 20:43
  • @RemyLebeau I don't quite understand how you are to use that with a `CComboBoxEx`. – Andrew Truckle Feb 04 '20 at 11:42
  • 1
    @and: The `CComboBoxEx` class doesn't provide a dedicated interface to attach an `IAutoComplete` source. You're just doing it the same way you would do it in plain Win32. – IInspectable Feb 04 '20 at 14:20
  • @AndrewTruckle the same way you do in Win32: get the ComboBox's HWND (via its `GetSafeHwnd()` method) and pass it to `SHAutoComplete()` or `IAutoComplete::Init()` – Remy Lebeau Feb 04 '20 at 15:40
  • 1
    That's not how you do it in Win32. You need to get the combo box' embedded edit control. With MFC you can call [CComboBox::GetComboBoxInfo](https://learn.microsoft.com/en-us/cpp/mfc/reference/ccombobox-class#getcomboboxinfo) to get its handle. – IInspectable Feb 04 '20 at 16:04
  • Pity there is not a worked example. Sounds interesting and I could make use of it. – Andrew Truckle Feb 04 '20 at 16:14

0 Answers0