系统设置
显示器 在不使用的时候5分钟后 关闭。
程序 设置如下:
控制台程序 调用 Dll,Dll内有一个Form窗体 
重载 wndproc 方法,监测 显示器状态。现在问题是 如果焦点不在Form窗体的时候
无法监测到显示器状态变化,如果焦点在Form窗体
的时候 则可以监控。
有什么办法 可以让焦点在 Console窗体的时候,
Form也运行的时候,还可以监测到显示器的状态么?

解决方案 »

  1.   

    重载 wndproc 方法,监测 显示器状态。
      

  2.   

    重写应该是,Windows提供了这个接口。
      

  3.   


    重载我知道
    检测呢?
    用哪些API?显示器 在不使用的时候5分钟后 关闭你不会在wndproc 里判断鼠标键盘没有使用吧?
      

  4.   

    wndproc哭着说,我没有特异功能。
      

  5.   

    using System;
    using System.Runtime.InteropServices;
    using System.Threading;namespace ConsoleApplication1
    {
        class Program
        {
            [DllImport("user32.dll")]
            static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);        [StructLayout(LayoutKind.Sequential)]
            struct LASTINPUTINFO
            {
                public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO));            [MarshalAs(UnmanagedType.U4)]
                public UInt32 cbSize;
                [MarshalAs(UnmanagedType.U4)]
                public UInt32 dwTime;
            }        static uint GetLastInputTime()
            {
                uint idleTime = 0;
                LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
                lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo);
                lastInputInfo.dwTime = 0;            uint envTicks = (uint)Environment.TickCount;            if (GetLastInputInfo(ref lastInputInfo))
                {
                    uint lastInputTick = lastInputInfo.dwTime;                idleTime = envTicks - lastInputTick;
                }            return idleTime;
            }        static void Main(string[] args)
            {
                while (true)
                {
                    Console.WriteLine(String.Format("鼠标键盘空闲时间 {0} 毫秒", GetLastInputTime()));
                    Thread.Sleep(300);
                }            Console.ReadKey();
            }
        }
    }
      

  6.   

    什么意思,wndproc实现不了这个需求?