Tuesday, December 28, 2004

Microsoft Shell Lightweight API...

May not mean much to the average Windows Developer. More familiarly, it is the full name for the functions and COM objects exposed by shlwapi.dll.

It was for a time a real pain to use as it required Internet Explorer 5 on your machine and this resulted in laborious alternatives when coding for environments at clients that chose not to upgrade to IE5 (Luddites!).

I use it all the time and I am constantly surprised when I discover yet more useful stuff.

The latest revelation is SHAutoComplete().

Using this adds the same autocompletion functionality that is available in the system edit boxes e.g. run, IE address bar and Windows Explorer address bar.

All you need to do is call it passing in the HWND of the embedded edit for a system ComboBoxEx and flags with the options for which lists you want and how you want it to behave.

To get the embedded edit box's HWND you'll need to apply an incantation. The CBEM_GETEDITCONTROL message returns the HWND of the embedded edit control of a CComboBoxEx control, (of course it does).

    LRESULT lResult = ::SendMessage(                
                (HWND) m_comboAppPaths.m_hWnd,        
                (UINT) CBEM_GETEDITCONTROL,            
    SHAutoComplete((HWND)lResult, SHACF_DEFAULT);

No comments: