public DeskSet(int position, ConferenceAttendee attendee) { fPosition = position; fAttendee = attendee; // Desk Set Felt Pad // Bifold Monitor AABB boundary = new AABB(new NewTOAPIA.Vector3D(0.33f, 0.33f, 0.025f), new Point3D(0,1.025f,0)); fMonitor = new DisplayMonitor(attendee.Session.Model.GI, boundary, new Resolution(1024,768)); fMonitor.Rotate(-60, new float3(0, 1, 0)); fMonitor.Translate(new Vector3D(-0.50f, 0.05f, 0.5f)); // Create some viewers to receive images fDesktopViewer = new ReceivingTexture(attendee.Session.Model.GI, 620, 440); fWebcamViewer = new ReceivingTexture(attendee.Session.Model.GI, 352, 288); // Show the display on multiple monitors fMonitor.ImageSource = fWebcamViewer; attendee.Session.Model.Room.Whiteboard.ImageSource = fDesktopViewer; // Video Pedestal display // Whiteboard Pen Set AddChild(fMonitor); }
//Move mouse cursor to target void MoveMousePosition() { try { //Get the current active screen int monitorNumber = Convert.ToInt32(Setting_Load(vConfigurationCtrlUI, "DisplayMonitor")); DisplayMonitor displayMonitorSettings = GetSingleMonitorEnumDisplay(monitorNumber); //Calculate target mouse position int windowTop = (int)(this.Top * displayMonitorSettings.DpiScaleVertical); int windowLeft = (int)(this.Left * displayMonitorSettings.DpiScaleHorizontal); int windowWidth = (int)(this.ActualWidth * displayMonitorSettings.DpiScaleHorizontal); int windowHeight = (int)(this.ActualHeight * displayMonitorSettings.DpiScaleVertical); int targetWidth = windowLeft + (windowWidth / 2); int targetHeight = windowTop - 30; //Check if target is outside screen if (targetHeight < 0) { targetHeight = windowTop + windowHeight + 30; } if (targetWidth < 0) { targetWidth = 30; } else if (targetWidth > displayMonitorSettings.WidthNative) { targetWidth = displayMonitorSettings.WidthNative - 30; } //Move mouse cursor to target SetCursorPos(targetWidth, targetHeight); } catch { } }
//Launch a Win32 application from databindapp async Task <bool> PrepareProcessLauncherWin32Async(DataBindApp dataBindApp, string launchArgument, bool silent, bool allowMinimize, bool runAsAdmin, bool createNoWindow, bool launchKeyboard) { bool appLaunched = false; try { //Set the app title string appTitle = dataBindApp.Name; //Check the launch argument if (string.IsNullOrWhiteSpace(launchArgument)) { launchArgument = dataBindApp.Argument; } else { //Update the app title if (dataBindApp.Category == AppCategory.Emulator) { appTitle += " with rom"; } else if (dataBindApp.LaunchFilePicker) { appTitle += " with file"; } } //Chromium DPI launch argument string processName = Path.GetFileNameWithoutExtension(dataBindApp.PathExe); if (vCtrlChromiumBrowsers.Any(x => x.String1 == processName)) { //Get the current active screen int monitorNumber = Convert.ToInt32(Setting_Load(vConfigurationCtrlUI, "DisplayMonitor")); DisplayMonitor displayMonitorSettings = GetSingleMonitorEnumDisplay(monitorNumber); //Get the current screen dpi double screenDPI = displayMonitorSettings.DpiScaleHorizontal; double chromiumDPI = Convert.ToDouble(Setting_Load(vConfigurationCtrlUI, "AdjustChromiumDpi")); //Update the launch argument string stringDPI = (screenDPI + chromiumDPI).ToString(vAppCultureInfo); launchArgument += " -force-device-scale-factor=" + stringDPI; Debug.WriteLine("Chromium dpi scale factor: " + stringDPI); } //Launch the application appLaunched = await PrepareProcessLauncherWin32Async(appTitle, dataBindApp.PathExe, dataBindApp.PathLaunch, launchArgument, silent, allowMinimize, runAsAdmin, createNoWindow, launchKeyboard, false); //Update last launch date if (appLaunched) { dataBindApp.LastLaunch = DateTime.Now.ToString(vAppCultureInfo); //Debug.WriteLine("Updated last launch date: " + dataBindApp.LastLaunch); JsonSaveApplications(); } } catch { } return(appLaunched); }
private static void TrayIconUpdateMonitorIndexes() { int dropMenuCount = ((ToolStripMenuItem)TrayMenuIcons.Items[0]).DropDownItems.Count; if (dropMenuCount > 0) { int count = 0; while (count < dropMenuCount) { try { ((ToolStripMenuItem)TrayMenuIcons.Items[0]).DropDownItems.RemoveAt(0); } catch (Exception) { } count++; } } for (int i = 0; i < DisplayMonitor.EnumerateMonitors().Length; i++) { ((ToolStripMenuItem)TrayMenuIcons.Items[0]).DropDownItems.Add($"#{i}", Resources.television__arrow.ToBitmap(), OnChangeMonitor); } }
//Get single monitor information public static DisplayMonitor GetSingleMonitorDisplayConfig(int screenNumber) { try { //Query single monitor bool querySingleCheck = QuerySingleMonitorDisplayConfig(screenNumber, out DISPLAYCONFIG_PATH_INFO pathInfoTarget, out DISPLAYCONFIG_MODE_INFO modeInfoTarget); if (!querySingleCheck) { Debug.WriteLine("Failed getting displayconfig monitor information."); return(null); } //Create display monitor DisplayMonitor displayMonitorSettings = new DisplayMonitor(); displayMonitorSettings.Identifier = screenNumber; //Get the screen name string monitorName = GetMonitorFriendlyName(pathInfoTarget.targetInfo.adapterId, pathInfoTarget.targetInfo.id); if (monitorName != "Unknown") { monitorName = monitorName + " (" + pathInfoTarget.targetInfo.id + ")"; } displayMonitorSettings.Name = monitorName; //Get the device path displayMonitorSettings.DevicePath = GetMonitorDevicePath(pathInfoTarget.targetInfo.adapterId, pathInfoTarget.targetInfo.id); //Get the screen dpi scale displayMonitorSettings.DpiScaleHorizontal = (float)GetMonitorDpiScale(pathInfoTarget.targetInfo.adapterId, pathInfoTarget.sourceInfo.id) / (float)100; displayMonitorSettings.DpiScaleVertical = displayMonitorSettings.DpiScaleHorizontal; //Get the screen resolution displayMonitorSettings.WidthNative = modeInfoTarget.sourceMode.position.y; displayMonitorSettings.HeightNative = modeInfoTarget.desktopImageInfo.PathSourceSize.x; displayMonitorSettings.WidthDpi = (int)(displayMonitorSettings.WidthNative / displayMonitorSettings.DpiScaleHorizontal); displayMonitorSettings.HeightDpi = (int)(displayMonitorSettings.HeightNative / displayMonitorSettings.DpiScaleVertical); //Get the screen refresh rate if (pathInfoTarget.targetInfo.refreshRate.Numerator != 0) { displayMonitorSettings.RefreshRate = (int)(pathInfoTarget.targetInfo.refreshRate.Numerator / pathInfoTarget.targetInfo.refreshRate.Denominator); } else { displayMonitorSettings.RefreshRate = 0; } //Get the screen hdr status displayMonitorSettings.HdrEnabled = GetMonitorHdrStatus(pathInfoTarget.targetInfo.adapterId, pathInfoTarget.targetInfo.id); displayMonitorSettings.HdrWhiteLevel = GetMonitorHdrWhiteLevel(pathInfoTarget.targetInfo.adapterId, pathInfoTarget.targetInfo.id); return(displayMonitorSettings); } catch { Debug.WriteLine("Failed getting displayconfig monitor information."); return(null); } }
private void ColorPrefixTextBox_TextChanged(object sender, EventArgs e) { var hexColors = ColorPrefixTextBox.Text; var intColors = DisplayMonitor.ColorsFromRgbs(hexColors); var values = intColors.Select(x => DisplayMonitor.GetValue(x)); ColorPrefixValueTextBox.Text = string.Join(",", values); }
static void Main(string[] args) { //============================================================== // EXTRACTING MONITOR EDID //============================================================== var devices = new EnumerateDevices(DisplayMonitor.GetDeviceSelector()); devices.EnumDisplay(); }
/// <summary> /// Gets display monitor information. /// </summary> /// <returns>Array of display monitor information</returns> public static async Task <DisplayItem[]> GetDisplayMonitorsAsync() { const string deviceInstanceIdKey = "System.Devices.DeviceInstanceId"; try { var devices = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector(), new[] { deviceInstanceIdKey }); if (devices?.Any() == true) { var items = new List <DisplayItem>(devices.Count); foreach (var device in devices) { if (!device.Properties.TryGetValue(deviceInstanceIdKey, out object value)) { continue; } var deviceInstanceId = value as string; if (string.IsNullOrWhiteSpace(deviceInstanceId)) { continue; } var displayMonitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id); //var displayMonitor = await DisplayMonitor.FromIdAsync(deviceInstanceId); if (displayMonitor is null) { continue; } //Debug.WriteLine($"DeviceInstanceId: {deviceInstanceId}"); //Debug.WriteLine($"DeviceName: {device.Name}"); //Debug.WriteLine($"DisplayName: {displayMonitor.DisplayName}"); //Debug.WriteLine($"ConnectionKind: {displayMonitor.ConnectionKind}"); //Debug.WriteLine($"PhysicalConnector: {displayMonitor.PhysicalConnector}"); //Debug.WriteLine($"PhysicalSize: {GetDiagonal(displayMonitor.PhysicalSizeInInches):F1}"); items.Add(new DisplayItem( deviceInstanceId: deviceInstanceId, displayName: displayMonitor.DisplayName, isInternal: (displayMonitor.ConnectionKind == DisplayMonitorConnectionKind.Internal), connectionDescription: GetConnectionDescription(displayMonitor.ConnectionKind, displayMonitor.PhysicalConnector), physicalSize: GetDiagonal(displayMonitor.PhysicalSizeInInches))); } return(items.ToArray()); } } catch (ArgumentException ax) when((uint)ax.HResult == ERROR_INVALID_PARAMETER) { } catch (Exception ex) when((uint)ex.HResult == ERROR_GEN_FAILURE) { } return(Array.Empty <DisplayItem>()); }
async Task vTaskLoop_MonitorTaskbar() { try { while (TaskCheckLoop(vTask_MonitorTaskbar)) { try { //Check taskbar visibility AVTaskbarInformation taskbarInfo = new AVTaskbarInformation(); //Check if auto hide is enabled if (taskbarInfo.IsAutoHide && taskbarInfo.IsVisible) { //Get the current active screen int monitorNumber = Convert.ToInt32(Setting_Load(vConfigurationCtrlUI, "DisplayMonitor")); DisplayMonitor displayMonitorSettings = GetSingleMonitorEnumDisplay(monitorNumber); //Get the current taskbar size int taskbarSize = 0; if (taskbarInfo.Position == AppBarPosition.ABE_BOTTOM) { AVActions.ActionDispatcherInvoke(delegate { try { //Update taskbar margin taskbarSize = (int)(taskbarInfo.Bounds.Height / displayMonitorSettings.DpiScaleVertical); grid_Application.Margin = new Thickness(0, 0, 0, taskbarSize); } catch { } }); continue; } } //Reset taskbar margin AVActions.ActionDispatcherInvoke(delegate { try { grid_Application.Margin = new Thickness(0); } catch { } }); } catch { } finally { //Delay the loop task await TaskDelayLoop(1000, vTask_MonitorTaskbar); } } } catch { } }
internal ExternalDisplayBrightnessController(MonitorInfo info, DisplayMonitor displayMonitor) { Maximum = info.MaxValue; Minimum = info.MinValue; currentValue = info.CurrentValue; hPhysicalMonitor = info.Handle; Brightness = currentValue; AssociatedDisplayMonitor = displayMonitor; }
private static int GetMonitor(int monitorIndex) { var monitorArray = DisplayMonitor.EnumerateMonitors(); if ((monitorArray.Length - 1) >= monitorIndex) { return((monitorArray[monitorIndex] != null) ? monitorIndex : 0); } return(0); }
//Update the window position async Task UpdateWindowPosition(bool notifyApps, bool silent) { try { //Check if the application is maximized bool isMaximized = vAppMaximized; if (isMaximized) { await AppSwitchScreenMode(false, true); } //Get the current active screen int monitorNumber = Convert.ToInt32(Setting_Load(vConfigurationCtrlUI, "DisplayMonitor")); DisplayMonitor displayMonitorSettings = GetSingleMonitorEnumDisplay(monitorNumber); //Get the current window size int windowWidth = (int)(this.ActualWidth * displayMonitorSettings.DpiScaleHorizontal); int windowHeight = (int)(this.ActualHeight * displayMonitorSettings.DpiScaleVertical); //Check and resize the target window size if (windowWidth > displayMonitorSettings.WidthNative || windowHeight > displayMonitorSettings.HeightNative) { windowWidth = displayMonitorSettings.WidthNative; windowHeight = displayMonitorSettings.HeightNative; WindowResize(vInteropWindowHandle, windowWidth, windowHeight); } //Center the window on target screen int horizontalLeft = (int)(displayMonitorSettings.BoundsLeft + (displayMonitorSettings.WidthNative - windowWidth) / 2); int verticalTop = (int)(displayMonitorSettings.BoundsTop + (displayMonitorSettings.HeightNative - windowHeight) / 2); WindowMove(vInteropWindowHandle, horizontalLeft, verticalTop); //Restore the previous screen mode if (isMaximized) { await AppSwitchScreenMode(true, false); } //Notify apps the monitor changed if (notifyApps) { await NotifyDirectXInputSettingChanged("DisplayMonitor"); await NotifyFpsOverlayerSettingChanged("DisplayMonitor"); } //Show monitor change notification if (!silent) { await Notification_Send_Status("MonitorNext", "Moved to monitor " + monitorNumber); } Debug.WriteLine("Moved the application to monitor: " + monitorNumber); } catch { } }
public static IEnumerable <DeviceItem> EnumerateMonitorDevices() { var size = (uint)Marshal.SizeOf <DISPLAY_DEVICE>(); var display = new DISPLAY_DEVICE { cb = size }; var monitor = new DISPLAY_DEVICE { cb = size }; for (uint i = 0; EnumDisplayDevices(null, i, ref display, EDD_GET_DEVICE_INTERFACE_NAME); i++) { if (display.StateFlags.HasFlag(DISPLAY_DEVICE_FLAG.DISPLAY_DEVICE_MIRRORING_DRIVER)) { continue; } if (!TryGetDisplayIndex(display.DeviceName, out byte displayIndex)) { continue; } byte monitorIndex = 0; for (uint j = 0; EnumDisplayDevices(display.DeviceName, j, ref monitor, EDD_GET_DEVICE_INTERFACE_NAME); j++) { var deviceInstanceId = GetDeviceInstanceId(monitor.DeviceID); var isActive = monitor.StateFlags.HasFlag(DISPLAY_DEVICE_FLAG.DISPLAY_DEVICE_ACTIVE); //Debug.WriteLine($"DeviceId: {monitor.DeviceID}"); //Debug.WriteLine($"DeviceInstanceId: {deviceInstanceId}"); //Debug.WriteLine($"DeviceString: {monitor.DeviceString}"); //Debug.WriteLine($"IsActive {isActive}"); if (!isActive) { continue; } var displayMonitorTask = DisplayMonitor.FromIdAsync(deviceInstanceId).AsTask(); displayMonitorTask.Wait(); var displayMonitor = displayMonitorTask.Result; yield return(new DeviceItem( deviceInstanceId: deviceInstanceId, description: monitor.DeviceString, displayIndex: displayIndex, monitorIndex: monitorIndex, friendlyName: displayMonitor.DisplayName)); monitorIndex++; } } }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Any(o => o == DependencyProperty.UnsetValue || o == null)) { return(null); } DisplayMonitor value = values[0] as DisplayMonitor; DisplayMonitor preferredValue = values[1] as DisplayMonitor; return(value == preferredValue); }
private void checkMonitor() { DisplayMonitor[] monitors = DisplayMonitor.EnumerateMonitors(); if (c_monitor < monitors.Length) { if (monitors[c_monitor] != null) { return; } } c_monitor = 0; }
public static VcpControl Vcp(this DisplayMonitor monitor) { if (AllVcp.ContainsKey(monitor)) { return(AllVcp[monitor]); } VcpControl vcp = new VcpControl(monitor); AllVcp.Add(monitor, vcp); return(vcp); }
private static async Task <List <DisplayMonitor> > GetMonitorInfosAsync() { var deviceInfos = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector()); List <DisplayMonitor> monitors = new(); foreach (var deviceInfo in deviceInfos) { DisplayMonitor monitor = await DisplayMonitor.FromInterfaceIdAsync(deviceInfo.Id); monitors.Add(monitor); } return(monitors); }
public async Task PopulateAsync() { System = GetSystem(); var sw = new Stopwatch(); var tasks = new[] { GetTask(nameof(DeviceItems), () => DeviceItems = DeviceContext.EnumerateMonitorDevices().ToArray()), GetTask(nameof(DisplayMonitorItems), async() => { if (OsVersion.Is10Build17134OrGreater) { DisplayMonitorItems = await DisplayMonitor.GetDisplayMonitorsAsync(); } }), GetTask(nameof(DisplayConfigItems), () => DisplayConfigItems = DisplayConfig.EnumerateDisplayConfigs().ToArray()), GetTask(nameof(InstalledItems), () => InstalledItems = DeviceInformation.EnumerateInstalledMonitors().ToArray()), GetTask(nameof(PhysicalItems), () => PhysicalItems = DeviceContext.GetMonitorHandles().ToDictionary( x => x, x => MonitorConfiguration.EnumeratePhysicalMonitors(x.MonitorHandle, true) .Select(x => new PhysicalItemPlus(x)) .ToArray())), GetTask(nameof(DesktopItems), () => DesktopItems = MSMonitor.EnumerateDesktopMonitors().ToArray()) }; sw.Start(); ElapsedTime = await Task.WhenAll(tasks); sw.Stop(); Task <string> GetTask(string name, Action action) => Task.Run(() => { action.Invoke(); var elapsed = sw.Elapsed; return($@"{name,-14} -> {elapsed.ToString($@"{(elapsed.Minutes > 0 ? @"m\:" : string.Empty)}s\.fff")}"); }); }
//Update the window position public void UpdateWindowPosition() { try { //Get the current active screen int monitorNumber = Convert.ToInt32(Setting_Load(vConfigurationCtrlUI, "DisplayMonitor")); DisplayMonitor displayMonitorSettings = GetSingleMonitorEnumDisplay(monitorNumber); //Move and resize the window WindowMove(vInteropWindowHandle, displayMonitorSettings.BoundsLeft, displayMonitorSettings.BoundsTop); WindowResize(vInteropWindowHandle, displayMonitorSettings.WidthNative, displayMonitorSettings.HeightNative); } catch { } }
public override string ToString() { if (MonitorString == null) { try { DisplayMonitor monitor = Task.Run(async() => await GetMonitorInfoAsync()).Result; if (monitor != null && monitor.DisplayName.Length > 0) { MonitorString = $"{monitor.DisplayName} - {monitor.DisplayAdapterTargetId}"; } else { string[] split = Id.Split('#', '&'); MonitorString = $"{split[1]} - {split[5][3..]}";
public SetupForm() { InitializeComponent(); // Automatically set the monitor index for (int i = 0; i < DisplayMonitor.EnumerateMonitors().Length; i++) { cbMonitorIndex.Items.Add(i); } LoadSettings(); lblVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
private async Task <DisplayMonitor> GetMonitorInfoAsync() { var deviceInfos = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector()); foreach (var deviceInfo in deviceInfos) { if (deviceInfo.Id == Id) { var monitor = await DisplayMonitor.FromInterfaceIdAsync(deviceInfo.Id); return(monitor); } } return(null); }
/// <summary> /// Gets display monitor information. /// </summary> /// <returns>Array of display monitor information</returns> public static async Task <DisplayItem[]> GetDisplayMonitorsAsync() { const string deviceInstanceIdKey = "System.Devices.DeviceInstanceId"; try { var devices = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector(), new[] { deviceInstanceIdKey }); if (devices is { Count : > 0 }) { var items = new List <DisplayItem>(devices.Count); foreach (var device in devices) { if (!device.Properties.TryGetValue(deviceInstanceIdKey, out object value)) { continue; } var deviceInstanceId = value as string; if (string.IsNullOrWhiteSpace(deviceInstanceId)) { continue; } var displayMonitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id); //var displayMonitor = await DisplayMonitor.FromIdAsync(deviceInstanceId); if (displayMonitor is null) { continue; } //Debug.WriteLine($"DeviceInstanceId: {deviceInstanceId}"); //Debug.WriteLine($"DisplayName: {displayMonitor.DisplayName}"); //Debug.WriteLine($"ConnectionKind: {displayMonitor.ConnectionKind}"); //Debug.WriteLine($"PhysicalConnector: {displayMonitor.PhysicalConnector}"); //Debug.WriteLine($"PhysicalSize: {GetDiagonal(displayMonitor.PhysicalSizeInInches):F1}"); items.Add(new DisplayItem( deviceInstanceId: deviceInstanceId, displayName: displayMonitor.DisplayName, isInternal: (displayMonitor.ConnectionKind == DisplayMonitorConnectionKind.Internal), connectionDescription: GetConnectionDescription(displayMonitor.ConnectionKind, displayMonitor.PhysicalConnector), physicalSize: GetDiagonal(displayMonitor.PhysicalSizeInInches))); } return(items.ToArray()); } }
public SetupForm() { LOG.Info("Instantiating SetupForm"); InitializeComponent(); // Automatically set the monitor index for (int i = 0; i < DisplayMonitor.EnumerateMonitors().Length; i++) { cbMonitorIndex.Items.Add(i); } LoadSettings(); tbHelp.Text = Resources.SetupFormHelp; lblVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString(); LOG.Info("SetupForm Instantiated"); }
/* * GET EACH DisplayMonitor OBJECT from the DeviceInformation of the device interface ID, * then acquire its descriptor (in this case, EDID). */ public async void EnumDisplay() { for (var index = 0; index < deviceList.Count; index++) { if (index != 0) { Console.WriteLine(); } DisplayMonitor display = await DisplayMonitor.FromInterfaceIdAsync(deviceList[index].Id); byte[] EDID = display.GetDescriptor(DisplayMonitorDescriptorKind.Edid); string hexBuffer = BitConverter.ToString(EDID).Replace("-", " ").ToLower(); Console.WriteLine(string.Format("{0} : {1}", deviceList[index].Name, deviceList[index].Id)); Console.Write(hexBuffer + "\n"); } }
static void TestParcel() { Console.WriteLine("This is an verification test for parcel to see if the values corresponds!"); var dsp = new DisplayMonitor(); Console.Write("The price in euro for the parcel is: "); priceRealEstate = Convert.ToDecimal(Console.ReadLine()); Console.Write("The zone is (central, periphery): "); zone = Console.ReadLine(); Console.Write("The cadastral number is: "); address = Console.ReadLine(); var realEstate = new Parcel(priceRealEstate, zone, address); dsp.Message(realEstate, new DummyCalculator()); }
//Update the window position public void UpdateWindowPosition() { try { //Get the current active screen int monitorNumber = Convert.ToInt32(Setting_Load(vConfigurationCtrlUI, "DisplayMonitor")); DisplayMonitor displayMonitorSettings = GetSingleMonitorEnumDisplay(monitorNumber); //Get the current window size int windowWidth = (int)(this.ActualWidth * displayMonitorSettings.DpiScaleHorizontal); int windowHeight = (int)(this.ActualHeight * displayMonitorSettings.DpiScaleVertical); //Move the window to bottom center int horizontalLeft = (int)(displayMonitorSettings.BoundsLeft + (displayMonitorSettings.WidthNative - windowWidth) / 2); int verticalTop = (int)(displayMonitorSettings.BoundsTop + displayMonitorSettings.HeightNative - windowHeight); WindowMove(vInteropWindowHandle, horizontalLeft, verticalTop); } catch { } }
//Move the keyboard window based on thumb movement public void MoveKeyboardWindow(int mouseHorizontal, int mouseVertical) { try { //Check the mouse movement position if (mouseHorizontal == 0 && mouseVertical == 0) { return; } //Get the current window position WindowRectangle positionRect = new WindowRectangle(); GetWindowRect(vInteropWindowHandle, ref positionRect); int moveLeft = positionRect.Left + mouseHorizontal; int moveTop = positionRect.Top + mouseVertical; int moveRight = positionRect.Right + mouseHorizontal; int moveBottom = positionRect.Bottom + mouseVertical; //Get the current active screen int monitorNumber = Convert.ToInt32(Setting_Load(vConfigurationCtrlUI, "DisplayMonitor")); DisplayMonitor displayMonitorSettings = GetSingleMonitorEnumDisplay(monitorNumber); //Get the current window size int windowWidth = (int)(this.ActualWidth * displayMonitorSettings.DpiScaleHorizontal); int windowHeight = (int)(this.ActualHeight * displayMonitorSettings.DpiScaleVertical); //Check if window leaves screen double screenEdgeLeft = moveLeft + windowWidth; double screenLimitLeft = displayMonitorSettings.BoundsLeft + 20; double screenEdgeTop = moveTop + windowHeight; double screenLimitTop = displayMonitorSettings.BoundsTop + 20; double screenEdgeRight = moveRight - windowWidth; double screenLimitRight = displayMonitorSettings.BoundsRight - 20; double screenEdgeBottom = moveBottom - windowHeight; double screenLimitBottom = displayMonitorSettings.BoundsBottom - 20; if (screenEdgeLeft > screenLimitLeft && screenEdgeTop > screenLimitTop && screenEdgeRight < screenLimitRight && screenEdgeBottom < screenLimitBottom) { WindowMove(vInteropWindowHandle, moveLeft, moveTop); } } catch { } }
private static async Task <List <DeviceItemPlus> > GetMonitorDevicesAsync() { IDisplayItem[] displayItems = OsVersion.Is10Redstone4OrNewer ? await DisplayMonitor.GetDisplayMonitorsAsync() : DisplayConfig.EnumerateDisplayConfigs().ToArray(); var deviceItems = DeviceContext.EnumerateMonitorDevices().ToArray(); _ids = new HashSet <string>(deviceItems.Select(x => x.DeviceInstanceId)); IEnumerable <DeviceItemPlus> Enumerate() { foreach (var deviceItem in deviceItems) { var displayItem = displayItems.FirstOrDefault(x => string.Equals(deviceItem.DeviceInstanceId, x.DeviceInstanceId, StringComparison.OrdinalIgnoreCase)); if (displayItem is not null) { var isDescriptionNullOrWhiteSpace = string.IsNullOrWhiteSpace(deviceItem.Description); if (isDescriptionNullOrWhiteSpace || Regex.IsMatch(deviceItem.Description, "^Generic (?:PnP|Non-PnP) Monitor$", RegexOptions.IgnoreCase)) { if (!string.IsNullOrWhiteSpace(displayItem.DisplayName)) { yield return(new DeviceItemPlus(deviceItem, displayItem.DisplayName, displayItem.IsInternal)); continue; } if (!isDescriptionNullOrWhiteSpace && !string.IsNullOrWhiteSpace(displayItem.ConnectionDescription)) { yield return(new DeviceItemPlus(deviceItem, $"{deviceItem.Description} ({displayItem.ConnectionDescription})", displayItem.IsInternal)); continue; } } } yield return(new DeviceItemPlus(deviceItem)); } } return(Enumerate().Where(x => !string.IsNullOrWhiteSpace(x.AlternateDescription)).ToList()); }
//[SupportedOSPlatform("Windows10.0.17134.0")] public async void UseDeviceApi() { if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134, 0)) { var deviceInformations = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector()); foreach (DeviceInformation device in deviceInformations) { DisplayMonitor displayMonitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id); // Print some info about the display monitor var x = "DisplayName: " + displayMonitor.DisplayName; var y = "ConnectionKind: " + displayMonitor.ConnectionKind; if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 19041, 0)) { var z = "IsDolbyVisionSupported: " + displayMonitor.IsDolbyVisionSupportedInHdrMode; } } } }
private async Task TestAsync() { var selector = DisplayMonitor.GetDeviceSelector(); var infos = await DeviceInformation.FindAllAsync(selector); var monitors = new List <DisplayMonitor>(); foreach (var info in infos) { var monitor = await DisplayMonitor.FromInterfaceIdAsync(info.Id); monitors.Add(monitor); } var output = new List <string>(); foreach (var monitor in monitors) { output.Add($"RawDpiX: {monitor.RawDpiX} RawDpiY: {monitor.RawDpiY} Width: {monitor.NativeResolutionInRawPixels.Width} Height: {monitor.NativeResolutionInRawPixels.Height}"); } MainListView.ItemsSource = output; }
public override void Create( string name, int width, int height, bool fullScreen, NamedParameterList miscParams ) { SWF.Control parentHWnd = null; SWF.Control externalHWnd = null; _fsaaType = D3D.MultisampleType.None; _fsaaQuality = 0; fsaa = 0; vSync = false; vSyncInterval = 1; var title = name; var colorDepth = 32; var left = int.MaxValue; // Defaults to screen center var top = int.MaxValue; // Defaults to screen center var depthBuffer = true; var border = ""; var outerSize = false; _useNVPerfHUD = false; var enableDoubleClick = false; var monitorIndex = -1; if ( miscParams != null ) { object opt; ; // left (x) if (miscParams.TryGetValue("left", out opt)) left = Int32.Parse( opt.ToString() ); // top (y) if (miscParams.TryGetValue("top", out opt)) top = Int32.Parse( opt.ToString() ); // Window title if (miscParams.TryGetValue("title", out opt)) title = (string)opt; // parentWindowHandle -> parentHWnd if (miscParams.TryGetValue("parentWindowHandle", out opt)) { // This is Axiom specific var handle = opt; var ptr = IntPtr.Zero; if (handle.GetType() == typeof(IntPtr)) { ptr = (IntPtr)handle; } else if (handle.GetType() == typeof(Int32)) { ptr = new IntPtr( (int)handle ); } else throw new AxiomException( "unhandled parentWindowHandle type" ); parentHWnd = SWF.Control.FromHandle( ptr ); } // externalWindowHandle -> externalHWnd if (miscParams.TryGetValue("externalWindowHandle", out opt)) { // This is Axiom specific var handle = opt; var ptr = IntPtr.Zero; if (handle.GetType() == typeof(IntPtr)) { ptr = (IntPtr)handle; } else if (handle.GetType() == typeof(Int32)) { ptr = new IntPtr((int)handle); } else throw new AxiomException("unhandled externalWindowHandle type"); externalHWnd = SWF.Control.FromHandle( ptr ); } // vsync [parseBool] if (miscParams.TryGetValue("vsync", out opt)) vSync = bool.Parse( opt.ToString() ); // hidden [parseBool] if (miscParams.TryGetValue("hidden", out opt)) _hidden = bool.Parse( opt.ToString() ); // vsyncInterval [parseUnsignedInt] if (miscParams.TryGetValue("vsyncInterval", out opt)) vSyncInterval = Int32.Parse( opt.ToString() ); // displayFrequency if (miscParams.TryGetValue("displayFrequency", out opt)) _displayFrequency = Int32.Parse( opt.ToString() ); // colorDepth if (miscParams.TryGetValue("colorDepth", out opt)) colorDepth = Int32.Parse( opt.ToString() ); // depthBuffer [parseBool] if (miscParams.TryGetValue("depthBuffer", out opt)) depthBuffer = bool.Parse( opt.ToString() ); // FSAA type if (miscParams.TryGetValue("FSAA", out opt)) _fsaaType = (MultisampleType)opt; // FSAA quality if (miscParams.TryGetValue("FSAAQuality", out opt)) fsaaHint = opt.ToString(); // window border style if (miscParams.TryGetValue("border", out opt)) border = ( (string)opt ).ToLower(); // set outer dimensions? if (miscParams.TryGetValue("outerDimensions", out opt)) outerSize = bool.Parse( opt.ToString() ); // NV perf HUD? if (miscParams.TryGetValue("useNVPerfHUD", out opt)) _useNVPerfHUD = bool.Parse( opt.ToString() ); // sRGB? if (miscParams.TryGetValue("gamma", out opt)) hwGamma = bool.Parse(opt.ToString()); // monitor index if (miscParams.TryGetValue("monitorIndex", out opt)) monitorIndex = Int32.Parse(opt.ToString()); if (miscParams.TryGetValue("show", out opt)) _hidden = bool.Parse(opt.ToString()); // enable double click messages if (miscParams.TryGetValue("enableDoubleClick", out opt)) enableDoubleClick = bool.Parse(opt.ToString()); } isFullScreen = fullScreen; // Destroy current window if any if ( hWnd != null ) { Dispose(); } System.Drawing.Rectangle rc; if ( externalHWnd == null ) { WindowsExtendedStyle dwStyleEx = 0; var hMonitor = IntPtr.Zero; // If we specified which adapter we want to use - find it's monitor. if ( monitorIndex != -1 ) { var direct3D9 = D3DRenderSystem.Direct3D9; for ( var i = 0; i < direct3D9.AdapterCount; ++i ) { if ( i != monitorIndex ) continue; hMonitor = direct3D9.GetAdapterMonitor( i ); break; } } // If we didn't specified the adapter index, or if it didn't find it if ( hMonitor == IntPtr.Zero ) { // Fill in anchor point. var windowAnchorPoint = new Point( left, top ); // Get the nearest monitor to this window. hMonitor = DisplayMonitor.FromPoint( windowAnchorPoint, MonitorSearchFlags.DefaultToNearest ).Handle; } var monitorInfo = new DisplayMonitor( hMonitor ); // Update window style flags. fullscreenWinStyle = WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_POPUP; windowedWinStyle = WindowStyles.WS_CLIPCHILDREN; if ( !_hidden ) { fullscreenWinStyle |= WindowStyles.WS_VISIBLE; windowedWinStyle |= WindowStyles.WS_VISIBLE; } if ( parentHWnd != null ) { windowedWinStyle |= WindowStyles.WS_CHILD; } else { if ( border == "none" ) windowedWinStyle |= WindowStyles.WS_POPUP; else if ( border == "fixed" ) windowedWinStyle |= WindowStyles.WS_OVERLAPPED | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_MINIMIZEBOX; else windowedWinStyle |= WindowStyles.WS_OVERLAPPEDWINDOW; } var winWidth = width; var winHeight = height; // No specified top left -> Center the window in the middle of the monitor if ( left == int.MaxValue || top == int.MaxValue ) { var screenw = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left; var screenh = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top; // clamp window dimensions to screen size var outerw = ( winWidth < screenw ) ? winWidth : screenw; var outerh = ( winHeight < screenh ) ? winHeight : screenh; if ( left == int.MaxValue ) left = monitorInfo.WorkingArea.Left + ( screenw - outerw )/2; else if ( monitorIndex != -1 ) left += monitorInfo.WorkingArea.Left; if ( top == int.MaxValue ) top = monitorInfo.WorkingArea.Top + ( screenh - outerh )/2; else if ( monitorIndex != -1 ) top += monitorInfo.WorkingArea.Top; } else if ( monitorIndex != -1 ) { left += monitorInfo.WorkingArea.Left; top += monitorInfo.WorkingArea.Top; } this.width = desiredWidth = width; this.height = desiredHeight = height; this.top = top; this.left = left; if ( fullScreen ) { dwStyleEx |= WindowsExtendedStyle.WS_EX_TOPMOST; this.top = monitorInfo.Bounds.Top; this.left = monitorInfo.Bounds.Left; } else { AdjustWindow( width, height, ref winWidth, ref winHeight ); if ( !outerSize ) { // Calculate window dimensions required // to get the requested client area rc = new System.Drawing.Rectangle( 0, 0, this.width, this.height ); AdjustWindowRect( ref rc, GetWindowStyle( fullScreen ), false ); this.width = rc.Right - rc.Left; this.height = rc.Bottom - rc.Top; // Clamp window rect to the nearest display monitor. if ( this.left < monitorInfo.WorkingArea.Left ) this.left = monitorInfo.WorkingArea.Left; if ( this.top < monitorInfo.WorkingArea.Top ) this.top = monitorInfo.WorkingArea.Top; if ( winWidth > monitorInfo.WorkingArea.Right - this.left ) winWidth = monitorInfo.WorkingArea.Right - this.left; if ( winHeight > monitorInfo.WorkingArea.Bottom - this.top ) winHeight = monitorInfo.WorkingArea.Bottom - this.top; } } WindowClassStyle classStyle = 0; if ( enableDoubleClick ) classStyle |= WindowClassStyle.CS_DBLCLKS; // Register the window class // NB allow 4 bytes of window data for D3D9RenderWindow pointer /* WNDCLASS wc = { classStyle, WindowEventUtilities::_WndProc, 0, 0, hInst, LoadIcon( 0, IDI_APPLICATION ), LoadCursor( NULL, IDC_ARROW ), (HBRUSH)GetStockObject( BLACK_BRUSH ), 0, "OgreD3D9Wnd" }; RegisterClass( &wc ); // Create our main window // Pass pointer to self _isExternal = false; hWnd = CreateWindowEx( dwStyleEx, "OgreD3D9Wnd", title.c_str(), getWindowStyle( fullScreen ), mLeft, mTop, winWidth, winHeight, parentHWnd, 0, hInst, this ); */ var wnd = new DefaultForm(classStyle, dwStyleEx, title, GetWindowStyle(fullScreen), this.left, this.top, winWidth, winHeight, parentHWnd); hWnd = wnd; wnd.RenderWindow = this; WindowEventMonitor.Instance.RegisterWindow( this ); } else { hWnd = externalHWnd; _isExternal = true; } // top and left represent outer window coordinates rc = new System.Drawing.Rectangle(hWnd.Location, hWnd.Size); this.top = rc.Top; this.left = rc.Left; // width and height represent interior drawable area rc = hWnd.ClientRectangle; this.width = rc.Right; this.height = rc.Bottom; this.name = name; depthBufferPoolId = depthBuffer ? PoolId.Default : PoolId.NoDepth; this.depthBuffer = null; this.colorDepth = colorDepth; LogManager.Instance.Write("D3D9 : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", this.name, this.width, this.height, this.colorDepth); active = true; _isClosed = false; IsHidden = _hidden; }