windows程序自动锁屏功能的实现
来源:互联网 发布:做淘宝客要交钱吗 编辑:程序博客网 时间:2024/06/05 03:34
这个问题来自论坛提问
Q:当我登录进入主界面时,在规定的时间内没有做任何操作,系统就注销(就像电脑的屏保)。
A: 其实很简单,参考一个api函数就可以了:GetLastInputInfo,以下是参考代码
演示程序在你10秒内没有任何鼠标键盘活动既最小化,最小化后晃动鼠标即可复原
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication28
... {
public partial class Form1 : Form
... {
[StructLayout(LayoutKind.Sequential)]
public struct LASTINPUTINFO
... {
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public uint dwTime;
}
[DllImport( " user32.dll " )]
public static extern bool GetLastInputInfo( ref LASTINPUTINFO plii);
public long getIdleTick()
... {
LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
if ( ! GetLastInputInfo( ref vLastInputInfo)) return 0 ;
return Environment.TickCount - ( long )vLastInputInfo.dwTime;
}
public Form1()
... {
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e)
... {
this .timer1.Interval = 2000 ;
this .timer1.Enabled = true ;
}
private void timer1_Tick( object sender, EventArgs e)
... {
long i = getIdleTick();
this .Text = string .Format( " jinjazz说:您已经{0}ms没有动了 " ,i);
if (i > 10 * 1000 )
... {
this .WindowState = FormWindowState.Minimized;
}
else
... {
this .WindowState = FormWindowState.Normal;
}
}
}
}
- windows程序自动锁屏功能的实现
- windows程序自动锁屏功能的实现
- 使用Windows服务实现投票结果的自动发送功能
- Windows Phone 7自动登录功能的实现方法
- 2005中ClickOnce实现程序的自动升级功能。
- ASP 程序实现自动升级功能
- 自动播放功能的实现
- 自动登录功能的实现
- Windows中实现定时自动运行程序
- Windows中实现定时自动运行程序
- 6.8 程序锁功能的实现
- 87程序锁的功能实现
- Android:程序锁功能的简单实现
- 禁用Windows XP的自动播放功能
- Windows 7的自动寻找驱动功能
- 禁用Windows系统的自动播放功能
- 关闭Windows XP的“自动播放”功能
- 关于windows的自动登录功能--autoadminlogon
- java.awt.Robot
- dedecms 静态化设置
- iframe中获得父页面的值
- 关于BIEE的Answer中使用unin。
- 设置EXCEL的默认打印机
- windows程序自动锁屏功能的实现
- [项目问题跟踪管理软件].JIRA.Enterprise.Edition.V3.13.4 安装
- 2.9 学习态度
- 03 与 07 多用户 的部署区别
- System.Data.DataTable计算功能详解
- 关于BIEE中提示器的使用技巧
- 8051、ARM和DSP指令周期的测试与分析
- 真心求助
- 过年了