Gold mine of Visual C++ tricks!
How to enable Auto Completion for Editboxes?
![]()
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.
| Print article | This entry was posted by Jijo Raj on April 15, 2008 at 1:10 pm, and is filed under Codeproject, MFC. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |









