The first step for a target is to decide how it will indicate what might happen in a drop operation. There are many ways to do this. A word processor, for example, might show a shaded caret at the point where text would be dropped.
An application such as Patron, which pastes graphics, might show a rectangle of the exact size and at the location the dropped data would occupy.
For Cosmo, pasting any Polyline data replaces the data in the window with the new data, so we can highlight the Polyline window itself with inverted edges.
This feedback is generated in the new function CCosmoDoc::DropSelectTargetWindow, which inverts a 3-pixel frame around the window. This function is a toggle: we'll turn the highlight on in IDropTarget::DragEnter and turn it off in IDropTarget::DragLeave and IDropTarget::Drop:
void CCosmoDoc::DropSelectTargetWindow(void)
{
HDC hDC;
RECT rc;
UINT dd=3;
HWND hWnd;
hWnd=m_pPL->Window();
hDC=GetWindowDC(hWnd);
GetClientRect(hWnd, &rc);
//Top
PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, dd, DSTINVERT);
//Bottom
PatBlt(hDC, rc.left, rc.bottom-dd, rc.right-rc.left, dd
, DSTINVERT);
//Left, excluding regions already affected by top and bottom
PatBlt(hDC, rc.left, rc.top+dd, dd, rc.bottom-rc.top-(2*dd)
, DSTINVERT);
//Right, excluding regions already affected by top and bottom
PatBlt(hDC, rc.right-dd, rc.top+dd, dd, rc.bottom-rc.top-(2*dd)
, DSTINVERT);
ReleaseDC(hWnd, hDC);
return;
}
The DropSelectTargetWindow function (like all such feedback functions) has two responsibilities. First, it needs to determine where to place the feedback. For Cosmo, we can use the rectangle of the Polyline window, but for applications such as word processors, you might need to calculate the line and character nearest the mouse cursor. For a spreadsheet, you would have to determine the closest range of cells.
Second, the function must draw the visuals at that location. Cosmo does this with PatBlt and DSTINVERT. Normally you'll use some sort of XOR operation so that you can show an image and remove it quickly and easily, but it's always your choice.