How can I hide the mouse cursor?

后端 未结 2 748
别跟我提以往
别跟我提以往 2021-01-29 15:10

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+

相关标签:
2条回答
  • 2021-01-29 15:32

    If you look at the documentation for the SetCursor function, setting the cursor to a NULL handle (e.g SetCursor(NULL)) will remove the cursor from the screen.

    0 讨论(0)
  • 2021-01-29 15:52

    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.

    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);
    

    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.

    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;
    

    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.

    0 讨论(0)
提交回复
热议问题