删除后CVSListBox通知

发布于 2024-07-09 20:59:14 字数 447 浏览 11 评论 0原文

我刚刚将新的(MFC 功能包)CVSListBox 控件之一添加到项目中。 控件中的项目列表由应用程序中的一些其他对象跟踪,因此当发生任何更改时,我需要从列表框中获取大量通知,以便我可以更新其他内容。 对于那些不了解该控件的人,有一个按钮栏提供基本的添加/删除/重新排序功能。

CVSListBox 控件提供了可重写的虚拟函数,用于添加或重命名项目以及更改其顺序 - 所有这些都运行良好。

然而,对于删除项目,唯一的替代是 OnBeforeRemoveItem,它在删除项目之前调用,并且必须返回 TRUE/FALSE 才能允许删除。 删除后,不会有任何具体通知。

删除后获取通知的最佳方式是什么?

显然,这里可能会发生一些可怕的事情,因为删除后将出现选择更改事件,并且可以保留删除前的标志来表示下一个选择更改是特殊的。 但我觉得我错过了一些更干净、更明显的东西。 有什么建议么?

I've just added one of the new (MFC Feature Pack) CVSListBox controls to a project. The list of items in the control is tracked by some other objects in my application, so I need to take lots of notifications from the list-box when anything changes so that I can update other stuff. For those that don't know the control, there is a button bar which offers basic add/delete/reorder functionality.

The CVSListBox control offers overridable virtual functions for things like adding or renaming items, and changing their order - all this works nicely.

However, for deleting items, the only override is OnBeforeRemoveItem, which is called BEFORE an item is removed, and from which one has to return TRUE/FALSE to permit the remove. Once the remove has occurred, there's no specific notification.

What's the best way to get notification AFTER a remove?

Obviously it's possible to hack something horrible here, in that there will be a selection-changed event after a remove, and it would be possible to hold a flag from the before-remove to say that the next selection-changed is special. But I feel like I'm missing something cleaner and more obvious. Any suggestions?

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

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

发布评论

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

评论(2

爱给你人给你 2024-07-16 20:59:15

尝试这样的事情:

class my_lbox : public CVSListBox
{
    protected:

        BOOL OnBeforeRemoveItem(int what_item)
        {
            CString txt = GetItemText(what_item);
            DWORD_PTR idata = GetItemData(what_item);

            if(true) //up to you to check if this item can be removed
            {
                OnAfterRemoveItem(txt,idata);
                return TRUE;
            }
            return FALSE;
        }

        void OnAfterRemoveItem(const CString& txt, DWORD_PTR idata)
        {
            CString info;
            info.Format(L"Removing item:'%s'",txt);

            MessageBox(info);
        }
};

希望有帮助。

Try something like this:

class my_lbox : public CVSListBox
{
    protected:

        BOOL OnBeforeRemoveItem(int what_item)
        {
            CString txt = GetItemText(what_item);
            DWORD_PTR idata = GetItemData(what_item);

            if(true) //up to you to check if this item can be removed
            {
                OnAfterRemoveItem(txt,idata);
                return TRUE;
            }
            return FALSE;
        }

        void OnAfterRemoveItem(const CString& txt, DWORD_PTR idata)
        {
            CString info;
            info.Format(L"Removing item:'%s'",txt);

            MessageBox(info);
        }
};

Hope it helps.

属性 2024-07-16 20:59:14

假设该项目每次都会真正被删除,您可以:

  • 在 OnBeforeRemoveItem 重写中进行处理,就好像该项目已被删除一样
  • 引发您自己的 OnAfterItemRemoved 事件
  • 查看是否可以获得基础列表控件的句柄(无论它是什么) be) 并挂钩其事件之一

Assuming that the item will truly be removed every time, you could either:

  • Do the handling in the OnBeforeRemoveItem override as if the item was already removed
  • Raise your own OnAfterItemRemoved event
  • See if you can get a handle on the underlying list control (whatever it may be) and hook one of its events
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文