我正在使用带有SHACF_FILESYSTEM选项的SHAutoComplete。问题是,相对于当前工作目录的文件未自动完成。没有关于相对路径的建议 - 例如,工作目录包含settings.txt,但我可以键入"设置"进入编辑,没有出现。
是否有相对简单的解决方案?或者我是否必须使用自己的查找覆盖自动完成行为?
提前谢谢!
答案 0 :(得分:2)
请查看以下文档: http://msdn.microsoft.com/en-us/library/bb776884
您需要明确指定“当前目录”作为选项。这必须通过IACList2 :: SetOptions http://msdn.microsoft.com/en-us/library/windows/desktop/bb776376
来完成==>您必须使用COM接口来设置所需的选项...以下是一个示例:
HRESULT EnableAutoComplete(HWND hWndEdit, LPWSTR szCurrentWorkingDirectory = NULL, AUTOCOMPLETELISTOPTIONS acloOptions = ACLO_NONE, AUTOCOMPLETEOPTIONS acoOptions = ACO_AUTOSUGGEST, REFCLSID clsid = CLSID_ACListISF)
{
IAutoComplete *pac;
HRESULT hr = CoCreateInstance(CLSID_AutoComplete,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pac));
if (FAILED(hr))
{
return hr;
}
IUnknown *punkSource;
hr = CoCreateInstance(clsid,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&punkSource));
if (FAILED(hr))
{
pac->Release();
return hr;
}
if ( (acloOptions != ACLO_NONE) || (szCurrentWorkingDirectory != NULL) )
{
IACList2 *pal2;
hr = punkSource->QueryInterface(IID_PPV_ARGS(&pal2));
if (SUCCEEDED(hr))
{
if (acloOptions != ACLO_NONE)
{
hr = pal2->SetOptions(acloOptions);
}
if (szCurrentWorkingDirectory != NULL)
{
ICurrentWorkingDirectory *pcwd;
hr = pal2->QueryInterface(IID_PPV_ARGS(&pcwd));
if (SUCCEEDED(hr))
{
hr = pcwd->SetDirectory(szCurrentWorkingDirectory);
pcwd->Release();
}
}
pal2->Release();
}
}
hr = pac->Init(hWndEdit, punkSource, NULL, NULL);
if (acoOptions != ACO_NONE)
{
IAutoComplete2 *pac2;
hr = pac->QueryInterface(IID_PPV_ARGS(&pac2));
if (SUCCEEDED(hr))
{
hr = pac2->SetOptions(acoOptions);
pac2->Release();
}
}
punkSource->Release();
pac->Release();
}
您可以通过以下方式致电:
wchar_t szCurDir[MAX_PATH];
GetCurrentDirectoryW(MAX_PATH, szCurDir);
EnableAutoComplete(m_txtBox1.m_hWnd, szCurDir, ACLO_CURRENTDIR);