Windows 函数"GetCursorInfo"返回成功,但光标的句柄为 NULL

Windows function "GetCursorInfo" returns success but the HANDLE to the cursor is NULL

本文关键字:光标 句柄 NULL 函数 GetCursorInfo 返回 成功 Windows      更新时间:2023-10-16

我正在尝试获取全局光标的句柄。因此,我使用Windows函数"GetCursorInfo"。函数的返回值为非零值,这意味着它成功了。但是,返回的游标的句柄为 NULL。

这是我正在使用的代码:

CURSORINFO ci;
ci.cbSize = sizeof(ci);
if (!GetCursorInfo(&ci)) {
cout << "GetCursorInfo() failed" << endl;
return 1;
}
cout << ci.hCursor << endl; // ci.hCursor is 0x00000000

我只在装有 Windows 10 的英特尔 NUC 迷你电脑上收到此错误(而不是在装有 Windows 10 的普通 PC 上(。

我在其他任何地方都找不到此错误,因此将不胜感激!

谢谢!

好的,我已经弄清楚为什么会发生这种情况:

我正在远程连接到我的英特尔 NUC 迷你电脑,因此没有连接物理鼠标。这似乎是导致问题的原因。一旦我连接物理鼠标,一切就会再次按预期工作。

一旦没有连接鼠标,Windows 似乎就会切换到平板电脑模式,因此隐藏光标。