链接:Enable Auto-complete on Your Edit Controls in VC++
Auto-complete edit and combo, without Platform SDK
一. 静态链接 - (注:需要 IE5 以上)。
Here's an example:
#include <shlwapi.h> #include <ole2.h> #pragma comment (lib, "shlwapi.lib") LRESULT CALLBACK MyDialogProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: HWND hFilePath; CoInitialize (NULL); hFilePath = GetDlgItem (hWnd, ID_FILEPATH); SHAutoComplete (hFilePath, SHACF_DEFAULT); break; case WM_DESTROY: CoUninitialize(); PostQuitMessage (0); break; } }
二. 动态调用:
The wrapper function.
// 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 0x80000000typedef 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; }
调用:
BOOL CMyDialog::OnInitDialog()
{
...
// enable auto complete for m_myEdit
SetupForAutoComplete(m_myEdit.m_hWnd,
SHACF_FILESYSTEM);
...
}