C# Physical Video Adapter and Screen Object (Get a Screen object relative to a specific video output

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Greetings,
I am working with Windows Forms, and am looking to set a form to be full-screen on a specific video output adapter. I am currently capable of moving/resizing a form to a Screen (System.Windows.Forms.Screen) object, but am looking on how to correlate the
Screen object with a specific output (for example, the HDMI port on a graphics card).
I have made a few attempts, and am not getting the information I seek. Either I am doing something incorrectly, or am missing the information entirely. Snippets of the attempts follow:
<pre class="prettyprint //This attempt for simply enumerating information. The information I want does not appear to be here.
[METHOD]
SelectQuery q = new SelectQuery(
"SELECT Name, DeviceID, Description, PNPDeviceID, MonitorManufacturer, DisplayType FROM Win32_DesktopMonitor");
using(ManagementObjectSearcher mos = new ManagementObjectSearcher(q))
{
foreach(ManagementObject mo in mos.Get())
{

string monName = mo.Properties["Name"].Value.ToString();
string deviceid = mo.Properties["DeviceID"].Value.ToString();
string desc = mo.Properties["Description"].Value.ToString();

string pnpid = mo.Properties["PNPDeviceID"].Value.ToString();
string manuf = mo.Properties["MonitorManufacturer"].Value.ToString();
string disptype = mo.Properties["DisplayType"].Value.ToString();

}
} [METHOD]<br/> [/code]
<pre class="prettyprint //A similiar attempt to the one above. [METHOD]
ManagementObjectSearcher searcher
= new ManagementObjectSearcher("SELECT * FROM Win32_DisplayConfiguration");


List<string> props = new List<string>();
foreach(ManagementObject mo in searcher.Get())
{
foreach(PropertyData property in mo.Properties)
{
try
{
string s = property.Name + ": " + property.Value.ToString();
props.Add(s);
}
catch
{
string s = property.Name;
props.Add(s);
}
}
} [METHOD] [/code]
<pre class="prettyprint //A third, more complicated attempt. I am still not able to find information on the specific video port.

[DECLARATION]

[DllImport("user32.dll")]
static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);


[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct DISPLAY_DEVICE
{
[MarshalAs(UnmanagedType.U4)]
public int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string DeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceString;
[MarshalAs(UnmanagedType.U4)]
public DisplayDeviceStateFlags StateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceKey;
}

[Flags()]
public enum DisplayDeviceStateFlags : int
{
/// <summary>The device is part of the desktop.</summary>
AttachedToDesktop = 0x1,
MultiDriver = 0x2,
/// <summary>The device is part of the desktop.</summary>
PrimaryDevice = 0x4,
/// <summary>Represents a pseudo device used to mirror application drawing for remoting or other purposes.</summary>
MirroringDriver = 0x8,
/// <summary>The device is VGA compatible.</summary>
VGACompatible = 0x16,
/// <summary>The device is removable; it cannot be the primary display.</summary>
Removable = 0x20,
/// <summary>The device has more display modes than its output devices support.</summary>
ModesPruned = 0x8000000,
Remote = 0x4000000,
Disconnect = 0x2000000
}

[DECLARATION]

[METHOD CALL]


var device = new DISPLAY_DEVICE();
device.cb = Marshal.SizeOf(device);

for(uint id = 0; EnumDisplayDevices(null, id, ref device, 0); id++)
{

var newDevice = new DISPLAY_DEVICE();
newDevice.cb = Marshal.SizeOf(device);
EnumDisplayDevices(device.DeviceName, 0, ref newDevice, 0);

//The newDevice does not contain the information I want


}

[METHOD CALL]
[/code]
<br/>
<br/>

[TL;DR]
Are there any methods for enumerating specific physical video adapters, and tying them to a Screen object? If not, do you have any ideas for alternatives or workarounds?<br/>

If you have any comments, or need more information, please let me know.
Thank you very much in advance.<br/>


View the full article
 
Back
Top