Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
<DllImport("user32.dll")> _
Private Shared Function ChangeDisplaySettingsEx(ByVal lpszDeviceName As String, ByRef lpDevMode As DEVMODE, ByVal hwnd As IntPtr, ByVal dwflags As UInteger, ByVal lParam As IntPtr) As DISP_CHANGE
End Function
You can not enable and set size in one call. If the second monitor is not enabled you must first call ChangeDisplaySettingsEx with dmFields = DM.Position, with dmPosition set something other than (0,0). Once enabled you can call ChangeDisplaySettingsEx again with dmFields = DM.PelsHeight | DM.PelsWidth | DM.Position to set position and size. To disable the monitor call ChangeDisplaySettingsEx with dmFields=DM.Position, with dmPosition set to (0,0). Disabling will not work if dmFields = DM.PelsHeight | DM.PelsWidth | DM.Position.
DISPLAY_DEVICE d = new DISPLAY_DEVICE();
DEVMODE dm = new DEVMODE();
d.cb = Marshal.SizeOf(d);
int deviceID=1; // This is only for my device setting. Go through the whole EnumDisplayDevices to find your device
EnumDisplayDevices(null,deviceID, ref d, 0); //
EnumDisplaySettings(d.DeviceName, 0, ref dm);
dm.dmPelsWidth = 1024;
dm.dmPelsHeight = 768;
dm.dmPositionX = Screen.PrimaryScreen.Bounds.Right;
dm.dmFields = DM.Position | DM.PelsWidth | DM.PelsHeight;
ChangeDisplaySettingsEx(d.DeviceName, ref dm, IntPtr.Zero, CDS_UPDATEREGISTRY, IntPtr.Zero);
Alternative Managed API:
Do you know one? Please contribute it!
Sample Code:
DISPLAY_DEVICE d = new DISPLAY_DEVICE();
DEVMODE dm = new DEVMODE();
d.cb = Marshal.SizeOf(d);
int deviceID=1; // This is only for my device setting. Go through the whole EnumDisplayDevices to find your device
EnumDisplayDevices(null,deviceID, ref d, 0); //
EnumDisplaySettings(d.DeviceName, 0, ref dm);
dm.dmPelsWidth = 1024;
dm.dmPelsHeight = 768;
dm.dmPositionX = Screen.PrimaryScreen.Bounds.Right;
dm.dmFields = DM.Position | DM.PelsWidth | DM.PelsHeight;
ChangeDisplaySettingsEx(d.DeviceName, ref dm, IntPtr.Zero, CDS_UPDATEREGISTRY, IntPtr.Zero);
Alternative Managed API:
Do you know one? Please contribute it!
Return values for ChangeDisplaySettings and ChangeDisplaySettingsEx
3/25/2011 11:36:01 AM - -74.46.76.243
Contains information about the initialization and environment of a printer or a display device.
2/1/2023 1:31:58 PM - shtolliver-47.227.243.115
dwflags for ChangeDisplaySettings and ChangeDisplaySettingsEx
7/21/2016 12:12:36 PM - -91.230.72.196
Changes the display settings via a DEVMODE struct.
8/10/2022 6:59:36 AM - 212.105.175.123
TODO - a short description
8/8/2019 8:30:35 AM - -50.78.140.98
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).