如何禁用从 Rich Edit 控件拖动

发布于 2024-08-26 04:30:07 字数 162 浏览 6 评论 0原文

我使用 CRichEditCtrl 的子类来提供 CEdit+ 类型控件。我想要的一件事是禁用拖放功能,这是基类默认提供的。

禁用拖放很容易: ::RevokeDragDrop(m_hWnd);

但我看不到禁用控件作为拖动源的简单方法。有简单的方法吗?

I use a subclass of CRichEditCtrl to provide a CEdit+ type control. One thing I want is to disable drag-drop functionality, which the base class provided by default.

Disabling dropping is easy: ::RevokeDragDrop(m_hWnd);

But I can't see a simple way to disable the control being a drag-source. Is there an easy way?

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

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

发布评论

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

评论(2

云之铃。 2024-09-02 04:30:07

要覆盖 RichEdit 控件中的启动拖放操作:

  1. 实现 IRichEditOleCallback 接口。
  2. 实现接口的 GetDragDropEffect() 方法,如下所示:
HRESULT CRichEditOleCallback::GetDragDropEffect( BOOL fDrag, DWORD grfKeyState,
            LPDWORD pdwEffect)
{
    CComPtr<IDataObject> pdata_obj;
    CComQIPtr<IDropSource> psource;
    DWORD dwEffect;

    // You put here your own data-object code....

    DoDragDrop( pdata_obj, psource, DROPEFFECT_COPY|DROPEFFECT_MOVE, &dwEffect);
    // This executes your own drag and drop function.


    return E_ABORT; // !!!! THIS IS ESSENTIALLY IMPORTANT !!!! NOT WRITTEN IN MANUAL !!!!
}

这里最重要的是 return E_ABORT; 这会导致退出默认拖放操作并启动自定义拖放操作。

要覆盖 RichEdit 控件中的接收拖放操作:

  1. 实现您自己的 IDropTarget 接口。
  2. 注册IDropTarget接口如下:

RichEdit派生子类函数中创建RichEdit控件后:

CComPtr<IDropTarget> pDropTarget; // this is your own customized drop target.

RevokeDragDrop(m_hWnd); // unregister default IDropTarget interface of Rich Edit.
RegisterDragDrop(m_hWnd, pDropTarget);

本示例覆盖RichEdit的默认放置目标函数

To Override Starting Drag-and-Drop in the RichEdit Control:

  1. Implement IRichEditOleCallback interface.
  2. implement GetDragDropEffect() method of the interface like this:
HRESULT CRichEditOleCallback::GetDragDropEffect( BOOL fDrag, DWORD grfKeyState,
            LPDWORD pdwEffect)
{
    CComPtr<IDataObject> pdata_obj;
    CComQIPtr<IDropSource> psource;
    DWORD dwEffect;

    // You put here your own data-object code....

    DoDragDrop( pdata_obj, psource, DROPEFFECT_COPY|DROPEFFECT_MOVE, &dwEffect);
    // This executes your own drag and drop function.


    return E_ABORT; // !!!! THIS IS ESSENTIALLY IMPORTANT !!!! NOT WRITTEN IN MANUAL !!!!
}

Most important here is return E_ABORT; this causes quitting default drag and drop operation and starting the customized one.

To Override Receiving Drag and Drop Operation in the RichEdit Control:

  1. Implement your own IDropTarget Interface.
  2. Register IDropTarget interface like this:

After Creating RichEdit control in RichEdit derived subclass function:

CComPtr<IDropTarget> pDropTarget; // this is your own customized drop target.

RevokeDragDrop(m_hWnd); // unregister default IDropTarget interface of Rich Edit.
RegisterDragDrop(m_hWnd, pDropTarget);

This example overrides the default drop target function of RichEdit.

还给你自由 2024-09-02 04:30:07

警告:我远离我的编译器,所以我无法检查这一点。

我也想不出一个简单的方法,但是......

这是一篇关于扩展文本控件以支持拖动的文章。
http://www.code-magazine.com/article。 aspx?quickid=0407031&page=5

是的,这与您想要的完全相反。

但请考虑,它是关于检测指示您要启动拖动操作的鼠标消息。如果您的子类执行了此操作,然后不让 CRichEditCtrl 获取触发拖动的窗口消息,则拖动将不会开始。

可能有用。

Caveat: I'm away from my compiler, so I can't check this.

I can't think of a simple way either, but ...

This is an article about extending a text control to support dragging.
http://www.code-magazine.com/article.aspx?quickid=0407031&page=5

Yes, it's the exact opposite of what you want.

But consider that it's about detecting the mouse messages that indicate that you want to initiate a drag action. If your subclass did this, and then just didn't let the CRichEditCtrl get the window message(s) that triggers the drag, the drag wouldn't start.

Might work.

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