private static void AddAdditionalInfos(List <DisplayInfo> displayInfo) { for (int id = 0; id < displayInfo.Count; id++) { var vDevMode = new DevMode(); var d = new DisplayDevice(); d.cb = Marshal.SizeOf(d); try { User32.EnumDisplayDevices(displayInfo[id].DeviceName, 0, ref d, 0); d.cb = Marshal.SizeOf(d); if ((d.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.AttachedToDesktop) { User32.EnumDisplaySettings(displayInfo[id].DeviceName, -1, ref vDevMode); displayInfo[id].devMode = vDevMode; } displayInfo[id].displayDevice = d; } catch (Exception e) { Logger.Exception(e); } } }
public override IEnumerable <Display> GetActiveDisplays() { var displayDevices = GetDisplayDevices(); // find out resolution parameters for each display device. foreach (var displayDevice in displayDevices.Where( x => x.StateFlags.HasFlag(DisplayDeviceStateFlags.AttachedToDesktop))) { var mode = new DevMode { size = (short)Marshal.SizeOf(typeof(DevMode)) }; // -1 means current RESOLUTION for specific display. // you can enumerate through 0..N to find supported resolutions. var success = XPWrapper.EnumDisplaySettings(displayDevice.DeviceName, -1, ref mode); if (!success) { continue; } var origin = mode.position; var resolution = mode.resolution; var refreshRate = mode.displayFrequency; var rotation = mode.displayOrientation; yield return(new Display { Resolution = resolution, Origin = origin, Rotation = rotation.ToScreenRotation(), RefreshRate = refreshRate, Name = displayDevice.DeviceName }); } }
void GetDisplayAdapterInfoForMonitor(Models.Monitor monitorDetails) { var devMode = new DevMode { Size = (ushort)_marshal.SizeOf <DevMode>() }; if (!_nativeMethods.EnumDisplaySettings(monitorDetails.DisplayAdapter.Name, NativeConstants.ENUM_CURRENT_SETTINGS, ref devMode)) { return; } monitorDetails.Frequency = Convert.ToInt32(devMode.DisplayFrequency); monitorDetails.Resolution = new Rectangle { Width = Convert.ToInt32(devMode.PelsWidth), Height = Convert.ToInt32(devMode.PelsHeight) }; // DevMode.LogPixels was returning the same density for all monitors, so some division is used to get the // scaling factor and DPI. monitorDetails.ScalingFactor = Convert.ToSingle(monitorDetails.Resolution.Width) / monitorDetails.MonitorCoordinates.Width; monitorDetails.Dpi = Convert.ToInt32(96f * monitorDetails.ScalingFactor); }
private static List <DisplayInfo> GetDisplays() { List <DisplayInfo> displayCollection = new List <DisplayInfo>(); MonitorEnumDelegate monitorDelegate = delegate(IntPtr hMonitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr dwData) { MonitorInfoEx monitorInfo = new MonitorInfoEx(); monitorInfo.size = (uint)Marshal.SizeOf(monitorInfo); if (GetMonitorInfo(hMonitor, ref monitorInfo)) { var info = new DevMode(); EnumDisplaySettings(monitorInfo.deviceName, -1, ref info); var monitor = new Rect { left = info.dmPositionX, right = info.dmPositionX + info.dmPelsWidth, top = info.dmPositionY, bottom = info.dmPositionY + info.dmPelsHeight }; DisplayInfo displayInfo = new DisplayInfo(monitor, monitorInfo.flags); displayCollection.Add(displayInfo); } return(true); }; EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, monitorDelegate, IntPtr.Zero); return(displayCollection); }
/// <summary> /// Call this if you want to receive list of currently active monitors. /// What does "active" mean in our context? It means the monitors that are "enabled" /// in Desktop properties screen. /// </summary> /// <returns>list of active monitors</returns> public IEnumerable <IDisplay> GetActiveMonitors() { var displayDevices = GetDisplayDevices(); // find out resolution parameters for each display device. foreach (var displayDevice in displayDevices.Where( x => x.StateFlags.HasFlag(DisplayDeviceStateFlags.AttachedToDesktop))) { var mode = new DevMode { size = (short)Marshal.SizeOf(typeof(DevMode)) }; // -1 means current RESOLUTION for specific display. // you can enumerate through 0..N to find supported resolutions. var success = XPWrapper.EnumDisplaySettings(displayDevice.DeviceName, -1, ref mode); if (!success) { continue; } var origin = mode.position; var resolution = mode.resolution; var refreshRate = mode.displayFrequency; var rotation = mode.displayOrientation; var isPrimary = IsPrimaryDisplay(origin); if (isPrimary && !displayDevice.StateFlags.HasFlag(DisplayDeviceStateFlags.PrimaryDevice)) { throw new Exception("SEEMS LIKE MSDN DOCUMENT LIED, IF THIS ERROR EVER HAPPENS."); } yield return(new XPDisplay(new DisplaySettings(resolution, origin, rotation.ToScreenRotation(), refreshRate, isPrimary, displayDevice.DeviceName))); } }
private void MainWindow_LocationChanged(object sender, EventArgs e) { IntPtr windowHandle = new WindowInteropHelper(Application.Current.MainWindow).Handle; var monitorHandle = MonitorFromWindow(windowHandle, MonitorDefaultToNearest); // Get the logical width and height of the monitor. var monitorInfo = new MonitorInfoEx(); monitorInfo.Size = Marshal.SizeOf(monitorInfo); GetMonitorInfoEx(monitorHandle, ref monitorInfo); int cxLogical = (monitorInfo.MonitorArea.Right - monitorInfo.MonitorArea.Left); // Get the physical width and height of the monitor. DevMode dm = new DevMode(); dm.dmSize = (short)Marshal.SizeOf(dm); dm.dmDriverExtra = 0; EnumDisplaySettings(monitorInfo.DeviceName, EnumCurrentSettings, ref dm); int cxPhysical = dm.dmPelsWidth; // Calculate the scaling factor. double scaleFactor = ((double)cxPhysical / (double)cxLogical); Scale.Text = scaleFactor.ToString(); }
public void Refresh() { var mi = new MonitorInfo { Size = Marshal.SizeOf(typeof(MonitorInfo)) }; if (!MonitorWin32.GetMonitorInfo(this.MonitorHandle, ref mi)) { return; } var deviceInfo = new DevMode { dmSize = (short)Marshal.SizeOf(typeof(DevMode)) }; if (!MonitorWin32.EnumDisplaySettings(mi.DeviceName, MonitorWin32.ENUM_CURRENT_SETTINGS, ref deviceInfo)) { return; } var orientation = (MonitorOrientation)deviceInfo.dmDisplayOrientation; var actualResolution = new Rectangle(deviceInfo.dmPositionX, deviceInfo.dmPositionY, deviceInfo.dmPelsWidth, deviceInfo.dmPelsHeight); var displayName = deviceInfo.dmDeviceName; this.Orientation = orientation; this.Resolution = actualResolution; this.DisplayName = displayName; }
private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(this); } }
public static void SetDisplayMode(string deviceName, DisplayMode displayMode) { DevMode devMode = new DevMode(); devMode.dmSize = (short)Marshal.SizeOf(devMode); devMode.dmBitsPerPel = displayMode.BitsPerPixels; devMode.dmPelsWidth = displayMode.Width; devMode.dmPelsHeight = displayMode.Height; devMode.dmDisplayFrequency = displayMode.Frequency; devMode.dmFields = DM.BitsPerPixel | DM.DisplayFrequency | DM.PelsHeight | DM.PelsWidth; DisplayChange result = User32.ChangeDisplaySettingsEx(deviceName, ref devMode, IntPtr.Zero, ChangeDisplaySettingsFlags.FullScreen, IntPtr.Zero); }
private void ProcessSPLRecord(SPLRecord record, BinaryReader fileReader) { Int64 recSeek = record.RecSeek; Int32 recSize = record.RecSize; if (recSize <= 0) { recSize = 8; } switch (record.RecType) { case SPLRecordTypeEnum.SRT_JOB_INFO: fileReader.BaseStream.Seek(recSeek + recSize, SeekOrigin.Begin); break; case SPLRecordTypeEnum.SRT_EOF: // Final de arquivo, não faz nada break; case SPLRecordTypeEnum.SRT_DEVMODE: devModeRecord = new DevMode(fileReader); fileReader.BaseStream.Seek(recSeek + 8 + recSize, SeekOrigin.Begin); break; case SPLRecordTypeEnum.SRT_PAGE: case SPLRecordTypeEnum.SRT_EXT_PAGE: ProcessEMFPage(record, fileReader); break; case SPLRecordTypeEnum.SRT_EOPAGE1: case SPLRecordTypeEnum.SRT_EOPAGE2: Byte[] bytes = fileReader.ReadBytes(recSize); if (recSize == 0x08) { fileReader.BaseStream.Seek(recSeek + recSize + 8, SeekOrigin.Begin); } break; case SPLRecordTypeEnum.SRT_EXT_FONT2: fileReader.BaseStream.Seek(recSeek + 4, SeekOrigin.Begin); break; default: fileReader.BaseStream.Seek(recSeek + recSize, SeekOrigin.Begin); break; } }
private static DisplaySetting[] GetDisplaySettings() { var settings = new List <DisplaySetting>(); foreach (var display in GetDisplays()) { var devMode = new DevMode().Initialize(); if (Methods.EnumDisplaySettings(display.DeviceName, DisplaySettingsMode.CurrentSettings, ref devMode)) { settings.Add(new DisplaySetting { DisplayName = display.DeviceName, DevMode = devMode }); } } return(settings.ToArray()); }
public static DisplayMode GetCurrentDisplayMode(string deviceName = null) { DisplayMode displayMode = new DisplayMode(); DevMode devMode = new DevMode(); devMode.dmSize = (short)Marshal.SizeOf(devMode); User32.EnumDisplaySettings(deviceName, User32.ENUM_CURRENT_SETTINGS, ref devMode); displayMode.BitsPerPixels = devMode.dmBitsPerPel; displayMode.Frequency = devMode.dmDisplayFrequency; displayMode.Height = devMode.dmPelsHeight; displayMode.Width = devMode.dmPelsWidth; return(displayMode); }
private static bool ApplyDisplaySettings(DisplaySetting[] settings) { var allDisplays = GetDisplays(); foreach (var setting in settings) { allDisplays.Remove( allDisplays.FirstOrDefault( ex => ex.DeviceName.ToLower().Trim() == setting.DisplayName.ToLower().Trim())); var flags = ChangeDisplaySettingsFlags.Updateregistry | ChangeDisplaySettingsFlags.Global | ChangeDisplaySettingsFlags.Noreset; if (setting.DevMode.Position.X == 0 && setting.DevMode.Position.Y == 0) { flags |= ChangeDisplaySettingsFlags.SetPrimary; } var devMode = setting.DevMode; if (Methods.ChangeDisplaySettingsEx(setting.DisplayName, ref devMode, IntPtr.Zero, flags, IntPtr.Zero) != ChangeDisplaySettingsExResults.Successful) { return(false); } } // Disable missing monitors foreach (var display in allDisplays) { var emptyDev = DevMode.GetEmpty(); Methods.ChangeDisplaySettingsEx( display.DeviceName, ref emptyDev, IntPtr.Zero, ChangeDisplaySettingsFlags.Updateregistry | ChangeDisplaySettingsFlags.Global | ChangeDisplaySettingsFlags.Noreset, IntPtr.Zero); } // Apply all settings Methods.ChangeDisplaySettingsEx( null, IntPtr.Zero, IntPtr.Zero, ChangeDisplaySettingsFlags.Reset, IntPtr.Zero); return(true); }
private IEnumerable <String> EnumerateDisplaySettings() { HashSet <String> set = new HashSet <String>(); DevMode devMode = new DevMode(); Int32 modeNum = 0; while (EnumDisplaySettings(null, modeNum++, ref devMode)) { if (devMode.dmPelsWidth >= 640 && devMode.dmPelsHeight >= 480) { String result = $"{devMode.dmPelsWidth.ToString(CultureInfo.InvariantCulture)}x{devMode.dmPelsHeight.ToString(CultureInfo.InvariantCulture)}"; if (set.Add(result)) { yield return(result); } } } }
/// <summary> /// Reads the device information using XP native functions /// and fills our specific structure. /// </summary> /// <param name="deviceName">Name of the device to get screen information from.</param> /// <returns>Fills it with screen resolution</returns> public void ReadDeviceInformation(string deviceName) { var vDevMode = new DevMode(); int rt = 0; // EnumDisplaySettings(deviceName, -1, ref vDevMode); if (rt != 0) { /* * // This is not necessiarly true * // TODO: In future, replace that. * // Primary is not always DISPLAY1 AFAIK * scr.Primary = deviceName == "\\\\.\\DISPLAY1"; * scr.BitsPerPixel = 1 << vDevMode.dmBitsPerPel; * scr.Bounds = new Rectangle(vDevMode.dmPositionX, vDevMode.dmPositionY, * vDevMode.dmPelsWidth, vDevMode.dmPelsHeight); * scr.WorkingArea = new Rectangle(vDevMode.dmPositionX, vDevMode.dmPositionY, * vDevMode.dmPelsWidth, vDevMode.dmPelsHeight); * scr.DeviceName = vDevMode.dmDeviceName;*/ } }
public static WindowsScreen Get(string deviceName) { Checker.Begin().NotNullOrEmpty(deviceName, nameof(deviceName)); var windowsScreen = Screen.AllScreens.FirstOrDefault(c => c.DeviceName.Equals(deviceName, StringComparison.OrdinalIgnoreCase)); if (windowsScreen == null) { throw new Win32ErrorCodeException($"DisplayDevice:{deviceName} does not find", Win32ErrorCode.DisplayDeviceNotExist); } var dm = new DevMode { dmSize = (short)Marshal.SizeOf(typeof(DevMode)) }; if (!Win32Api.EnumDisplaySettings(deviceName, EnumCurrentSettings, ref dm)) { throw new Win32ErrorCodeException($"Get displayDevice:{deviceName} failed", Win32ErrorCode.Win32ErrorGetDisplayDeviceFailed); } return(new WindowsScreen { DeviceName = deviceName, IsPrimary = windowsScreen.Primary, RealResolution = new WindowsRealResolution { Width = dm.dmPelsWidth, Height = dm.dmPelsHeight }, VirtualResolution = new WindowsVirtualResolution { Height = windowsScreen.Bounds.Height, Width = windowsScreen.Bounds.Width, ScaleY = dm.dmPelsHeight / (float)windowsScreen.Bounds.Height, ScaleX = dm.dmPelsWidth / (float)windowsScreen.Bounds.Width } }); }
public static IList <DisplayMode> GetDisplayModes(string deviceName = null) { IList <DisplayMode> result = new ArrayList <DisplayMode>(); int i = 0; DevMode devMode = new DevMode(); devMode.dmSize = (short)Marshal.SizeOf(devMode); while (User32.EnumDisplaySettings(deviceName, i++, ref devMode)) { DisplayMode displayMode = new DisplayMode(); displayMode.BitsPerPixels = devMode.dmBitsPerPel; displayMode.Frequency = devMode.dmDisplayFrequency; displayMode.Height = devMode.dmPelsHeight; displayMode.Width = devMode.dmPelsWidth; result.Add(displayMode); } return(result); }
/// <summary> /// Initializes a new display object. /// </summary> /// <param name="displayNumber"></param> public Display(uint displayNumber) { Device = new DISPLAY_DEVICE(); Mode = new DEVMODE(); Device.cb = Marshal.SizeOf(Device); if (!NativeMethods.EnumDisplayDevices(null, displayNumber, ref Device, 0)) { throw new ArgumentOutOfRangeException("DisplayNumber", displayNumber, "Number is greater than connected displays."); } DisplayNumber = displayNumber; NativeMethods.EnumDisplaySettings(Device.DeviceName, NativeMethods.ENUM_CURRENT_SETTINGS, ref Mode); Name = Device.DeviceName; DeviceString = Device.DeviceString; DeviceID = Device.DeviceID; DeviceKey = Device.DeviceKey; DeviceState = Device.StateFlags; DevMode = Mode.dmFields; Orientation = (Orientations)Mode.dmDisplayOrientation; }
public static extern bool EnumDisplaySettings(IntPtr lpszDeviceName, uint iModeNum, ref DevMode lpDevMode);
public ReaderTests() { _marshal = new Mock <IMarshal>(); _nativeMethods = new Mock <INativeMethods>(); _edidFactory = new Mock <IEdidFactory>(); var rect = new Rect(); const string adapterName = "Adapter"; const string monitorName = "Monitor"; const string monitorId = "a\\Id\\c\\d"; const string instanceId = "Id"; _marshal .Setup(a => a.GetLastWin32Error()) .Returns(() => _marshal.Invocations.Count(a => a.Method.Name == nameof(IMarshal.GetLastWin32Error)) > 1 ? NativeConstants.ERROR_NO_MORE_ITEMS : 0); _nativeMethods .Setup( a => a.EnumDisplayMonitors(It.IsAny <IntPtr>(), It.IsAny <IntPtr>(), It.IsAny <MonitorEnumDelegate>(), It.IsAny <IntPtr>())) .Callback <IntPtr, IntPtr, MonitorEnumDelegate, IntPtr>( (a, b, c, d) => c(new IntPtr(1), IntPtr.Zero, ref rect, IntPtr.Zero)) .Returns(true); _nativeMethods .Setup( a => a.EnumDisplayDevices(null, It.IsAny <uint>(), ref It.Ref <DisplayDevice> .IsAny, It.IsAny <uint>())) .Callback(new EnumDisplayDevicesDelegate((string a, uint b, ref DisplayDevice c, uint d) => c.DeviceName = adapterName)) .Returns <string, uint, DisplayDevice, uint>((a, b, c, d) => b == 0); _nativeMethods .Setup( a => a.EnumDisplayDevices(adapterName, It.IsAny <uint>(), ref It.Ref <DisplayDevice> .IsAny, It.IsAny <uint>())) .Callback(new EnumDisplayDevicesDelegate((string a, uint b, ref DisplayDevice c, uint d) => { c.DeviceId = monitorId; c.DeviceName = monitorName; })) .Returns <string, uint, DisplayDevice, uint>((a, b, c, d) => b == 0); _nativeMethods .Setup( a => a.SetupDiEnumDeviceInfo(It.IsAny <IntPtr>(), It.IsAny <uint>(), ref It.Ref <SpDevInfoData> .IsAny)) .Returns(true); _nativeMethods .Setup(a => a.GetMonitorInfo(It.IsAny <IntPtr>(), ref It.Ref <MonitorInfoEx> .IsAny)) .Callback(new GetMonitorInfoDelegate((IntPtr a, ref MonitorInfoEx b) => b = new MonitorInfoEx { Device = adapterName, Flags = NativeConstants.MONITORINFOF_PRIMARY, Monitor = new Rect { Right = 10, Bottom = 10 } })) .Returns(true); _nativeMethods .Setup(a => a.EnumDisplaySettings(It.IsAny <string>(), It.IsAny <uint>(), ref It.Ref <DevMode> .IsAny)) .Callback(new EnumDisplaySettingsDelegate((string a, uint b, ref DevMode c) => c = new DevMode { DisplayFrequency = 1, PelsWidth = 20, PelsHeight = 20 })) .Returns(true); _nativeMethods .Setup(a => a.SetupDiGetClassDevsEx(It.IsAny <Guid[]>(), It.IsAny <string>(), It.IsAny <IntPtr>(), It.IsAny <uint>(), It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <IntPtr>())) .Returns(new IntPtr(1)); _nativeMethods .Setup(a => a.SetupDiGetDeviceInstanceId(It.IsAny <IntPtr>(), ref It.Ref <SpDevInfoData> .IsAny, It.IsAny <char[]>(), It.IsAny <uint>(), It.IsAny <IntPtr>())) .Callback(new SetupDiGetDeviceInstanceIdDelegate( (IntPtr a, ref SpDevInfoData b, char[] c, uint d, IntPtr e) => Array.Copy(instanceId.ToCharArray(), 0, c, 0, instanceId.Length))) .Returns(true); _nativeMethods .Setup(a => a.SetupDiOpenDevRegKey(It.IsAny <IntPtr>(), ref It.Ref <SpDevInfoData> .IsAny, It.IsAny <uint>(), It.IsAny <uint>(), It.IsAny <uint>(), It.IsAny <uint>())) .Returns(IntPtr.Zero); _reader = new Reader(_marshal.Object, _nativeMethods.Object, _edidFactory.Object); }
public static extern int ChangeDisplaySettings(ref DevMode devMode, int flags);
public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DevMode devMode);
public bool EnumDisplaySettings(string deviceName, uint modeNum, ref DevMode devMode) { return(NativeMethods.EnumDisplaySettings(deviceName, modeNum, ref devMode)); }
public bool PrinterProperties() { var nullPtr = new IntPtr(0); IntPtr printerHandle = nullPtr; IntPtr bufPtr = nullPtr; PrinterDefaults pd; pd.pDatatype = 0; pd.pDevMode = 0; pd.DesiredAccess = PRINTER_USER_ACCESS; bool open = false; long result = 0; try { open = OpenPrinter(printerName, out printerHandle, ref pd); if (open) { int nSize = DocumentProperties(form.Handle, printerHandle, /* Handle to our printer. */ printerName, /* Name of the printer. */ IntPtr.Zero, /* Asking for size, so */ IntPtr.Zero, /* these are not used. */ 0); /* Zero returns buffer size. */ bufPtr = Marshal.AllocHGlobal(nSize); /* * Step 2: * Get the default DevMode for the printer and * modify it for your needs. */ result = DocumentProperties(form.Handle, printerHandle, printerName, bufPtr, /* The address of the buffer to fill. */ IntPtr.Zero, /* Not using the input buffer. */ DM_OUT_BUFFER); /* Have the output buffer filled. */ if (result < 1) { /* If failure, cleanup and return failure. */ Marshal.FreeHGlobal(bufPtr); throw new Exception( Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error1") + "\n" + Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error2") + ": " + Marshal.GetLastWin32Error()); } dm = (DevMode)Marshal.PtrToStructure(bufPtr, typeof(DevMode)); Marshal.StructureToPtr(dm, bufPtr, true); result = DocumentProperties(form.Handle, printerHandle, printerName, bufPtr, /* The address of the buffer to fill. */ bufPtr, /* Not using the input buffer. */ DM_IN_BUFFER | DM_OUT_BUFFER); dm = (DevMode)Marshal.PtrToStructure(bufPtr, typeof(DevMode)); IntPtr tempPtr = Marshal.AllocHGlobal(bufPtr); Marshal.WriteIntPtr(bufPtr, tempPtr); SetPrinter(printerHandle, 9, tempPtr, 0); Marshal.FreeHGlobal(tempPtr); result = AdvancedDocumentProperties(form.Handle, printerHandle, printerName, bufPtr, bufPtr); dm = (DevMode)Marshal.PtrToStructure(bufPtr, typeof(DevMode)); Marshal.StructureToPtr(dm, bufPtr, true); Marshal.FreeHGlobal(bufPtr); } else { throw new Exception( Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error3") + " " + printerName + "\n" + Environment.StringResources.GetString("PrinterOp_PrinterProperties_Error2") + ": " + Marshal.GetLastWin32Error()); } } catch (Exception ex) { Data.Env.WriteToLog(ex); MessageForm.Show(ex.Message, Environment.StringResources.GetString("Error")); } finally { if (open && printerHandle != nullPtr) { ClosePrinter(printerHandle); } } return(result > 0); }
/// <summary> /// Cancels a review. /// </summary> public void CancelReview() { var pendingChanges = BasicSccProvider.GetServiceEx<BBPendingChanges>(); pendingChanges.EndReview(); this.CurrentMode = DevMode.Working; // force the commands to update var shell = BasicSccProvider.GetServiceEx<IVsUIShell>(); if (shell != null) { shell.UpdateCommandUI(0); } this.sccProvider.RefreshToolWindows(); }
/// <summary> /// Compare working directory with TFS /// </summary> public void Review() { const string OperationName = "Review"; this.notificationService.ClearMessages(); this.notificationService.NewSection("Start " + OperationName); var currentBranch = this.sccHelper.GetCurrentBranch(); if (!this.CheckWorkingDirectoryClean() || string.IsNullOrEmpty(currentBranch) || !this.CheckLatestFromTfs(currentBranch)) { return; } var diff = SccHelperService.DiffBranches(BlinkboxSccOptions.Current.TfsRemoteBranch, currentBranch); if (diff.Any()) { // Switch to reviewing mode this.CurrentMode = DevMode.Reviewing; var pendingChangesView = BasicSccProvider.GetServiceEx<BBPendingChanges>(); if (pendingChangesView != null) { pendingChangesView.Review(diff.ToList(), BlinkboxSccOptions.Current.TfsRemoteBranch); } // force the commands to update var shell = BasicSccProvider.GetServiceEx<IVsUIShell>(); if (shell != null) { shell.UpdateCommandUI(0); } } else { notificationService.AddMessage("No changes found to review"); } }
}//main() /// <summary> /// Dont set primary when in Duplicate Modus. Any Monitor (so usualy the wrong one) can be Primary after. /// Best to set Prmiary it in Extend Modus only. /// </summary> /// <param name="bUsePrimarySettings"></param> static private void changeDisplaySettings(bool bUsePrimarySettings = true) { //get Config (fails when config is wrong) _log.Debug("read config, Start - fails when config is wrong"); //get MkDirServers from config file (fails when config is wrong) DisplayConfig config = (DisplayConfig)ConfigurationManager.GetSection("DisplaySettings"); if (config != null) { _log.Debug("DisplaySettings loaded."); } else { String strError = "Worker, failed to load DisplaySettings section. -> check config file."; _log.Fatal(strError); throw new Exception(strError); } List <DisplayElement> configdisplays = config.GetAllDisplays(); foreach (DisplayElement displ in configdisplays) { _log.Debug("setting found: " + displ.ToString()); } _log.Debug("read config, End"); //get all Displays from Windows Display display = new Display(); List <DISPLAY_DEVICE> windowsdisplays = display.GetDisplayList(); //all windows installed displays foreach (DISPLAY_DEVICE dev in windowsdisplays) { //display defined in configuration foreach (DisplayElement configDisplay in configdisplays) { //check name or devicestring bool bMatchingName = false; if (configDisplay.name != "") { //use device name if (configDisplay.name == "*" || configDisplay.name.ToLower() == dev.DeviceName.ToLower()) { bMatchingName = true; } } else if (configDisplay.devicestring != "") { //use device string (usualy the real name) if (configDisplay.devicestring.ToLower() == dev.DeviceString.ToLower()) { bMatchingName = true; } } else if (configDisplay.deviceid != "") { //use device string (usualy the real name) if (dev.DeviceID.ToLower().Contains(configDisplay.deviceid.ToLower())) { bMatchingName = true; } } else { throw new Exception("must define name, devicestring or deviceid"); } //found? if (bMatchingName) { //found _log.Debug("matching device found, name: '" + dev.DeviceName + "' string: '" + dev.DeviceString + "'."); //get resolutions List <DevMode> settings = display.GetDisplaySettings(dev.DeviceName); bool bResFound = false; DevMode selectedMode = new DevMode(); foreach (DevMode mode in settings) { if (mode.dmPelsHeight == configDisplay.height && mode.dmPelsWidth == configDisplay.width) { _log.Debug("matching resolution found: " + dev.DeviceName); //optional if (configDisplay.freqhz > 0) { if (mode.dmDisplayFrequency == configDisplay.freqhz) { _log.Debug("matching frequency found: " + dev.DeviceName); //bingo bResFound = true; selectedMode = mode; break; } } else { //ignore freq //bingo bResFound = true; selectedMode = mode; break; } } }//foreach mode of this display if (bResFound) { _log.Debug("settings found for device" + dev.DeviceName); //set resolution if (bResFound) { bool bSetAsPrimary = false; if (bUsePrimarySettings) { bSetAsPrimary = configDisplay.primary; } _log.Info("Change Settings, name: '" + dev.DeviceName + "', id: '" + dev.DeviceID + "'. primary: '" + bSetAsPrimary.ToString() + "' Res: " + selectedMode.dmPelsWidth.ToString() + "x" + selectedMode.dmPelsHeight.ToString() + " " + selectedMode.dmDisplayFrequency + "Hz"); string strError = display.ChangeSettings(dev.DeviceName, selectedMode, bSetAsPrimary); if (strError == "") { _log.Debug("Changed Settings successful."); } else { _log.Error("Changed Settings with Error: " + strError); } } else { Console.WriteLine("could not find the Resolution in the possible Modes."); } } else { _log.Debug("no matching settings found for device, name: '" + dev.DeviceName + "', id: '" + dev.DeviceID + "'."); } } //if match } //foreach config entry } //foreach windows device }
internal static extern bool EnumDisplaySettings(string deviceName, uint modeNum, ref DevMode devMode);
public static extern ChangeDisplaySettingsExResults ChangeDisplaySettingsEx( string lpszDeviceName, ref DevMode lpDevMode, IntPtr hwnd, ChangeDisplaySettingsFlags dwflags, IntPtr lParam);
private static extern Boolean EnumDisplaySettings(String deviceName, Int32 modeNum, ref DevMode devMode);
public static extern int ChangeDisplaySettings([In, Out] ref DevMode lpDevMode, [param: MarshalAs(UnmanagedType.U4)] uint dwflags);
public static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DevMode lpDevMode);
public static extern bool EnumDisplaySettings( string deviceName, DisplaySettingsMode modeNum, ref DevMode devMode);