WinAPI SetSystemCursor和LoadCursorFrom-如何设置默认光标? [英] WinAPI SetSystemCursor and LoadCursorFrom - how to set default cursor?

查看:242
本文介绍了WinAPI SetSystemCursor和LoadCursorFrom-如何设置默认光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式设置了自己的光标:

I set my own cursor by:

HCURSOR hCurStandard =  LoadCursorFromFile(TEXT("cursor.cur"));
SetSystemCursor(hCurStandard, 32512);
DestroyCursor(hCurStandard);

如何返回并设置默认光标?

How to go back and set default cursor?

这不起作用:

SetSystemCursor(LoadCursor(0, IDC_ARROW), 32512);

----编辑-----

----EDIT-----

HCURSOR hcursor = LoadCursor(0, IDC_ARROW);
HCURSOR hcursor_copy = CopyCursor(hcursor);
BOOL ret = SetSystemCursor(hcursor_copy, OCR_NORMAL);
DestroyCursor(hcursor);

这适用于除IDC_ARROW以外的所有游标,什么呢?

This works for all cursors except IDC_ARROW, what the...?

推荐答案

问题是您可能使用SetSystemCursor函数更改了标准箭头光标。该函数实际上使用您提供的HCURSOR覆盖了系统游标,因此,当您使用IDC_ARROW调用LoadCursor时,它将加载您的自定义游标。这就解释了程序的怪异行为。为避免这种情况,应在更改默认系统光标之前保存它。

The problem is that you probably use SetSystemCursor function to change the standard arrow cursor. This function actually overwrites the system cursor with HCURSOR you provided, so when you call LoadCursor with IDC_ARROW it loads your custom cursor. That explains the weird behaviour of your program. To avoid that, you should save the default system cursor before you change it.

HCURSOR def_arrow_cur = CopyCursor(LoadCursor(0, IDC_ARROW));
//now you have a copy of the original cursor
SetSystemCursor(LoadCursorFromFile("my_awesome_cursor.cur"),OCR_NORMAL);
...
SetSystemCursor(def_arrow_cur,OCR_NORMAL);//restore the good old arrow

我知道这是一个迟来的答案,但我希望有人会觉得这个有用。

I know it's a late answer, but I hope somebody will find this useful.

这篇关于WinAPI SetSystemCursor和LoadCursorFrom-如何设置默认光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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