Custom made win32 drag-drop, can't get change invalid (slashed circle ) cursor
I've a quite difficult problem to explain but I will try my best. I've made a custom drag-drop implementation to a win32 GUI based application. Due to limitations of the program I can't use the proper OLE drag-drop mechanism. Its okey, I made my own with mouse key tracking and it works so so. The only problem I can't solve now is the bloody invalid (slashed circle) - IDC_NO cursor.
My window thinks it is undroppable and changes the cursor to invalid when something is about to drop. I tried everything to change it but it insists to stay there.
case WM_SETCURSOR:
{
//SetSystemCursor(CopyCursor(LoadCursor(NULL, IDC_CROSS)), 32648);
//DestroyCursor();
SetCursor(LoadCursor(NULL, IDC_CROSS));
SetWindowLong(hwnd, DWL_MSGRESULT, TRUE);
return TRUE;
}
break;
I even tried, to change icon outside the message switch which runs in every call to the callback function. It worked a little but not OK. Its like I'm setting it to IDC_CROSS cursor but it is returning back to IDC_NO.
Ho开发者_StackOverflow社区w can I get rid-off this invalid cursor? I want to set it to IDC_CROSS.
Or how can I implement a Drag-drop without using OLE or MFC classes to make my application dropable and not showing that invalid cursor.
Quite complicated but thank you for your time, even for reading my question ;)
You can draw your custom icon. Try this:
ScreenToClient(hwnd, &point);
RECT clearRect;
clearRect.left = point.x - 128;
clearRect.top = point.y - 128;
clearRect.right = point.x + 128;
clearRect.bottom = point.y + 128;
InvalidateRect(hwnd, &clearRect, TRUE);
UpdateWindow(hwnd);
DrawIcon(GetDC(hwnd), point.x, point.y, LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(YOUR_RESOURCE_ID)));
You're on the wrong track with this. The cursor shape is not controlled by WM_SETCURSOR anymore when a D+D is in progress. COM takes over and alters the shape when a window give the 'okay to drop' feedback. Which is probably what's missing from your code.
You cannot bypass 'OLE' or the MFC wrappers that make it easy, the source of the drag will use it. Lookup IDropTarget::DragEnter to get that right. Using a class wrapper is certainly the best approach, it isn't that easy to get it right on your own.
Are you registering your window to accept dragged files with the DragAcceptFiles
function? (http://msdn.microsoft.com/en-us/library/bb776406%28VS.85%29.aspx) It's useful for getting very basic drag-drop functionality without getting into OLE, but doesn't provide as much versatility, because you only get the WM_DROPFILES
message after the mouse button is released.
精彩评论