我如何知道 HCURSOR 对象的大小
我想获取 .cur 文件的高度和宽度,而不查看其格式。
我尝试使用 LoadCursorFromFile() 来获取 HCURSOR,我想有一个 API 函数可以获取 HCURSOR 信息,但我发现 GetCursorInfo() 根本不是我想要的。
有没有办法获取 HCURSOR 对象的高度和宽度?
I want to get the height and width of a .cur file without look into its format.
I try to use LoadCursorFromFile() to get a HCURSOR, I suppose there is a API function to obtain the HCURSOR infos, but I find that GetCursorInfo() is not I want at all.
Is there any way to get the height and width of a HCURSOR object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通用 C++ 代码,适用于任何光标:
Universal C++ code, for any cursor:
此答案已过时
请参阅 23W 的答案。这对我来说看起来很正确。
Raymond Chen 有一篇博客文章,解释了
SM_CXCURSOR
和SM_CYCURSOR
系统指标是由显示适配器实现的硬件光标的大小。由于光标不再是现代显示硬件的功能,因此这些值已过时,但操作系统仍报告向后兼容性的值。感谢@SO_fix_the_vote_sorting_bug 的评论让我注意到这一点。
历史背景的原始答案
Windows 中的图标和光标之间的 API 存在一些重叠。您可以调用
GetIconInfoEx
使用 HCURSOR 以及 HICON。您返回的结构将包含有关热点的信息。我没有找到获得实际大小的方法。从技术上讲,所有光标图标都是固定大小,您可以通过询问系统获得固定大小(使用
GetSystemMetrics
) 用于SM_CXCURSOR
和SM_CYCURSOR
。看起来较小的实际上就是那个尺寸,它们只是有很多透明像素。如果您必须知道表观尺寸,则必须提取掩模并扫描位以找出边界矩形。THIS ANSWER IS OUT OF DATE
See 23W's answer instead. That looks right to me.
Raymond Chen has a blog post that explains the
SM_CXCURSOR
andSM_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.Thanks to @SO_fix_the_vote_sorting_bug's comment for bringing this to my attention.
ORIGINAL ANSWER FOR HISTORICAL CONTEXT
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.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
) forSM_CXCURSOR
andSM_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.来自MSDN:
nWidth 和 nHeight 参数必须指定当前显示驱动程序支持的宽度和高度,因为系统无法创建其他尺寸的光标。要确定显示驱动程序支持的宽度和高度,请使用 GetSystemMetrics 函数,并指定 SM_CXCURSOR 或 SM_CYCURSOR 值。
From MSDN:
The nWidth and nHeight parameters must specify a width and height that are supported by the current display driver, because the system cannot create cursors of other sizes. To determine the width and height supported by the display driver, use the GetSystemMetrics function, specifying the SM_CXCURSOR or SM_CYCURSOR value.