Skip to content

Instantly share code, notes, and snippets.

@lennartb-
Created January 3, 2014 15:20
Show Gist options
  • Save lennartb-/8239571 to your computer and use it in GitHub Desktop.
Save lennartb-/8239571 to your computer and use it in GitHub Desktop.
Switches the active display to the inactive and vice verse
public void SwitchActiveInactive() {
GetDisplayInfo();
// Negative x numbers = left
ddInactive.dmPosition.x = -1920;
ddInactive.dmPosition.y = 0;
ddInactive.dmFields = DM.Position;
var res = ChangeDisplaySettingsEx(
szInactiveDeviceName,
ref ddInactive,
IntPtr.Zero,
(int)(CDSFlags.CDS_NORESET | CDSFlags.CDS_UPDATEREGISTRY| CDSFlags.CDS_SET_PRIMARY ), IntPtr.Zero);
ddActive.dmPosition.x = 0;
ddActive.dmPosition.y = 0;
ddActive.dmPelsHeight = 0;
ddActive.dmPelsWidth = 0;
ddActive.dmFields = DM.Position | DM.PelsHeight | DM.PelsWidth;
ChangeDisplaySettingsEx(szActiveDeviceName, ref ddActive, IntPtr.Zero, (int)CDSFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
Console.WriteLine(res.ToString());
ChangeDisplaySettings(IntPtr.Zero, IntPtr.Zero);
Console.ReadKey();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment