如何在从图标文件生成的Windows游标上设置热点坐标? [英] How do you set hotspot co-ordinates on a Windows cursor generated from an icon file?

查看:197
本文介绍了如何在从图标文件生成的Windows游标上设置热点坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从图标文件中设置我的应用程序上的自定义光标,但点击点位于错误的坐标。我正在设置光标

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)

其中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.

维基百科文章。 ico文件说,热点只在.cur文件上指定,而不是.ico。

The wikipedia article on .ico files says the hotspots are only specified on .cur files, not .ico.

编辑:澄清的问题

ref: LoadImage() msdn上的SetClassLongPtr()

推荐答案

您可以使用 CreateIconFromResourceEx

您传入指向CURSOR_RES_HDR的指针作为第一个参数。这是你可以在文档中找到的那些结构之一,但它不是我可以找到的任何头文件。这很简单,但基本上是16位无符号整数,后跟一个包含光标图像数据的BITMAPINFOHEADER。

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.

typedef struct {
   WORD             xHot;         // x hotspot
   WORD             yHot;         // y hotspot
   BITMAPINFOHEADER bih;
   } CURSOR_RES_HDR;

...

CURSOR_RES_HDR * pImage;

// Fill out pImage

HCURSOR hcur = CreateIconFromREsourceEx((BYTE*)pImage, 
                  cbImage, // size of image data + hotspot (in bytes)
                  FALSE,
                  0x00030000, // version: value mandated by windows
                  0, 0,       // width & height, 0 means use default
                  LR_DEFAULTSIZE | LR_DEFAULTCOLOR);

这篇关于如何在从图标文件生成的Windows游标上设置热点坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆