Hello,
i have this code and it works (if the device is in landscape it retrieves
the display orientation ok):
DEVMODE sDevMode = {0};
sDevMode.dmSize = sizeof(DEVMODE);
sDevMode.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(NULL, &sDevMode, NULL, CDS_TEST, NULL);
if(sDevMode.dmDisplayOrientation != DMDO_0)
{
sDevMode.dmDisplayOrientation = DMDO_90;
ChangeDisplaySettingsEx(NULL, &sDevMode, NULL, CDS_RESET, NULL);
}
I write this code in c# and it works fine to change the orientation of the
display, but when i try to query the current orientation i get always the
DMDO_0 value.
public static uint DM_DISPLAYORIENTATION = 0x00800000;
public static int DISP_CHANGE_SUCCESSFUL = 0;
public static int DISP_CHANGE_RESTART = 1;
public static int DISP_CHANGE_FAILED = -1;
public static int DISP_CHANGE_BADMODE = -2;
public static int DISP_CHANGE_NOTUPDATED = -3;
public static int DISP_CHANGE_BADFLAGS = -4;
public static int DISP_CHANGE_BADPARAM = -5;
public static uint CDS_RESET = 0x40000000;
public static uint CDS_TEST = 0x00000002;
public static uint DMDO_0 = 0;
public static uint DMDO_90 = 1;
public static uint DMDO_180 = 2;
public static uint DMDO_270 = 4;
private const int CCHDEVICENAME = 32;
private const int CCHFORMNAME = 32;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
struct DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public uint dmFields;
public short dmOrientation;
public short dmPaperSize;
public short dmPaperLength;
public short dmPaperWidth;
public short dmScale;
public short dmCopies;
public short dmDefaultSource;
public short dmPrintQuality;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
public string dmFormName;
public short dmLogPixels;
public uint dmBitsPerPel;
public uint dmPelsWidth;
public uint dmPelsHeight;
public uint dmDisplayFlags;
public uint dmDisplayFrequency;
public uint dmDisplayOrientation;
}
[DllImport("coredll.dll", CharSet = CharSet.Auto)]
static extern int ChangeDisplaySettingsEx(string lpszDeviceName,
[In] ref DEVMODE lpDevMode, IntPtr hwnd, uint dwFlags, IntPtr lParam);
and this is the sample i used:
DEVMODE dm = new DEVMODE();
dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
dm.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(null, ref dm, IntPtr.Zero, CDS_TEST, IntPtr.Zero);
if (dm.dmDisplayOrientation != DMDO_90)
{
dm.dmDisplayOrientation = DMDO_90;
ChangeDisplaySettingsEx(null, ref dm, IntPtr.Zero, CDS_RESET, IntPtr.Zero);
}
the code above works fine and rotates the display to the right, the problem
is that if the device is already turned to the right the value
dm.dmDisplayOrientation after first call of function with parameter CDS_TEST
is always DMDO_0.
can anyone give me a hint? why i can get the correct rotation value? because
i can change it.
andrei