问题
I want to hide my mouse after 5 seconds if my system mouse is not moved. I asked in this question check mouse activity
Now I'm able to check the activity of mouse and change cursor ... My code is:
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#include <io.h>
#include <iostream>
#include <ctime>
#include "resource.h"
HCURSOR hCurBlank;
HCURSOR hCurstandard;
void blank_cursor()
{
hCurBlank = LoadCursor(NULL, MAKEINTRESOURCE(IDC_CURSOR1)); //loading a cursor from a file
HCURSOR hcCopyblnkcur = CopyCursor(hCurBlank);
BOOL bret= SetSystemCursor( hcCopyblnkcur, 32512); //will set the cursor by using load cursor from file
}
void default_cursor()
{
hCurstandard = LoadCursor(NULL, MAKEINTRESOURCE(IDC_CURSOR2));
HCURSOR hcursdef = CopyCursor(hCurstandard);
HCURSOR hCurStandard = GetCursor();
//SetCursor(hCurstandard);
BOOL brets =SetSystemCursor( hcursdef, 32512);
}
void determine_idle_time()
{
LASTINPUTINFO lif; //Typedef for last input info will result in cb and dwtime
lif.cbSize = sizeof(LASTINPUTINFO);
DWORD tickCount, idleCount; // Double word value
for (;;)
{
GetLastInputInfo(&lif); //It will check the system's last activity module
tickCount = GetTickCount(); //GetTickCount will get the time from which system has been started and will be continue
//upto 49 days
idleCount = (tickCount - lif.dwTime) / 1000; //This will return the time in the seconds. It will check for
//starting time and the last input info time. so the last activity time will be returned
std::cout<< "Idle time: " << idleCount << " seconds." << std::endl;
// Sleep for some milliseconds before the next output.
DWORD randomized_time = rand() % (800 - 600 + 1) + 10; //rand()%(800-300+1) + 300;
//rand will pick any random value and this will generate a double value
Sleep(randomized_time);
//Sleep(500);
if(idleCount>10)
{
blank_cursor();
}
else
{
default_cursor();
}
}
}
int main() {
srand(unsigned(time(NULL)));
determine_idle_time();
}
This code can change my cursors but If I'm getting the arrow cursor, It's changing in busy cursor. I can see that SetSystemCursor is not working properly, with which I'm unable to change the cursor image. I want to replace my cursor with a blank cursor after 10 seconds or 5 second and then on mouse move it becomes arrow.
problem: Arrow cursor becomes busy and hide is working fine. I can't use LoadCursorFromFile() because It'll read from file not from resource that will create a problem in my release. Please share your experience..
来源:https://stackoverflow.com/questions/20655350/hide-and-show-mouse-cursor-after-a-particular-interval-of-time