我想做一个类似屏保的程序,如何判断鼠标的静止时间,比如鼠标不动,timer开始计时,到时间就出现一个全黑的form(我把它当作屏保了,呵呵),点击就退出.我遇到的困难是,如何判断鼠标静止不动,如果动了的话就重新计时?
解决方案 »
- DataGridView不绑定数据源情况下的 高难度问题!重金悬赏
- DataGridView 底部添加合计行后,怎样才能使垂直滚动条滚动到最后时,最后一行不被合计行遮挡?
- vs2008 一個解決方案加載項目數量有上限么? 谁能解惑100分相送
- 求救~大侠帮忙!
- 報表
- 在mdi 窗体中,子窗体如何访问父窗体的迭件,如statubar
- 请教:从任意位置直接退出整个程序用哪个?return?谢谢!
- 急、急、急!哪位应用过CompactFramework在windows ce上的请进.
- 谁有Cristal Report 的注册码?重分送上!!!!!!!!!!!!!!
- Could you send me microsoft win2k advanced server CDKEY。 I will learn C#
- C# 跨窗体传值问题!
- 咨询
{
private static Boolean lockState = false;//保存当前的锁定状态
private static System.Windows.Forms.Timer appTimer = new Timer(); //计时器
private static int iTimeLen = 0; //时间计数
public Form1()
{
InitializeComponent();
RegisterAppLockProcess();
}
/// <summary>
/// 注册应用程序的锁定处理
/// </summary>
private static void RegisterAppLockProcess()
{
appTimer.Interval = 1000; //每间隔一秒执行一次检查
appTimer.Tick += new EventHandler(CheckLockState); appTimer.Start(); LockMessager lm = new LockMessager(); Application.AddMessageFilter(lm);
} /// <summary>
/// 循环检查锁定状态
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void CheckLockState(object sender, EventArgs e)
{ if (lockState) return; iTimeLen = iTimeLen + 1; //当五秒内没有接收到鼠标和键盘的按键,则进行锁定
if (iTimeLen >= 5)
{
//LockProcess(); ShowLockWindow(); lockState = true;
}
} /// <summary>
/// 显示锁定后的界面
/// </summary>
private static void ShowLockWindow()
{
//这里简单显示出锁定后的界面
Form2 frmLock = new Form2();
frmLock.Show();
}
internal class LockMessager : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
//如果检测到有鼠标或则键盘被按下的消息,则使计数为0.....
if (m.Msg == 0x0201 || m.Msg == 0x0100 || m.Msg == 0x0204 || m.Msg == 0x0207 || m.Msg == 0x0216)
iTimeLen = 0; return false;
}
}
internal class LockMessager : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{ //如果检测到有鼠标或则键盘被按下的消息,则使计数为0.....
if (m.Msg == 0x0201 || m.Msg == 0x0100 || m.Msg == 0x0204 || m.Msg == 0x0207 || m.Msg == 0x0216)
{
lockState = false;
iTimeLen = 0;
}
return false;
}
}
在你点击鼠标的时候把lockState状态重置成false,不然每次到time时间里面总是return
能详细点吗?