Example #1
0
        public static bool IsMonitorOn()
        {
            //return false;
            try
            {
                IntPtr handle = Win32Helper.GetForegroundWindow();

                bool          IsNonZeroHandle = IntPtr.Zero != handle;
                int           nchars          = 255;
                StringBuilder Buff            = new StringBuilder(nchars);

                if (IsNonZeroHandle && Win32Helper.GetWindowText(handle, Buff, nchars) > 0)
                {
                    string title = Buff.ToString();
                    Trace.WriteLine($"Win32Helper.GetForegroundWindow():{handle} title:{title}");
                }

                return(IsNonZeroHandle);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                return(false);
            }
        }