Skip to content

Instantly share code, notes, and snippets.

@hansschmucker
Created September 7, 2014 11:34
Show Gist options
  • Save hansschmucker/b0586be4ccd63f6c9712 to your computer and use it in GitHub Desktop.
Save hansschmucker/b0586be4ccd63f6c9712 to your computer and use it in GitHub Desktop.
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