Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sets the display resolution from commandline using https://gist.github.com/hansschmucker/820d3bdeca34c665b77a
@ECHO OFF
SETLOCAL
SET RES_X=%1
SET RES_Y=%2
echo @^
using System.Runtime.InteropServices;^
[StructLayout(LayoutKind.Sequential)]^
public struct DispSet {^
[MarshalAs(UnmanagedType.ByValArray,SizeConst=106)]^
byte[] padding0;^
public int width, height;^
[MarshalAs(UnmanagedType.ByValArray,SizeConst=40)]^
byte[] padding1;^
};^
public class App {^
[DllImport("user32.dll")] public static extern^
int EnumDisplaySettings(string a, int b, ref DispSet c);^
[DllImport("user32.dll")] public static extern^
int ChangeDisplaySettings(ref DispSet a, int b);^
public static void Main() {^
var disp = new DispSet();^
if ( EnumDisplaySettings(null, -1, ref disp) == 0)^
return;^
disp.width=int.Parse(System.Environment^
.GetEnvironmentVariable("RES_X"));^
disp.height=int.Parse(System.Environment.^
GetEnvironmentVariable("RES_Y"));^
ChangeDisplaySettings(ref disp, 1);^
}^
}^
|c#
ENDLOCAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment