Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C++
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;
}


here m_Combo is the object of CComboBox. But when execute the program SHAutoComplete API return fail. why?
Posted
Updated 6-Dec-12 21:53pm
v2
Comments
Jochen Arndt 7-Dec-12 4:20am    
What is the value of hRes?

To get the handle of the edit control you can use GetComboBoxInfo().
[no name] 7-Dec-12 4:58am    
I think API need some more information also. I also try GetComboBox info. stil it failed. Thanks for your reply
Jochen Arndt 7-Dec-12 5:19am    
The note about GetComboBoxInfo() was just a hint. It will not solve your problem.

To solve your problem, check the hRes value. It is an error code that will tell you what is wrong.

A common error is forgetting to call CoInitialize(), OleInitialize(), or AfxOleInit().
[no name] 7-Dec-12 5:41am    
thanks jochen. Actualy i forgot to call CoInitialize(). thanks..I think you can add it as a solution. Then it will be usefull for others. thank you very much
Jochen Arndt 7-Dec-12 6:03am    
Thank you for your feedback. I have added a solution. You may accept it to mark the question as solved.

1 solution

The discussion from the comments section leads to the solution:

A common error is forgetting to call CoInitialize(), OleInitialize(), or AfxOleInit(). One of these must be called before using functions from COM libraries like SHAutoComplete().
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900