SHAutoComplete API返回失败 [英] SHAutoComplete API return fail
问题描述
我想将自动完成属性设置为我的Combobox。对于那个iam使用windows的SHAutoComplete API。我知道这个api用于指示系统编辑控件使用AutoComplete来帮助完成URL或文件系统路径。要将自动完成设置为combbox,iam使用组合框内的编辑控件具有控件ID 1001.使用带有此ID的GetDlgItem()函数来获取编辑控件的句柄。代码部分如下。
I want to set Auto complete property to my Combobox. For that iam use SHAutoComplete API of windows.I know this api is used for Instructs system edit controls to use AutoComplete to help complete URLs or file system paths. To set autocomplete to combbox, iam use edit control inside the combobox has a control ID 1001. Use the GetDlgItem() function with this ID to get the handle of the edit control. the code section is below.
BOOL CAutocompleteDlg::OnInitDialog()
{
CWnd* pEditCombo = m_Combo.GetDlgItem( 1001 );
if( pEditCombo )
{
HRESULT hRes = SHAutoComplete( pEditCombo->m_hWnd, SHACF_FILESYSTEM );
if( S_OK != hRes )
{
AfxMessageBox( _T( "Failed" ));
}
}
return TRUE;
}
这里m_Combo是CComboBox的对象。但是当执行程序时SHAutoComplete API返回失败。为什么?
here m_Combo is the object of CComboBox. But when execute the program SHAutoComplete API return fail. why?
推荐答案
评论部分的讨论导致了解决方案:
一个常见的错误是忘记调用CoInitialize()
,OleInitialize()
,或AfxOleInit()
。其中一个必须在使用COM库中的函数之前调用,如SHAutoComplete()
。
The discussion from the comments section leads to the solution:
A common error is forgetting to callCoInitialize()
,OleInitialize()
, orAfxOleInit()
. One of these must be called before using functions from COM libraries likeSHAutoComplete()
.
这篇关于SHAutoComplete API返回失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!