如何在从图标文件生成的 Windows 光标上设置热点坐标?
我正在从图标文件在我的应用程序上设置自定义光标,但单击点位于错误的坐标处。我正在设置光标,
SetClassLongPtr(hwnd, GCL_HCURSOR, reinterpret_cast<LONG_PTR>cursor)
其中cursor is the result of;
LoadImage(
NULL,
"some_path/cursor.ico",
IMAGE_ICON, //also tried IMAGE_CURSOR
0, //width. 0 uses the width of the file provided
0, //height. 0 uses the height of the file provided
LR_LOADFROMFILE
);
光标加载良好,但其点击来自光标图像的左下角,而不是左上角。
关于 .ico 文件的维基百科文章表示热点仅在 .cur 上指定文件,而不是 .ico。
编辑:澄清问题
参考:LoadImage() 和 msdn 上的 SetClassLongPtr()。
I'm setting a custom cursor on my app from an icon file, but the click point is at the wrong co-ordinates. I'm setting the cursor with
SetClassLongPtr(hwnd, GCL_HCURSOR, reinterpret_cast<LONG_PTR>cursor)
where cursor is the result of;
LoadImage(
NULL,
"some_path/cursor.ico",
IMAGE_ICON, //also tried IMAGE_CURSOR
0, //width. 0 uses the width of the file provided
0, //height. 0 uses the height of the file provided
LR_LOADFROMFILE
);
The cursor loads fine, but its clicks come from the bottom-left corner of the cursor image, rather than top left.
The wikipedia article on .ico files says the hotspots are only specified on .cur files, not .ico.
Edit: Clarified question
ref: LoadImage() and SetClassLongPtr() on msdn.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 CreateIconFromResourceEx
传入的内容来 执行此操作指向 CURSOR_RES_HDR 的指针作为第一个参数。这是您可以在文档中找到的结构之一,但它不是我能找到的任何头文件。不过它非常简单,基本上是 16 位无符号整数,后跟包含光标图像数据的 BITMAPINFOHEADER。
You can do this with CreateIconFromResourceEx
You pass in a pointer to a CURSOR_RES_HDR as the first parameter. This is one of those structures that you can find buried in the documentation, but it isn't any header file I can find. It's pretty simple though, basically to 16 bit unsigned ints followed by a BITMAPINFOHEADER containing the cursor image data.
使用这个优秀的光标编辑器来创建光标,您可以设置热点,使其动画等等。我发现它非常漂亮和整洁。
希望这有帮助,
此致,
汤姆.
Use this excellent cursor editor for creating cursors and you can set the hotspot, make it animated, etc. I found it quite nifty and neat.
Hope this helps,
Best regards,
Tom.
是的,热点是由.cur 文件的内容决定的。维基百科文章向您展示了这一点,偏移量 4 和 6。Windows 没有 API 可以在加载光标后更改热点。只需在 Visual Studio 或任何其他光标编辑器中编辑光标,指定热点并将文件另存为 .cur 文件。
Yes, the hotspot is determined by the content of the .cur file. The Wikipedia article shows you this, offsets 4 and 6. Windows doesn't have an API to change the hotspot after the cursor is loaded. Simply edit the cursor in Visual Studio or any other cursor editor, specify the hot spot and save the file as a .cur file.