ShowCursor(FALSE) does not work

点点圈 提交于 2019-12-03 04:01:30

You can use LoadImage() to achieve what you want. Here is the modified working version of the function UsingLoadImage() you quoted in the question. You have to include a cursor resource file to your visual studio project. Download the cursor from here or create your own.

Resource Files->Add->Existng Item and browse to the nocursor.cur file.

void UsingLoadImage()
{
    // Save a copy of the default cursor
    HANDLE arrowHandle = LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR, 0, 0, LR_SHARED);
    HCURSOR hcArrow = CopyCursor(arrowHandle);

    // Set the cursor to a transparent one to emulate no cursor
    HANDLE noCursorHandle = LoadImage(GetModuleHandle(NULL), L"nocursor.cur", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE); //worked
    //HANDLE noCursorHandle = LoadCursorFromFile(L"nocursor.cur"); //this also worked

    HCURSOR noCursor = CopyCursor(noCursorHandle);
    SetSystemCursor(noCursor, OCR_NORMAL);
    int i =0 ;
    while(i++<10)
    {
        cout<<i<<endl;
        Sleep(1000);
    }
    SetSystemCursor(hcArrow, OCR_NORMAL);
    DestroyCursor(hcArrow);
}

This would replace the normal arrow cursor with the transparent one. If you want to hide all the other cursor like the text, loading, hand cursors etc you have to hide them individually. If you don't want that to be the case, then you should opt out of the console application as many commenters have pointed out.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!