Click here to Skip to main content
Sign Up to vote bad
good
See more: VC6C++
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:52
Edited 6 Dec '12 - 21:53

Comments
Jochen Arndt - 7 Dec '12 - 4:20
What is the value of hRes? To get the handle of the edit control you can use GetComboBoxInfo().
sajeesh.c - 7 Dec '12 - 4:58
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:19
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().
sajeesh.c - 7 Dec '12 - 5:41
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:03
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().
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 330
2 Arun Vasu 253
3 Zoltán Zörgő 194
4 CPallini 173
0 Sergey Alexandrovich Kryukov 10,105
1 OriginalGriff 7,739
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 2,999


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