c# - How to manage multiple display setting in Windows 7 programatically? -


i need change resolution, position, , select 1 main display, preferably in .net.

i think can using user32.dll api functions via p/invoke.
see avaiable functions.

sample code:

[dllimport("user32.dll")] static extern long changedisplaysettings(ref devicemode lpdevmode, int dwflags);  [dllimport("user32.dll")] static extern int enumdisplaysettings(string lpszdevicename, int imodenum, ref devicemode lpdevmode);  [dllimport("user32.dll")] static extern int enumdisplaydevices(string lpdevice, int idevnum, ref displaydevice lpdisplaydevice, int dwflags); 

code changing screen resolution:

//displaydevice wrapper ... can find [here](http://pinvoke.net/default.aspx/structures/display_device.html) list<displaydevice> devices = new list<displaydevice>();  bool error = false; //here listing displaydevices (monitors) (int devid = 0; !error; devid++) {     try     {         displaydevice device = new displaydevice();         device.cb = marshal.sizeof(typeof(displaydevice));         error = enumdisplaydevices(null, devid, ref device, 0) == 0;         devices.add(device);     }     catch (exception)     {         error = true;     } }  list<displayset> devicesandmodes = new list<displayset>();  foreach (var dev in devices) {     error = false;     //here listing devicemodes (resolutions) each displaydevice (monitors)     (int = 0; !error; i++)     {         try         {             //devicemode wrapper. can find [here](http://pinvoke.net/default.aspx/structures/devmode.html)             devicemode mode = new devicemode();             error = enumdisplaysettings(dev.devicename, -1 + i, ref mode) == 0;             //display              devicesandmodes.add(new displayset { displaydevice = dev, devicemode = mode });         }         catch (exception ex)         {             error = true;         }     } }  //select 800x600 resolution ... devicemode d800x600 = devicesandmodes.where(s => s.devicemode.dmpelswidth == 800).first().devicemode;  //apply selected resolution ... changedisplaysettings(ref d800x600, 0); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -