private static void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
        {
            if (_contextMenu != null)
            {
                _contextMenu.Close();
            }
            _contextMenu = new NotifyIconContextMenu(_toolViewModel);

            POINT p = new POINT();

            GetCursorPos(ref p);
            double x       = p.X;
            double y       = p.Y;
            var    w       = _contextMenu.Width;
            var    h       = _contextMenu.Height;
            var    scrInfo = DisplayDevices.GetCurrentScreenInfo(x, y);
            var    r       = scrInfo.WorkArea;

            if (w + x > r.Right)
            {
                x += r.Right - (w + x) + AppSettings.NotifyIconContextMenuDx;
            }
            if (h + y > r.Bottom)
            {
                y += r.Bottom - (h + y) + AppSettings.NotifyIconContextMenuDy;
            }
            _contextMenu.Left = x;
            _contextMenu.Top  = y;
#if alldbg || dbg
            DesktopPanelTool.Lib.Debug.WriteLine($"scr={scrInfo}");
            DesktopPanelTool.Lib.Debug.WriteLine($"x={x} y={y} w={w} h={h}");
#endif
            _contextMenu.Show();
        }
        /// <summary>
        /// first run new settings
        /// </summary>
        internal static void InitializeDefaultSettings()
        {
            var panel = AddDesktopPanel(null, DockName.None);

            panel.ViewModel.Title = "dock 1";

            var widget1 = new WidgetControl();

            widget1.ViewModel.Title = "widget 1";
            widget1.AutoSizableElementViewModel.WidthSizeMode  = SizeMode.MaximizedResizable;
            widget1.AutoSizableElementViewModel.HeightSizeMode = SizeMode.Auto;
            panel.ViewModel.AddWidget(widget1);

            var widget2 = new WidgetControl();

            widget2.ViewModel.Title       = "widget 2";
            widget2.ViewModel.HasSettings = false;
            widget2.AutoSizableElementViewModel.WidthSizeMode  = SizeMode.Auto;
            widget2.AutoSizableElementViewModel.HeightSizeMode = SizeMode.AutoResizable;
            panel.ViewModel.AddWidget(widget2);

            var widget3 = new WidgetControl();

            widget3.ViewModel.Title = "widget 3";
            widget3.AutoSizableElementViewModel.WidthSizeMode  = SizeMode.MaximizedResizable;
            widget3.AutoSizableElementViewModel.HeightSizeMode = SizeMode.MaximizedResizable;
            panel.ViewModel.AddWidget(widget3);

            var scr = DisplayDevices.GetCurrentScreenInfo();
            var x   = (scr.WorkArea.Width - panel.Width) / 2d;
            var y   = (scr.WorkArea.Height - panel.Height) / 2d;

            panel.Left = x;
            panel.Top  = y;
        }
Ejemplo n.º 3
0
        BatchTaskEventArgs GetBatchTaskEventArgs()
        {
            BatchTaskEventArgs evargs = new BatchTaskEventArgs();

            evargs.currentAccount = AccountManager.Instance.CurrentAccount;
            evargs.Devices        = DisplayDevices.ToList();
            return(evargs);
        }
Ejemplo n.º 4
0
        public DockablePanelWindowBehavior()
        {
            ScreenInfos = DisplayDevices.GetScreensInfos();
#if alldbg || dbg
            foreach (var scr in ScreenInfos)
            {
                DesktopPanelTool.Lib.Debug.WriteLine(scr);
            }
#endif
        }
Ejemplo n.º 5
0
        public string GetDisplayDeviceList()
        {
            string temp = "";
            List <DisplayDevice> pvr = DisplayDevices.EnumerateDevices().ToList();

            foreach (var dd in pvr)
            {
                temp += dd + " \n";
            }

            return(temp);
            //return hidDevices.GetType().FullName;
            //DisplayDevices.EnumerateDevices().ToList();
        }
 public void AttachToDock(
     DockName dock,
     ScreenInfo dockScreen = null)
 {
     if (dockScreen == null)
     {
         dockScreen = DisplayDevices
                      .GetScreensInfos()
                      .Where(x => x.IsPrimary)
                      .FirstOrDefault();
     }
     if (dockScreen != null)
     {
         _behavior.AttachToDock(dock, dockScreen);
     }
 }
Ejemplo n.º 7
0
        private void ThemeDialog_Load(object sender, EventArgs e)
        {
            previewer           = new WPF.ThemePreviewer();
            previewerHost.Child = previewer;

            listView1.ContextMenuStrip   = contextMenuStrip1;
            listView1.ListViewItemSorter = new CompareByItemText();
            SetWindowTheme(listView1.Handle, "Explorer", null);

            ImageList imageList = new ImageList();

            imageList.ColorDepth = ColorDepth.Depth32Bit;
            Size thumbnailSize = ThemeThumbLoader.GetThumbnailSize(this);

            imageList.ImageSize      = thumbnailSize;
            listView1.LargeImageList = imageList;

            imageList.Images.Add(ThemeThumbLoader.ScaleImage(windowsWallpaper, thumbnailSize));
            listView1.Items.Add(_("None"), 0);

            string[] displayNames = DisplayDevices.GetAllMonitorsFriendlyNames().ToArray();
            for (int i = 0; i < displayNames.Length; i++)
            {
                displayComboBox.Items.Add(string.Format(_("Display {0} - {1}"), i + 1, displayNames[i]));
            }
            displayComboBox.Enabled       = UwpDesktop.IsMultiDisplaySupported();
            displayComboBox.SelectedIndex = 0;

            string activeTheme = ThemeManager.currentTheme?.themeId;

            if (!JsonConfig.IsNullOrEmpty(JsonConfig.settings.multiDisplayThemes))
            {
                displayComboBox.SelectedIndex = 1;
                activeTheme = JsonConfig.settings.multiDisplayThemes[0];
            }
            else if (activeTheme == null && (JsonConfig.firstRun || JsonConfig.settings.themeName != null))
            {
                activeTheme = "Mojave_Desert";
            }

            Task.Run(new Action(() =>
                                LoadThemes(ThemeManager.themeSettings, (activeTheme != null) ? activeTheme : "")));
        }
Ejemplo n.º 8
0
    private static Monitor ParseMonitor(IntPtr monitorHandle, IntPtr hdc)
    {
        var info = new MonitorInfoEx(); //TODO: MonitorInfo not getting filled with data.
        var a    = User32.GetMonitorInfo(new HandleRef(null, monitorHandle), info);

        var name = new string(info.szDevice).TrimEnd((char)0);

        var monitor = new Monitor
        {
            Handle       = monitorHandle,
            Name         = name,
            FriendlyName = name,
            NativeBounds = new Rect(info.rcMonitor.Left, info.rcMonitor.Top,
                                    info.rcMonitor.Right - info.rcMonitor.Left,
                                    info.rcMonitor.Bottom - info.rcMonitor.Top),
            Bounds = new Rect(info.rcMonitor.Left, info.rcMonitor.Top,
                              info.rcMonitor.Right - info.rcMonitor.Left,
                              info.rcMonitor.Bottom - info.rcMonitor.Top),
            WorkingArea = new Rect(info.rcWork.Left, info.rcWork.Top,
                                   info.rcWork.Right - info.rcWork.Left,
                                   info.rcWork.Bottom - info.rcWork.Top),
            IsPrimary = (info.dwFlags & Constants.MonitorinfoPrimary) != 0
        };

        #region Extra details

        try
        {
            var display = new DisplayDevices(true);

            for (uint id = 0; User32.EnumDisplayDevices(null, id, ref display, 0); id++)
            {
                var found   = display.DeviceName == monitor.Name;
                var adapter = display.DeviceString;

                User32.EnumDisplayDevices(display.DeviceName, id, ref display, 0);

                if (!found)
                {
                    continue;
                }

                monitor.AdapterName  = adapter;
                monitor.FriendlyName = string.IsNullOrWhiteSpace(display.DeviceString) ? LocalizationHelper.Get("S.Recorder.Screen.Name.Internal") :
                                       display.DeviceString == "Generic PnP Monitor" ? LocalizationHelper.Get("S.Recorder.Screen.Name.Generic") : display.DeviceString;
                break;
            }
        }
        catch (Exception ex)
        {
            LogWriter.Log(ex, "Impossible to get extra details of screen.");
        }

        #endregion

        #region Screen DPI

        try
        {
            ShCore.GetDpiForMonitor(monitorHandle, DpiTypes.Effective, out var aux, out _);
            monitor.Dpi = aux > 0 ? (int)aux : 96;
        }
        catch (Exception ex)
        {
            LogWriter.Log(ex, "Impossible to detect screen DPI.");

            try
            {
                var h = Gdi32.CreateCompatibleDC(IntPtr.Zero);
                monitor.Dpi = Gdi32.GetDeviceCaps(h, (int)DeviceCaps.LogPixelsX);
                Gdi32.DeleteDC(h);
            }
            catch (Exception e)
            {
                LogWriter.Log(e, "Error getting fallback of screen DPI.");
            }
        }

        #endregion

        return(monitor);
    }
Ejemplo n.º 9
0
 internal static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DisplayDevices lpDisplayDevices, uint dwFlags);
 public void Execute()
 {
     DisplayDevices.TurnOff();
     Application.SetSuspendState(PowerState.Hibernate, true, true);
 }
Ejemplo n.º 11
0
 public FormDisplay()
 {
     devices     = new DisplayDevices();
     monitorMode = new MonitorMode();
     InitializeComponent();
 }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            //SetDisplayMode(DisplayMode.Duplicate);
            //SetDisplayMode(DisplayMode.Extend);
            //Display display = new Display();
            //List<DevMode> modes = display.GetDisplaySettings();
            //Console.WriteLine("Develop mode");
            Dictionary <string, string> values = new Dictionary <string, string>();

            values.Add("key", "value");
            values.Add("key2", "value2");

            string output = JsonConvert.SerializeObject(values);

            Console.WriteLine(output);
            //Newtonsoft.Json.Serialization.

            DisplayDevices display = new DisplayDevices();

            display.SetupDisplay();
            var allDisplays = display.GetActiveDisplayDevices();

            //List<DisplayDevice> devices = new List<DisplayDevice>();

            //bool error = false;
            //////Here I am listing all DisplayDevices (Monitors)
            //for (int devId = 0; !error; devId++)
            //{
            //    try
            //    {
            //        DisplayDevice device = new DisplayDevice();
            //        device.cb = Marshal.SizeOf(typeof(DisplayDevice));
            //        error = NativeMethods.EnumDisplayDevicesW(null, devId, ref device, 0) == 0;
            //        devices.Add(device);
            //    }
            //    catch (Exception)
            //    {
            //        error = true;
            //    }
            //}
            //List<string> monitors = new List<String>();
            //monitors.Add(@"\\.\DISPLAY1");
            //monitors.Add(@"\\.\DISPLAY2");

            //List<DisplaySet> devicesAndModes = new List<DisplaySet>();
            //Dictionary<DisplayDevice, List<DevMode>> devs = new Dictionary<DisplayDevice, List<DevMode>>();
            //foreach (var device in devices)
            //{
            //    error = false;
            //    for (int i = 0; !error; i++)
            //    {
            //        try
            //        {
            //            DevMode mode = new DevMode();
            //            //-1 get's the current display setting
            //            error = NativeMethods.EnumDisplaySettings(device.DeviceName, -1 + i, ref mode) == 0;
            //            if (!error)
            //            {
            //                if (!devs.Keys.Contains(device))
            //                {
            //                    devs.Add(device, new List<DevMode>());
            //                }

            //                if (!devs[device].Where(m => m.dmPelsWidth == mode.dmPelsWidth && m.dmPelsHeight == mode.dmPelsHeight && m.dmDeviceName == mode.dmDeviceName && m.dmDisplayFrequency == mode.dmDisplayFrequency && m.dmBitsPerPel == mode.dmBitsPerPel).Any())
            //                {
            //                    Console.WriteLine(string.Format("{0}: {1}x{2} {3}hz", device.DeviceName, mode.dmPelsWidth, mode.dmPelsHeight, mode.dmDisplayFrequency));
            //                    devs[device].Add(mode);
            //                }
            //                //devicesAndModes.Add(new DisplaySet { DisplayDevice = device, DevMode = mode });
            //            }
            //        }
            //        catch (Exception ex)
            //        {
            //            error = false;
            //        }
            //    }
            //}

            //foreach (var dev in devices)
            //{
            //    error = false;
            //    //Here I am listing all DeviceModes (Resolutions) for each DisplayDevice (Monitors)
            //    for (int i = 0; !error; i++)
            //    {
            //        try
            //        {
            //            //DeviceMode is a wrapper. You can find it [here](http://pinvoke.net/default.aspx/Structures/DEVMODE.html)
            //            DevMode mode = new DevMode();
            //            error = NativeMethods.EnumDisplaySettings(null, -1 + i, ref mode) == 0;
            //            //error = NativeMethods.EnumDisplaySettings(dev.DeviceName, -1 + i, ref mode) == 0;
            //            //Display
            //            //DisplayDevice test = dev;
            //            //DevMode testMode = mode;
            //            devicesAndModes.Add(new DisplaySet { DisplayDevice = dev, DevMode = mode });
            //            var info = mode.GetInfoArray();
            //            Console.WriteLine("Just another line");
            //        }
            //        catch (Exception ex)
            //        {
            //            error = true;
            //        }
            //    }
            //}

            //Select any 800x600 resolution ...
            //DevMode d800x600 = devicesAndModes.Where(s => s.DevMode.dmPelsWidth == 800).FirstOrDefault().DevMode;//.First().DevMode;
            //List<DisplaySet> d800x600Sets = devicesAndModes.Where(s => s.DevMode.dmPelsWidth == 800).ToList();
            //DisplaySet set = devicesAndModes.Where(s => s.DevMode.dmPelsWidth == 1920).FirstOrDefault();
            //IntPtr ptr = new IntPtr();

            //var code = NativeMethods.ChangeDisplaySettingsEx(set.DisplayDevice.DeviceName, ref set.DevMode, ptr, 0, ptr);
            //NativeMethods.ChangeDisplaySettingsExW(set.DisplayDevice.DeviceName, ref set.DevMode, null, 0, null);
            //NativeMethods.ChangeDisplaySettings(ref d800x600, 0);
            //DevMode devmode = new DevMode();
            //int iModeNum = NativeMethods.ENUM_CURRENT_SETTINGS;

            //var deviceName = devices[3].DeviceName;

            //int value = NativeMethods.EnumDisplaySettings(deviceName, iModeNum, ref devmode);

            //return NativeMethods.EnumDisplaySettings(null, iModeNum, ref devmode);
            ////Select any 800x600 resolution ...
            //DeviceMode d800x600 = devicesAndModes.Where(s => s.DeviceMode.dmPelsWidth == 800).First().DeviceMode;

            ////Apply the selected resolution ...
            //ChangeDisplaySettings(ref d800x600, 0);

            Console.WriteLine($"Display count {allDisplays.Count}");
            Console.ReadLine();
            Console.WriteLine("Device");
        }