zoukankan      html  css  js  c++  java
  • 实现程序多长时间没有接受到用户的消息

     1   private void Form1_Load(object sender, EventArgs e)
     2         {
     3             System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
     4             t.Interval = 100;
     5             t.Tick += new EventHandler(t_Tick);
     6             t.Start();
     7         }
     8 
     9         void t_Tick(object sender, EventArgs e)
    10         {
    11             long time = GetLastInputTime();
    12             if (time > 1000)
    13             {
    14                 ((System.Windows.Forms.Timer)sender).Stop();
    15                 MessageBox.Show(time.ToString());
    16             }
    17         }
    18 
    19         [StructLayout(LayoutKind.Sequential)]
    20         struct LASTINPUTINFO
    21         {
    22             [MarshalAs(UnmanagedType.U4)]
    23             public int cbSize;
    24             [MarshalAs(UnmanagedType.U4)]
    25             public uint dwTime;
    26         }
    27 
    28         [DllImport("user32.dll")]
    29         static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
    30 
    31         static long GetLastInputTime()
    32         {
    33             LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
    34             vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
    35             if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
    36             return Environment.TickCount - (long)vLastInputInfo.dwTime;
    37         }
  • 相关阅读:
    紫书 例题8-6 UVa 1606(扫描法)
    紫书 例题8-5 UVa11054(等价转换)
    紫书 例题8-4 UVa 11134(问题分解 + 贪心)
    紫书 例题8-3 UVa 1152(中途相遇法)
    紫书 例题8-2 UVa 11605(构造法)
    Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
    2016ACM/ICPC亚洲区沈阳站
    Tenka1 Programmer Contest D
    [Gym-101512C] 凸包+最远点对
    ZOJ
  • 原文地址:https://www.cnblogs.com/sskset/p/669357.html
Copyright © 2011-2022 走看看