java程序中隐藏光标隐藏光标_在特定时间间隔后隐藏和显示鼠标光标

如果我的系统鼠标没有移动,我想在5秒后隐藏我的鼠标 . 我问过这个问题check mouse activity

现在我可以检查鼠标的活动并更改光标...我的代码是:

#define WINDOWS_LEAN_AND_MEAN

#include

#include

#include

#include

#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(),因为它将从文件中读取而不是从我的版本中会产生问题的资源中读取 . 请分享您的经验..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值