How to enable Auto Completion for Editboxes?

15 04 2008


In windows, we experience auto completion in several places such as URL auto completion in Internet Explorer address bar, File path auto completion in Run dialog etc. You can enable auto completion in editboxes or comboboxes of your application too.


Use the shell function – SHAutoComplete() to enable the auto completion feature for any edit boxes. Please see the following code snippet for how to use it.

#include "objbase.h"
#include "Shlwapi.h"

...

// Initialize COM.
::CoInitialize(0);

// Get the window handle.
// For time being, i took it from a ctrl variable.
HWND hEditWnd = m_EditCtrl.GetSafeHwnd();

// Enable Auto completion.
::SHAutoComplete( hEditWnd, SHACF_DEFAULT );


Both File path and URL auto completion will be enabled by default. If you want any one of these, just use – SHACF_FILESYSTEM or SHACF_URLALL appropriately. Have a look at MSDN for other useful flags.

Don’t forget to add library – Shlwapi.lib to your project settings.


Targeted Audience – Beginners.