c# - Display Count (Inc. Disabled Displays) -
hello new stackoverflow.com. not sure how question asked here, doing best. done, quite research on subject, couldn't find single thing resolve detection.
example case: trying identify count of active , disabled displays in windows 7-10 systems.
code gpu[availability]:
private int moncount; [dllimport("user32.dll")] private static extern bool enumdisplaydevices( string lpdevice, int idevnum, ref display_device lpdisplaydevice, int dwflags); [structlayout(layoutkind.sequential)] public struct display_device { public int cb; [marshalas(unmanagedtype.byvaltstr, sizeconst = 32)] public string devicename; [marshalas(unmanagedtype.byvaltstr, sizeconst = 128)] public string devicestring; public int stateflags; [marshalas(unmanagedtype.byvaltstr, sizeconst = 128)] public string deviceid; [marshalas(unmanagedtype.byvaltstr, sizeconst = 128)] public string devicekey; public display_device(int flags) { cb = 0; stateflags = flags; devicename = new string((char)32, 32); devicestring = new string((char)32, 128); deviceid = new string((char)32, 128); devicekey = new string((char)32, 128); cb = marshal.sizeof(this); } } public void monitorcheck() { display_device lpdisplaydevice = new display_device(0); // out display_device monitor_name = new display_device(0); // out int devnum = 0; while (enumdisplaydevices(null, devnum, ref lpdisplaydevice, 0)) { listbox1.items.add("\ndevnum =" + devnum); listbox1.items.add("cb =" + lpdisplaydevice.cb); listbox1.items.add("deviceid =" + lpdisplaydevice.deviceid); listbox1.items.add("devicekey =" + lpdisplaydevice.devicekey); listbox1.items.add("devicename =" + lpdisplaydevice.devicename.trim()); listbox1.items.add("devicestring =" + lpdisplaydevice.devicestring.trim()); // show monitor name: enumdisplaydevices(lpdisplaydevice.devicename, 0, ref monitor_name, 0); listbox1.items.add("monitor name =" + monitor_name.devicestring.trim()); ++devnum; } }
source: c# how windows monitor name
return: attachable monitors graphic adapter information. count how many monitors can attached in display adapter.
code active displays:
screen.allscreens.count();
return: active monitor count.
problem:
if gpu adapter has 3 outputs: * above gpu[availability] code returns: 3 (no matter how many displays attached it.)
if 2 monitors attached (example: laptop monitor + external hdmi monitor), display setup set to: laptop monitor (external hdmi monitor not active) -> active displays code returns: 1
question:
how return 2 there non-active display , active display attached (laptop monitor + non-active external monitor)?
solutions:
there's few ideas how resolve this:
- activate displays extending them , redo:
screen.allscreens.count();
idea: compare output of gpu[availability] output , count gives value monitor_name.devicestring.trim()
(however, i've tested @ desktop having nvidia adapter: outcome null, in laptop intel hd adapter: output "generic pnp-monitor", so, no solution).
stupid me... never though use 3 methods solve problem. (seems damn hard code work in code tags here @ forums.
- maximum attachable displays
- currently attached displays
- currently active displays
solution:
hmm, can't seem able attach code stackoverflow reply, so:
Comments
Post a Comment