|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionHere's a quick article that shows how you can add the handy auto-completion effect that you see in the Win2K file-open dialog for your own edits and combo boxes - without having to download the entire Platform SDK (9 hours on a 56K modem!). If you already have the Platform SDK, this article is probably useless to you. DemoI'm not providing any demo project here, the code is small enough that you can just copy and paste (one function!). Some constantsThese would be defined in the Platform SDK, but since we're not using that, I'll include these here. You'll have to copy these to your app. // See the MSDN for SHAutoComplete for a full // description of what these options do. #define SHACF_DEFAULT 0x00000000 #define SHACF_FILESYSTEM 0x00000001 #define SHACF_URLALL (SHACF_URLHISTORY | SHACF_URLMRU) #define SHACF_URLHISTORY 0x00000002 #define SHACF_URLMRU 0x00000004 #define SHACF_USETAB 0x00000008 #define SHACF_FILESYS_ONLY 0x00000010 #define SHACF_AUTOSUGGEST_FORCE_ON 0x10000000 #define SHACF_AUTOSUGGEST_FORCE_OFF 0x20000000 #define SHACF_AUTOAPPEND_FORCE_ON 0x40000000 #define SHACF_AUTOAPPEND_FORCE_OFF 0x80000000 The simple wrapper functiontypedef HRESULT (WINAPI *SHAUTOCOMPLETEFN) (HWND hTarget, DWORD dwFlags); static HINSTANCE hSHLWAPIDLL = NULL; bool SetupForAutoComplete(HWND hTarget, DWORD dwFlags) { if (hTarget == NULL) { return false; } bool ok = false; if (hSHLWAPIDLL == NULL) { hSHLWAPIDLL= LoadLibrary("SHLWAPI.DLL"); if (hSHLWAPIDLL== NULL) { return false; } } SHAUTOCOMPLETEFN pSHAC = (SHAUTOCOMPLETEFN)GetProcAddress(hSHLWAPIDLL, "SHAutoComplete"); if (pSHAC != NULL) { ok = SUCCEEDED(pSHAC(hTarget, dwFlags)); } return ok; } Using it
First, make sure you've called
I'd also recommend that you call Now the good stuffIf you have an an edit control in your dialog class that's hooked up to a member variable, all you have to do is: BOOL CMyDialog::OnInitDialog()
{
...
// enable auto complete for m_myEdit
SetupForAutoComplete(m_myEdit.m_hWnd,
SHACF_FILESYSTEM);
...
}
And that's it. Now, when you start typing a path, the edit control will drop down a list box with paths that match what you've typed so far - just like the file open dialog. If you want to do this to a combo box, it's slightly more complicated: BOOL CMyDialog::OnInitDialog()
{
...
// the edit control of a CComboBox is always at dlg ID 1001
CEdit * pMyEdit = (CEdit *)m_myCombo.GetDlgItem(1001);
if (pMyEdit)
{
// enable auto complete for m_myCombo
SetupForAutoComplete(pMyEdit->m_hWnd, SHACF_FILESYSTEM);
}
...
}
And that's that. Concerns
The heart of this whole thing is More info
And that's that. Enjoy responsibly. Oh yeah, thanks Michael Dunn, for your invaluable input :)
|
||||||||||||||||||||||