Article ID: 139408
Article Last Modified on 10/15/2003
HRESULT DoSpecialDragDrop(LPDATAOBJECT pDataObject,
LPDROPSOURCE pDropSource,
DWORD dwOKEffect,
DWORD *pdwEffect)
{
POINT pt;
HWND hwndAttach;
DWORD dwAttachThreadID;
DWORD dwCurrentThreadID;
HRESULT hr = E_FAIL;
// Find the window under the mouse pointer.
// This window might not be owned by the current thread, which
// means you need to use AttachThreadInput in order for mouse
// capture (and drag and drop) to work correctly.
GetCursorPos(&pt);
hwndAttach = WindowFromPoint(pt);
if (!hwndAttach)
return hr;
// Get thread ID's
dwAttachThreadID = GetWindowThreadProcessId(hwndAttach, NULL);
dwCurrentThreadID = GetCurrentThreadId();
// Attach input queues if necessary
if (dwAttachThreadID != dwCurrentThreadID)
AttachThreadInput(dwAttachThreadID, dwCurrentThreadID, TRUE);
// Do the drag and drop
hr = DoDragDrop(pDataObject, pDropSource, dwOKEffect, pdwEffect);
// Detach input queues
if (dwAttachThreadID != dwCurrentThreadID)
AttachThreadInput(dwAttachThreadID, dwCurrentThreadID, FALSE);
return hr;
}
DoSpecialDragDrop is called in the same way as DoDragDrop, except that it
should not be called while processing the taskbar notification message
because the shell sends this message with SendMessage. Because shell
interaction may be required during the drag and drop operation, the
application should delay the drag and drop by posting itself another
message, allowing the shell to continue execution as in this example:
#define WM_MYNOTIFICATIONMESSAGE WM_APP // app-defined messages
#define WM_MYDODRAGDROP WM_APP + 1
case WM_MYNOTIFICATIONMESSAGE: // icon notification message
if (lParam == WM_LBUTTONDOWN && wParam == idMyNotificationIcon)
{
// Give control back to the taskbar and do Drag/Drop later.
// This way the shell won't be blocked on a SendMessage call
// while we are trying to do the drag/drop.
PostMessage(hwnd, WM_MYDODRAGDROP, wParam, lParam);
}
break;
case WM_MYDODRAGDROP:
{
LPDATAOBJECT pDataObject;
LPDROPSOURCE pDropSource;
DWORD dwEffect;
// Initialize IDataObject and IDropSource objects
:
// This drag source only allows Copy, not Move or Link.
DoSpecialDragDrop(pDataObject,
pDropSource,
DROPEFFECT_COPY,
&dwEffect);
// Clean up IDataObject and IDropSource objects
:
}
break;
Additional query words: 2.00 tray Shell_TrayWnd TrayNotifyWnd
Keywords: kbcode KB139408