使用 IEnumString 的 IAutoComplete 自定义源

发布于 2024-12-09 22:36:34 字数 360 浏览 1 评论 0原文

我正在尝试为组合框(win32,c++)或编辑控件实现自动建议。但我不知道如何正确使用IAutoComplete接口。我需要一个自定义字符串列表,应从中获取自动建议的匹配项。但是如何用 IEnumString 来实现呢?我找到了此链接,但它并未显示所有内容: http://msdn.microsoft.com/en-us/library/windows/desktop/hh127437%28v=vs.85%29.aspx

有人曾经实现过这个吗? 提前谢谢 迈克尔

I am trying to implement auto-suggest for a comboxbox (win32, c++) or an edit-control. But I dont know how to use the interface IAutoComplete correctly. I need a custom list of strings where the matches for auto-suggest should be taken from. But how to implement this with IEnumString? I found this link but it doesnt reveal everything: http://msdn.microsoft.com/en-us/library/windows/desktop/hh127437%28v=vs.85%29.aspx

Has anybody ever implemented this?
Thx in advance
Michael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里的微风 2024-12-16 22:36:34

正如我在评论中指出的,ATL 已经为您预先编写了一份。

typedef CComEnum<IEnumString,
                 &IID_IEnumString,
                 LPOLESTR,
                 _Copy<LPOLESTR> > CComEnumString;

CComObject<CComEnumString> *pes;
HRESULT hr = CComObject<CComEnumString>::CreateInstance(&pes);

该代码基本上是从CComEnum 文档。

As I noted in my comment, ATL has one pre-written for you.

typedef CComEnum<IEnumString,
                 &IID_IEnumString,
                 LPOLESTR,
                 _Copy<LPOLESTR> > CComEnumString;

CComObject<CComEnumString> *pes;
HRESULT hr = CComObject<CComEnumString>::CreateInstance(&pes);

That code was basically stolen from the CComEnum documentation.

旧瑾黎汐 2024-12-16 22:36:34

好的,在所有答案的帮助下,我到目前为止得到了它:

            IAutoComplete *pac;

        HRESULT hr = CoCreateInstance(CLSID_AutoComplete, 
                                        NULL, 
                                      CLSCTX_INPROC_SERVER,
                                      IID_PPV_ARGS(&pac));

        typedef CComEnum<IEnumString,
             &IID_IEnumString,
             LPOLESTR,
             _Copy<LPOLESTR> > CComEnumString;

        CComObject<CComEnumString> *pes;
        HRESULT hRes = CComObject<CComEnumString>::CreateInstance(&pes);

        // hRes = pes->Init(

        IUnknown* pUnk;
        hRes = pes->QueryInterface(IID_IEnumString, (void**) &pUnk);

        pac->Init(hEdit, pUnk, NULL, NULL);

        // maybe we release ?
        pUnk->Release();

        IAutoComplete2 *pac2;

        if (SUCCEEDED(pac->QueryInterface(IID_IAutoComplete2, (LPVOID*)&pac2)))
        {
            pac2->SetOptions(ACO_AUTOSUGGEST);
            pac2->Release();
        }

只剩下一件事:

CComObject *pes 的初始化。假设我有一个像这样的数组:

std::string myArray[] = { string("abc"), string("foo"), string("muh") };

现在我希望将这些字符串填充到 pes->Init(...) 方法中。这里实际上是如何转换为 LPOLESTR 的? Init(...) 方法包含一个指向该数组的开头和结尾的指针。结尾应该是最后一个数组元素之外的一个位置,那么这里是 myArray[3] 吗?我只是问,因为我认为这实际上超出了这个数组的范围?

非常感谢!

Ok, with the help of all answers I got it so far:

            IAutoComplete *pac;

        HRESULT hr = CoCreateInstance(CLSID_AutoComplete, 
                                        NULL, 
                                      CLSCTX_INPROC_SERVER,
                                      IID_PPV_ARGS(&pac));

        typedef CComEnum<IEnumString,
             &IID_IEnumString,
             LPOLESTR,
             _Copy<LPOLESTR> > CComEnumString;

        CComObject<CComEnumString> *pes;
        HRESULT hRes = CComObject<CComEnumString>::CreateInstance(&pes);

        // hRes = pes->Init(

        IUnknown* pUnk;
        hRes = pes->QueryInterface(IID_IEnumString, (void**) &pUnk);

        pac->Init(hEdit, pUnk, NULL, NULL);

        // maybe we release ?
        pUnk->Release();

        IAutoComplete2 *pac2;

        if (SUCCEEDED(pac->QueryInterface(IID_IAutoComplete2, (LPVOID*)&pac2)))
        {
            pac2->SetOptions(ACO_AUTOSUGGEST);
            pac2->Release();
        }

There is just one thing remaining:

The initialisation of the CComObject *pes. Lets assume I have an array like this:

std::string myArray[] = { string("abc"), string("foo"), string("muh") };

Now I want these strings to be stuffed into the pes->Init(...) method. How is the conversion to LPOLESTR actually done here? The Init(...) method taes a pointer to the begin and end of this array. The end should be one position BEYOND the last array element, so would this be myArray[3] here? I am just asking because I think this is actually out of bounds in this array?

Thx very much!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文