SetCursor 在鼠标移动后恢复 [英] SetCursor reverts after a mouse move

查看:34
本文介绍了SetCursor 在鼠标移动后恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SetCursor 将系统光标设置为我自己的图像.代码如下所示:

I am using SetCursor to set the system cursor to my own image. The code looks something like this:

// member on some class
HCURSOR _cursor;

// at init time
_cursor = LoadCursorFromFile("somefilename.cur");

// in some function
SetCursor(_cursor);

当我这样做时,光标确实发生了变化,但是在第一次鼠标移动消息时,它又变回了默认的系统箭头光标.这是项目中设置光标的唯一代码.我需要做什么才能使光标保持我设置的方式?

When I do this the cursor does change, but on the first mouse move message it changes back to the default system arrow cursor. This is the only code in the project that is setting the cursor. What do I need to do to make the cursor stay the way I set it?

推荐答案

看来我有两个选择.第一个是Mark Ransom在这里建议的,就是响应windows的WM_SETCURSOR消息,根据鼠标所在的位置调用当时的SetCursor.通常,当光标位于窗口上方时,窗口只会向您发送 WM_SETCURSOR,因此您只需在窗口中设置光标.

It seems that I have two options. The first is the one that Mark Ransom suggested here, which is to respond to the windows WM_SETCURSOR message and call SetCursor at that time based on where the mouse is. Normally windows will only send you WM_SETCURSOR when the cursor is over your window, so you would only set the cursor in your window.

另一个选项是在调用 SetCursor 的同时为窗口句柄设置默认光标.这会将默认处理程序设置的光标更改为 WM_SETCURSOR.该代码看起来像这样:

The other option is to set the default cursor for the window handle at the same time as I call SetCursor. This changes the cursor set by the default handler to WM_SETCURSOR. That code would look something like this:

// defined somewhere
HWND windowHandle;
HCURSOR cursor;

SetCursor(cursor);
SetClassLong(windowHandle, GCL_HCURSOR, (DWORD)cursor);

如果你使用第二种方法,你必须同时调用 SetCursorSetClassLong 否则你的光标不会更新,直到下一次鼠标移动.

If you use the second method you have to call both SetCursor and SetClassLong or your cursor will not update until the next mouse move.

这篇关于SetCursor 在鼠标移动后恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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