#region 锁屏
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 ;
return Environment.TickCount - (long)vLastInputInfo.dwTime;
}
private void timer2_Tick(object sender, EventArgs e)
{
long i = getIdleTick() / ;
if (i > )//(i > 10 * 1000)//超过一分钟
{
suoping();
}
}
private void butsp_Click(object sender, EventArgs e)
{
suoping();
}
void suoping()
{
this.timer2.Enabled = false;
frmpassword frm = new frmpassword();
frm.ShowDialog();
if (frm.DialogResult == DialogResult.OK)
this.timer2.Enabled = true;
else
Application.ExitThread();
}
#endregion
05-23 13:09