Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 C++
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 22:52pm
Edited 6-Dec-12 22:53pm
v2
Comments
Jochen Arndt at 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 at 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 at 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
good
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().
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 325
1 Sergey Alexandrovich Kryukov 133
2 Rana Waqas 105
3 Sebastiaan Meijerink 105
4 Abhinav S 99
0 Sergey Alexandrovich Kryukov 6,558
1 OriginalGriff 6,268
2 Peter Leow 2,534
3 Abhinav S 2,344
4 Maciej Los 2,297


Advertise | Privacy | Mobile
Web02 | 2.8.150414.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2015
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