Adding Drop Source Capabilities

To enable your application to become the source of a drag and drop operation, follow these steps:

  1. Initialize the OLE libraries. Any application that uses the OLE libraries must check the version of the libraries and call the OleInitialize function during its initialization.

You should make sure that the system's OLE libraries are at least as recent as the ones for which the application was written.

Before you call any other OLE functions, you must call OleInitialize to initialize the OLE libraries. Because each call to OleInitialize must have a matching call to the OleUninitialize function, you should maintain an fOleInitialized flag so that you will know whether to call OleUninitialize when your application exits.

  1. Implement the IDropSource interface. Not including the member functions that it inherits from IUnknown, IDropSource has only two member functions: QueryContinueDrag and GiveFeedback. OLE calls QueryContinueDrag intermittently during the drag operation. Its parameters include the state of the keyboard, which the drop source uses to control the drag operation. The drop source returns the S_OK value to continue dragging, the DRAGDROP_CANCEL value to cancel dragging, or the DRAGDROP_DROP value to drop the object.

  2. OLE calls GiveFeedback to tell the drop source to update the cursor and ask the source window for visual feedback about what would happen if the user dropped at the current point. It sounds like a lot of work to update the cursor, but OLE will use its default cursors if the DRAGDROP_S_USEDEFAULTCURSORS value is returned.

  3. Implement the IDataObject interface, which is used by OLE applications to transfer data. In a drag and drop operation, the drop source gives OLE a pointer to its IDataObject implementation. OLE saves the pointer and passes it to the drop target when the cursor first enters the target window and when the drop occurs. Fortunately, you only need to implement the following (non-IUnknown) IDataObject member functions for drag and drop support: GetData, GetDataHere, QueryGetData, and EnumFormatEtc.

  4. Call the DoDragDrop function to begin the drag operation. After you have detected that the user wants to drag something, you should call DoDragDrop. OLE uses the IDataObject and IDropSource pointers that are passed in, along with its list of registered drop targets, to control the drag operation. When the drag operation is complete, DoDragDrop returns either the DRAGDROP_S_DROP or DRAGDROP_S_CANCEL value. In addition, OLE returns a DWORD in the address pointed to by pdwEffect that tells how the drop should affect the source datapics/WIN3200090001.gifthat is, whether the operation was a move, copy, link, or scroll. You should look at the pdwEffect value and modify the source data as necessary.

  5. Call OleUninitialize. Before an OLE application exits, it must call OleUninitialize to release the OLE libraries. You should check your fOleInitialized flag before calling OleUninitialize and should only call OleUninitialize if OleInitialize returned successfully.

    Software for developers
    Delphi Components
    .Net Components
    Software for Android Developers
    More information resources
    MegaDetailed.Net
    Unix Manual Pages
    Delphi Examples
    Databases for Amazon shops developers
    Amazon Categories Database
    Browse Nodes Database