tags:

views:

383

answers:

2

I want to be able to enable my secondary monitor with C# in Windows Vista. Here is what I do:

SafeNativeMethods.EnumDisplayDevices(null, (uint)id, ref d, (uint)0);
...
SafeNativeMethods.EnumDisplaySettings(d.DeviceName, -2, ref mode0);
...
SafeNativeMethods.DEVMODE dm = mode0;

dm.dmPosition.x = 1440;
dm.dmFields = SafeNativeMethods.DM_POSITION;
long result = SafeNativeMethods.ChangeDisplaySettingsEx(d.DeviceName, ref dm, IntPtr.Zero, SafeNativeMethods.CDS_NORESET| SafeNativeMethods.CDS_UPDATEREGISTRY, IntPtr.Zero);
result = SafeNativeMethods.ChangeDisplaySettingsEx(null, ref dm, IntPtr.Zero, SafeNativeMethods.CDS_UPDATEREGISTRY, IntPtr.Zero);

This does not affect my secondary monitor even if I get 0 as result (which means SUCCESSFUL).

What have I done wrong ?

Thank you.

A: 

I haven't tried it myself, but it seems the folks over at this forum have a clue. The code is not C#, but it's understandable.

kek444
+1  A: 

I think you need to set more than just the Position field, you could probably get the current settings from EnumDisplaySettings (at least the size and color, maybe refresh rate also)

Anders