|
To enable your application to become a drop target, follow these steps:
- Initialize the OLE libraries. You should check the build version and call the OleInitialize function exactly as you would for a drop source.
- Call the RegisterDragDrop function. OLE keeps a list of the windows that are drop targets. Every window
that accepts dropped objects must register itself and its IDropTarget interface pointer. Then when the user drags the object over a drop target
window, OLE has the IDropTarget interface pointer handy.
- Implement the IDropTarget interface. OLE uses the IDropTarget interface pointer that you registered with RegisterDragDrop to keep you informed of the state of a drop operation.
When the cursor first enters a registered drop target window, OLE calls the IDropTarget::DragEnter member function. In this member function, you should ensure that your
application can create the dragged object if it is dropped. Your application may also
display visual feedback showing where the dropped object will appear, if
appropriate.
When the cursor moves around inside a drop target window, OLE calls the IDropTarget::DragOver member function, just as Windows 95 sends WM_MOUSEMOVE messages. Here you
should update any visual feedback that your application displays to reflect the
current cursor position. When the cursor leaves a drop target window, OLE calls
the IDropTarget::DragLeave member function. In your DragLeave member function, you should remove any feedback you displayed during DragOver or DragEnter.
OLE calls your IDropTarget::Drop member function when the user drops the object. To be precise, a drop occurs
when the drop source returns the DRAGDROP_DROP value from the IDropSource::QueryContinueDrag member function. In your Drop member function, you should create an appropriate object from IDataObject that is passed as a parameter. The following example shows how to implement IDropTarget::Drop.
STDMETHODIMP CDropTarget::Drop (LPDATAOBJECT pDataObj,
DWORD grfKeyState, POINTL pointl, LPDWORD pdwEffect)
{
FORMATETC fmtetc;
SCODE sc = S_OK;
UndrawDragFeedback(); // removes any visual feedback
// QueryDrop returns TRUE if the app. can accept a drop based on
// the current key state, requested action, and cursor position.
if (pDataObj && QueryDrop(grfKeyState,pointl,FALSE,pdwEffect)) {
m_pDoc->m_lpSite = CSimpleSite::Create(m_pDoc);
m_pDoc->m_lpSite->m_dwDrawAspect = DVASPECT_CONTENT;
// Initialize the FORMATETC structure.
fmtetc.cfFormat = NULL;
fmtetc.ptd = NULL;
fmtetc.lindex = -1;
fmtetc.dwAspect = DVASPECT_CONTENT; // draws object's content
fmtetc.tymed = TYMED_NULL;
HRESULT hrErr = OleCreateFromData
(pDataObj,IID_IOleObject,OLERENDER_DRAW,
&fmtetc, &m_pDoc->m_lpSite->m_OleClientSite,
m_pDoc->m_lpSite->m_lpObjStorage,
(LPVOID FAR *)&m_pDoc->m_lpSite->m_lpOleObject);
if (hrErr == NOERROR)
// The object was created successfully.
else
// The object creation failed.
sc = GetScode(hrErr);
}
return ResultFromScode(sc);
}
- Call the RevokeDragDrop function. Before a drop target window is destroyed, it must call RevokeDragDrop to allow OLE to remove the window from its list of drop targets.
- Uninitialize the OLE libraries. Like a drop source, your application needs to
uninitialize the OLE libraries before terminating.
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|