The previous article about OLE drag-and-drop is now copied.

Source: Internet
Author: User

[OLE drag and drop]

There are many interfaces related to OLE drag and drop:

Idataobject: this interface is mainly responsible for data processing. It is implemented in the OLE drag source to define the data transmission format. In the target object dragged by OLE, you can obtain the idataobject interface and obtain data through the getdata method of this interface. The details are described below.

Idropsource: this interface defines some methods to process the drag-and-drop interface display. (Whether this is the case remains to be verified)

Idroptarget: this interface defines the method to be implemented to receive OLE drag. You must implement this interface to receive objects dragged by Ole.

--------------------------------------------------------------------------------

Now I mainly want to respond to OLE drag and drop, so let's start with idroptarget.

To respond to OLE drag, you must first implement the idroptarget interface and register the interface to the window to respond to OLE drag. For example, the object is as follows:
Tdropmanager = Class (tinterfacedobject, idroptarget)
Private
Fowner: twincontrol;
Fhandle: hwnd;
Ftarget: pointer;
Public
Constructor create (aowner: twincontrol );
Destructor destroy; override;
Function dragenter (const dataobj: idataobject; grfkeystate: longint; Pt: tpoint;
VaR dweffect: longint): hresult; stdcall;
Function dragover (grfkeystate: longint; Pt: tpoint; var dweffect: longint): hresult; stdcall;
Function dragleave: hresult; stdcall;
Function drop (const dataobj: idataobject; grfkeystate: longint; Pt: tpoint;
VaR dweffect: longint): hresult; stdcall;
End;
This object implements idroptarget to create this object. Write the following code in the create method:
Constructor tpsdragdropmanager. Create (aowner: twincontrol );
Begin
Inherited create;
Fowner: = aowner;
Fhandle: = aowner. Handle;
Olecheck (registerdragdrop (fhandle, self ));
End;
Registerdragdrop registers the objects that support the idroptarget interface as the window referred to by fhandle to process OLE drag objects. The program knows that the parent window of this object can get OLE drag events, which are triggered in dragenter, dragover, dragleave, and drop. Of course, you also need to cancel registration when the object is released. That is, call revokedragdrop (fhandle) in the destructor. Note that registerdragdrop and revokedragdrop do not have to be placed in the constructor. They can be placed anywhere.

[Important Note: Ole is called here, So Initialization is required. Use oleinitialize (NiL) and oleuninitialize functions. I use the two functions in the initialization and finalization sections of this unit respectively (note, in Delphi)]
<Another note: In dragenter, The result: = s_ OK event will be passed to dragover, dragleave, and so on.>

In the dragenter, dragover, and drop functions, both have the const dataobj: idataobject parameter. This interface is the interface for passing data. You can call the getdata method of this interface to obtain the data dragged by Ole. The getdata statement is as follows: function getdata (const formatetcin: tformatetc; out medium: tstgmedium): hresult; stdcall; it requires two parameters. The formatetcin function specifies the type of drag data that can respond. The medium parameter stores specific data information.
For example:
Const
Hdropformatetc: tformatetc = (cfformat: cf_hdrop; PTD: Nil; dwaspect: dvaspect_content;
Lindex:-1; tymed: $ ffffffff );
Hdropformatetc1: tformatetc = (cfformat: cf_text; PTD: Nil; dwaspect: dvaspect_content;
Lindex:-1; tymed: $ ffffffff );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.