private DisplaySettings( WindowsApi.DEVMODEW devmode, UInt32 widthInPixels, UInt32 heightInPixels, UInt32 refreshRateInHertz, UInt32 bitsPerPixel, DisplayOrientation?orientation, FixedResolutionOutputOption?fixedOutputOption, DisplayFlags?flags, System.Drawing.Point?position ) { this.devmode = devmode; this.widthInPixels = widthInPixels; this.heightInPixels = heightInPixels; this.refreshRateInHertz = refreshRateInHertz; this.bitsPerPixel = bitsPerPixel; this.orientation = orientation; this.fixedOutputOption = fixedOutputOption; this.flags = flags; this.position = position; }
public static DisplaySettings?GetCurrentDisplaySettingsForDisplayAdapter(String displayAdapterName) { var displayAdapterNameAsCharArray = ConvertStringToNullTerminatedCharArray(displayAdapterName); var success = true; var devmode = new WindowsApi.DEVMODEW(); devmode.Init(); success = WindowsApi.EnumDisplaySettingsEx(displayAdapterNameAsCharArray, WindowsApi.ENUM_CURRENT_SETTINGS, ref devmode, 0); if (success == false) { return(null); } var displaySettings = DisplaySettings.CreateNew(devmode); if (displaySettings == null) { return(null); } return(displaySettings); }
public static List <DisplaySettings> GetAllDisplaySettingsForDisplayAdapter(String displayAdapterName) { var result = new List <DisplaySettings>(); var displayAdapterNameAsCharArray = ConvertStringToNullTerminatedCharArray(displayAdapterName); // get the display settings for each graphics mode of this display adapter UInt32 iGraphicsMode = 0; var success = true; while (success == true) { var devmode = new WindowsApi.DEVMODEW(); devmode.Init(); success = WindowsApi.EnumDisplaySettingsEx(displayAdapterNameAsCharArray, iGraphicsMode, ref devmode, 0); if (success == false) { break; } var displaySettings = DisplaySettings.CreateNew(devmode); if (displaySettings == null) { iGraphicsMode += 1; continue; } result.Add(displaySettings.Value); iGraphicsMode += 1; } return(result); }
internal static DisplaySettings?CreateNew(WindowsApi.DEVMODEW devmode) { if ((UInt32)(devmode.dmFields & WindowsApi.DM_FieldSelectionBit.DM_PELSWIDTH) == 0) { return(null); } var widthInPixels = devmode.dmPelsWidth; // if ((UInt32)(devmode.dmFields & WindowsApi.DM_FieldSelectionBit.DM_PELSHEIGHT) == 0) { return(null); } var heightInPixels = devmode.dmPelsHeight; // if ((UInt32)(devmode.dmFields & WindowsApi.DM_FieldSelectionBit.DM_DISPLAYFREQUENCY) == 0) { return(null); } var refreshRateInHertz = devmode.dmDisplayFrequency; // if ((UInt32)(devmode.dmFields & WindowsApi.DM_FieldSelectionBit.DM_BITSPERPEL) == 0) { return(null); } var bitsPerPixel = devmode.dmBitsPerPel; // DisplayOrientation?orientation = null; if ((UInt32)(devmode.dmFields & WindowsApi.DM_FieldSelectionBit.DM_DISPLAYORIENTATION) != 0) { orientation = (DisplayOrientation)devmode.DUMMYUNIONNAME.DUMMYSTRUCTNAME2.dmDisplayOrientation; } // FixedResolutionOutputOption?fixedOutputOption = null; if ((UInt32)(devmode.dmFields & WindowsApi.DM_FieldSelectionBit.DM_DISPLAYFIXEDOUTPUT) != 0) { fixedOutputOption = (FixedResolutionOutputOption)devmode.DUMMYUNIONNAME.DUMMYSTRUCTNAME2.dmDisplayFixedOutput; } // DisplayFlags?flags = null; if ((UInt32)(devmode.dmFields & WindowsApi.DM_FieldSelectionBit.DM_DISPLAYFLAGS) != 0) { flags = (DisplayFlags)devmode.DUMMYUNIONNAME2.dmDisplayFlags; } // System.Drawing.Point?position = null; if ((UInt32)(devmode.dmFields & WindowsApi.DM_FieldSelectionBit.DM_POSITION) != 0) { position = new System.Drawing.Point(devmode.DUMMYUNIONNAME.DUMMYSTRUCTNAME2.dmPosition.x, devmode.DUMMYUNIONNAME.DUMMYSTRUCTNAME2.dmPosition.y); } var result = new DisplaySettings( devmode, widthInPixels, heightInPixels, refreshRateInHertz, bitsPerPixel, orientation, fixedOutputOption, flags, position ); return(result); }