Click here to Skip to main content
12,954,001 members (43,226 online)
Rate this:
Please Sign up or sign in to vote.
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.
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 6-Dec-12 21:52pm
Updated 6-Dec-12 21:53pm
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().
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().
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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().

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100