如何隐藏鼠标光标? [英] How can I hide the mouse cursor?

查看:361
本文介绍了如何隐藏鼠标光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下是否有人可以为我提供一个c ++代码,当按下一个特定的键时,我可以隐藏/显示鼠标的指针。
我发现几个代码只写TURBO C ++,可以使用dev c ++甚至可视化c ++编译和运行。

I wanna ask if someone can provide me a c++ code in which I can hide/show the pointer of the mouse when pressing a specific key.. I found several codes written for only TURBO C++, none of which can be compiled and run using dev c++ or even visual c++..

我试过运行在Dev C ++中找到的代码,但是我只得到了很多错误和不兼容。

I tried running the codes I found in Dev C++ but I only get lots of errors and incompatibilities..

我也发现了几篇文章,说我可以使用ShowCursor函数,但它不会工作。

I also found several articles that says I can use the function ShowCursor but it just wouldn't work..

推荐答案

事实上,隐藏游标可能是一个相当一个任务,这取决于你想要的achive。如果你正在使用WinAPI编程GUI应用程序,这很容易。

In fact hiding the cursor can turn out to be quite a task, depending on what you want to achive. If you're programming a GUI-application using the WinAPI it is pretty easy.

只需调用ShowCursor(false);一次可能在某些情况下可能不工作,因为ShowCursor函数只设置内部显示计数器。将显示光标,直到此计数器小于0(请参阅 msdn )。您可以尝试这样的:

Just calling ShowCursor(false); once might turn out not to work in some cases though, since the ShowCursor function only "sets an internal display counter". The cursor is displayed until this counter is smaller than 0 (see msdn on it). You could try something like this:

while(ShowCursor(false)>=0);

以确保计数器低于0.
这将只隐藏应用程序窗口,如果你使用较新的Windows版本,如Windows 7.隐藏光标在整个系统可能变得更困难很多。

to ensure the counter gets below 0. This will however only hide the cursor inside your applications window, if you're using newer Windows versions like Windows 7. Hiding the cursor all over the system could turn out to be a lot more difficult.

如果你是编程控制台应用程序ShowCursor将不会显示任何效果,只要我测试它。使用以下代码:

If you are programming a console application ShowCursor won't show any effect as far as I've tested it. Using the following code:

while(ShowCursor(false)>=0);    
std::cout<<ShowCursor(false)<<std::endl;
std::cout<<ShowCursor(true)<<std::endl;



我们可以看到,计数器肯定低于0,但仍然显示光标。我到目前为止还没有找到解决方案。

we can see, that the counter definitely is below 0, but still the cursor is displayed. I haven't come up with a solution to this so far.

这篇关于如何隐藏鼠标光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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