简体   繁体   English

如何禁用从 Rich Edit 控件拖动

[英]How to disable dragging from a Rich Edit Control

I use a subclass of CRichEditCtrl to provide a CEdit+ type control.我使用 CRichEditCtrl 的子类来提供 CEdit+ 类型控件。 One thing I want is to disable drag-drop functionality, which the base class provided by default.我想要的一件事是禁用拖放功能,默认情况下是基类提供的。

Disabling dropping is easy: ::RevokeDragDrop(m_hWnd);禁用删除很容易::RevokeDragDrop(m_hWnd);

But I can't see a simple way to disable the control being a drag-source.但是我看不到一种简单的方法来禁用控件是拖动源。 Is there an easy way?有没有简单的方法?

To Override Starting Drag-and-Drop in the RichEdit Control:要覆盖RichEdit控件中的开始拖放:

  1. Implement IRichEditOleCallback interface.实现IRichEditOleCallback接口。
  2. implement GetDragDropEffect() method of the interface like this:像这样实现接口的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 !!!!
}

Most important here is return E_ABORT;这里最重要的是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:RichEdit控件中覆盖接收拖放操作:

  1. Implement your own IDropTarget Interface.实现您自己的IDropTarget接口。
  2. Register IDropTarget interface like this:像这样注册IDropTarget接口:

After Creating RichEdit control in RichEdit derived subclass function: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);

This example overrides the default drop target function of RichEdit .此示例覆盖RichEdit的默认放置目标函数。

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 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.如果您的子类这样做,然后只是没有让 CRichEditCtrl 获取触发拖动的窗口消息,则拖动将不会开始。

Might work.可能工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM