定制的win32拖放,无法获取更改无效(斜线圆圈)光标

发布于 2024-09-16 20:07:41 字数 684 浏览 7 评论 0原文

我有一个很难解释的问题,但我会尽力。我已经对基于 win32 GUI 的应用程序进行了自定义拖放实现。由于程序的限制,我无法使用正确的 OLE 拖放机制。没关系,我自己用鼠标键跟踪做了一个,效果一般。我现在唯一无法解决的问题是该死的无效(斜线圆圈)-IDC_NO 光标。

我的窗口认为它是不可删除的,并且当某些东西即将删除时将光标更改为无效。我尝试了一切方法来改变它,但它坚持留在那里。

case WM_SETCURSOR:
{
    //SetSystemCursor(CopyCursor(LoadCursor(NULL, IDC_CROSS)), 32648);
    //DestroyCursor();
    SetCursor(LoadCursor(NULL, IDC_CROSS));
    SetWindowLong(hwnd, DWL_MSGRESULT, TRUE);
    return TRUE;
}
break;

我什至尝试更改消息开关外部的图标,该开关在每次调用回调函数时运行。有点效果,但不太好。就像我将其设置为 IDC_CROSS 游标,但它返回到 IDC_NO。

我怎样才能摆脱这个无效的光标?我想将其设置为IDC_CROSS。

或者如何在不使用 OLE 或 MFC 类的情况下实现拖放以使我的应用程序可放置并且不显示无效光标。

相当复杂,但感谢您抽出时间,甚至阅读我的问题;)

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.

How 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 ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苦妄 2024-09-23 20:07:41

您可以绘制您的自定义图标。试试这个:

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 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)));
荭秂 2024-09-23 20:07:41

你在这方面走错了路。当 D+D 正在进行时,光标形状不再由 WM_SETCURSOR 控制。当窗口给出“可以放下”反馈时,COM 就会接管并改变形状。这可能是您的代码中缺少的内容。

您无法绕过“OLE”或使其变得简单的 MFC 包装器,拖动源将使用它。查找 IDropTarget::DragEnter 即可获得正确结果。使用类包装器当然是最好的方法,但自己做对并不那么容易。

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.

萌梦深 2024-09-23 20:07:41

您是否正在使用 DragAcceptFiles 函数注册窗口以接受拖动的文件? (http://msdn.microsoft.com/en -us/library/bb776406%28VS.85%29.aspx) 它对于在不进入 OLE 的情况下获得非常基本的拖放功能很有用,但不提供那么多的多功能性,因为您只能获得WM_DROPFILES 消息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文