且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何知道 HCURSOR 对象的大小

更新时间:2023-11-13 12:56:40

此答案已过时

请参阅 23W 的回答.这对我来说是正确的.

See 23W's answer instead. That looks right to me.

Raymond Chen 有一篇博文 解释了SM_CXCURSORSM_CYCURSOR 系统指标是显示适配器实现的硬件光标的大小.由于光标不再是现代显示硬件的功能,因此这些值已过时,但操作系统仍会报告向后兼容的值.

Raymond Chen has a blog post that explains the SM_CXCURSOR and SM_CYCURSOR system metrics were the size of the hardware cursor implemented by the display adapter. Since cursors are no longer a feature of modern display hardware, these values are obsolete, but the OS still reports values for backward compatibility.

感谢@SO_fix_the_vote_sorting_bug 的评论让我注意到这一点.

Thanks to @SO_fix_the_vote_sorting_bug's comment for bringing this to my attention.

历史背景的原始答案

Windows 中图标和光标之间的 API 存在一些重叠.您可以调用 GetIconInfoEx 使用 HCURSOR 和 HICON.您返回的结构将包含有关热点的信息.

There is some overlap in the APIs between icons and cursors in Windows. You can call GetIconInfoEx with an HCURSOR as well as with an HICON. The structure you get back will have information about the hotspot.

我没有找到获得实际尺寸的方法.从技术上讲,所有光标图标都是固定大小,您可以通过询问系统(使用 GetSystemMetrics) 用于 SM_CXCURSORSM_CYCURSOR.看起来更小的那些实际上是那个大小,它们只是有很多透明像素.如果您必须知道表观大小,则必须提取掩码并扫描位以找出边界矩形.

I don't see a way to get the actual size. Technically, all cursor icons are a fixed size that you can get by asking the system (with GetSystemMetrics) for SM_CXCURSOR and SM_CYCURSOR. The ones that appear smaller are actually that size, they just have a lots of transparent pixels. If you must know the apparent size, you'll have to extract the mask and scan the bits to figure out the bounding rectangle.