如果我的系统鼠标没有移动,我想在5秒后隐藏我的鼠标。我问了这个问题check mouse activity
现在我可以检查鼠标的活动并更改光标了... 我的代码是:
#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();
}
这段代码可以改变我的游标但是如果我得到了箭头光标,那么它在繁忙的光标中会发生变化。 我可以看到SetSystemCursor无法正常工作,我无法更改光标图像。 我想在10秒或5秒后用空白光标替换光标,然后在鼠标移动时它变成箭头。
问题:箭头光标变忙,隐藏工作正常。 我不能使用LoadCursorFromFile(),因为它将从文件中读取而不是从我的版本中会产生问题的资源中读取。 请分享您的经验..