示例#1
0
        private NativeStructures.PHYSICAL_MONITOR[] getMonitors()
        {
            WindowInteropHelper helper = new WindowInteropHelper(this);

            // Get the right monitor
            NativeStructures.tagPOINT right = new NativeStructures.tagPOINT();
            right.x = 2000;
            right.y = 0;
            //IntPtr hMonitor = NativeMethods.MonitorFromWindow(helper.Handle, NativeConstants.MONITOR_DEFAULTTONULL);
            IntPtr hMonitor       = NativeMethods.MonitorFromPoint(right, NativeConstants.MONITOR_DEFAULTTONULL);
            int    lastWin32Error = Marshal.GetLastWin32Error();

            uint pdwNumberOfPhysicalMonitors          = 0u;
            bool numberOfPhysicalMonitorsFromHmonitor = NativeMethods.GetNumberOfPhysicalMonitorsFromHMONITOR(
                hMonitor, ref pdwNumberOfPhysicalMonitors);

            lastWin32Error = Marshal.GetLastWin32Error();

            NativeStructures.PHYSICAL_MONITOR[] pPhysicalMonitorArray =
                new NativeStructures.PHYSICAL_MONITOR[pdwNumberOfPhysicalMonitors];
            bool physicalMonitorsFromHmonitor = NativeMethods.GetPhysicalMonitorsFromHMONITOR(
                hMonitor, pdwNumberOfPhysicalMonitors, pPhysicalMonitorArray);

            lastWin32Error = Marshal.GetLastWin32Error();

            return(pPhysicalMonitorArray);
        }
示例#2
0
        public Monitor(NativeStructures.PHYSICAL_MONITOR physicalMonitor)
        {
            HPhysicalMonitor = physicalMonitor.hPhysicalMonitor;
            Name             = physicalMonitor.szPhysicalMonitorDescription;

            Brightness.IsSupported = NativeMethods.GetMonitorBrightness(HPhysicalMonitor, ref Brightness.Min, ref Brightness.Current, ref Brightness.Max);
            Brightness.Original    = Brightness.Current;
        }
        public bool Add(IntPtr hMonitor)
        {
            uint monitorCount = 0;

            NativeMethods.GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref monitorCount);
            if (monitorCount <= 0)
            {
                return(false);
            }

            var monitorArray = new NativeStructures.PHYSICAL_MONITOR[monitorCount];

            NativeMethods.GetPhysicalMonitorsFromHMONITOR(hMonitor, monitorCount, monitorArray);

            /*
             * Parallel.ForEach(monitorArray, (physicalMonitor) =>
             * {
             * Monitor newMonitor = new Monitor(physicalMonitor);
             *
             * this.Add(newMonitor);
             * });
             */

            foreach (var physicalMonitor in monitorArray)
            {
                Monitor newMonitor = new Monitor(physicalMonitor);
                this.Add(newMonitor);
            }
            ;

            /*
             * Debug.Write("\n\nStart Add");
             *
             * Stopwatch stopWatch = new Stopwatch();
             * stopWatch.Start();
             *
             * stopWatch.Stop();
             * TimeSpan ts = stopWatch.Elapsed;
             *
             * Debug.Write("Checking duration: " + ts.ToString() + "\n");
             */

            return(true);
        }
示例#4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            WindowInteropHelper helper = new WindowInteropHelper(this);

            IntPtr hMonitor       = NativeMethods.MonitorFromWindow(helper.Handle, NativeConstants.MONITOR_DEFAULTTOPRIMARY);
            int    lastWin32Error = Marshal.GetLastWin32Error();

            uint pdwNumberOfPhysicalMonitors          = 0u;
            bool numberOfPhysicalMonitorsFromHmonitor = NativeMethods.GetNumberOfPhysicalMonitorsFromHMONITOR(
                hMonitor, ref pdwNumberOfPhysicalMonitors);

            lastWin32Error = Marshal.GetLastWin32Error();

            NativeStructures.PHYSICAL_MONITOR[] pPhysicalMonitorArray =
                new NativeStructures.PHYSICAL_MONITOR[pdwNumberOfPhysicalMonitors];
            bool physicalMonitorsFromHmonitor = NativeMethods.GetPhysicalMonitorsFromHMONITOR(
                hMonitor, pdwNumberOfPhysicalMonitors, pPhysicalMonitorArray);

            lastWin32Error = Marshal.GetLastWin32Error();

            uint pdwMonitorCapabilities        = 0u;
            uint pdwSupportedColorTemperatures = 0u;
            var  monitorCapabilities           = NativeMethods.GetMonitorCapabilities(
                pPhysicalMonitorArray[0].hPhysicalMonitor, ref pdwMonitorCapabilities, ref pdwSupportedColorTemperatures);

            lastWin32Error = Marshal.GetLastWin32Error();

            NativeStructures.MC_DISPLAY_TECHNOLOGY_TYPE type =
                NativeStructures.MC_DISPLAY_TECHNOLOGY_TYPE.MC_SHADOW_MASK_CATHODE_RAY_TUBE;
            var monitorTechnologyType = NativeMethods.GetMonitorTechnologyType(
                pPhysicalMonitorArray[0].hPhysicalMonitor, ref type);

            lastWin32Error = Marshal.GetLastWin32Error();

            var destroyPhysicalMonitors = NativeMethods.DestroyPhysicalMonitors(
                pdwNumberOfPhysicalMonitors, pPhysicalMonitorArray);

            lastWin32Error = Marshal.GetLastWin32Error();

            this.lbl.Content = type;
        }
示例#5
0
        public bool Add(IntPtr hMonitor)
        {
            uint monitorCount = 0;

            NativeMethods.GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref monitorCount);
            if (monitorCount <= 0)
            {
                return(false);
            }

            var monitorArray = new NativeStructures.PHYSICAL_MONITOR[monitorCount];

            NativeMethods.GetPhysicalMonitorsFromHMONITOR(hMonitor, monitorCount, monitorArray);

            foreach (var physicalMonitor in monitorArray)
            {
                Monitor newMonitor = new Monitor(physicalMonitor);

                this.Add(newMonitor);
            }
            return(true);
        }
        private static uint GetMonitorHandleMinMaxCurBirghtness(
            out NativeStructures.PHYSICAL_MONITOR[] pPhysicalMonitorArray,
            out uint pdwMinimumBrightness,
            out uint pdwCurrentBrightness,
            out uint pdwMaximumBrightness)
        {
            var hMonitor = NativeMethods.MonitorFromWindow(
                NativeMethods.GetDesktopWindow(),
                NativeConstants.MONITOR_DEFAULTTOPRIMARY);

            var pdwNumberOfPhysicalMonitors = 0u;
            var numberOfPhysicalMonitorsFromHmonitor = NativeMethods.GetNumberOfPhysicalMonitorsFromHMONITOR(
                hMonitor,
                ref pdwNumberOfPhysicalMonitors);
            if (!numberOfPhysicalMonitorsFromHmonitor)
                throw new Win32Exception(Marshal.GetLastWin32Error());

            pPhysicalMonitorArray = new NativeStructures.PHYSICAL_MONITOR[pdwNumberOfPhysicalMonitors];
            var physicalMonitorsFromHmonitor = NativeMethods.GetPhysicalMonitorsFromHMONITOR(
                hMonitor,
                pdwNumberOfPhysicalMonitors,
                pPhysicalMonitorArray);
            if (!physicalMonitorsFromHmonitor)
                throw new Win32Exception(Marshal.GetLastWin32Error());

            pdwMinimumBrightness = 0u;
            pdwCurrentBrightness = 0u;
            pdwMaximumBrightness = 0u;
            var getMonitorBrightness = NativeMethods.GetMonitorBrightness(
                pPhysicalMonitorArray[0].hPhysicalMonitor,
                ref pdwMinimumBrightness,
                ref pdwCurrentBrightness,
                ref pdwMaximumBrightness);
            if (!getMonitorBrightness)
                throw new Win32Exception(Marshal.GetLastWin32Error());
            return pdwNumberOfPhysicalMonitors;
        }
示例#7
0
        public bool Add(IntPtr hMonitor)
        {
            bool retVal       = false;
            uint monitorCount = 0;

            if (NativeMethods.GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref monitorCount))
            {
                var monitorArray = new NativeStructures.PHYSICAL_MONITOR[monitorCount];
                NativeMethods.GetPhysicalMonitorsFromHMONITOR(hMonitor, monitorCount, monitorArray);

                NativeStructures.MonitorInfoEx mInfo = new NativeStructures.MonitorInfoEx();
                for (int i = 0; i < monitorArray.Length; i++)
                //foreach (var physicalMonitor in monitorArray)
                {
                    var physicalMonitor = monitorArray[i];
                    NativeMethods.GetMonitorInfo(hMonitor, ref mInfo);
                    Monitor newMonitor = new Monitor(physicalMonitor);

                    ml.Add(newMonitor);
                }
                retVal = true;
            }
            return(retVal);
        }
示例#8
0
 public Monitor(NativeStructures.PHYSICAL_MONITOR physicalMonitor)
 {
     HPhysicalMonitor = physicalMonitor.hPhysicalMonitor;
     Name             = physicalMonitor.szPhysicalMonitorDescription;
     //CheckCapabilities();
 }