开发者

How to disable dragging from a Rich Edit Control

开发者 https://www.devze.com 2022-12-23 05:14 出处:网络
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.

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.

开发者_JAVA百科

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号