Hi Thelgord,
I was trying to do the same thing with C# on my laptop. The screen swivels and re-closes into tablet form with buttons on the front panel, one of which is supposed to rotate the screen. The software for the buttons only worked right in Vista, but I loaded XP. After some scanning using regmon, I discovered that the HP software was registering the button presses, but the screen wasn't being rotated.
My laptop has an Nvidia graphics chipset, so I was able to use an interop call to nvcpl.
Code:
[DllImport("nvcpl.dll", CharSet=CharSet.Ansi)]
public static extern bool dtcfgex(string nvCommand);
My native screen resolution is 1280x800, so I determine first determine the screen height. If it's 800, I rotate to 270-deg (portrait). If it's 1280, I rotate the screen to 0-deg (normal).
Code:
private static void UpdateCurrentSettings()
{
// helper to update the UI with current settings
DEVMODE dm = NativeMethods.CreateDevmode();
bool bSuccess = false;
GetSettings(ref dm);
if (dm.dmPelsHeight == 800 && dm.dmPelsWidth == 1280)
{
bSuccess = NativeMethods.dtcfgex("rotate 1 270");
}
if (dm.dmPelsHeight == 1280 && dm.dmPelsWidth == 800)
{
bSuccess = NativeMethods.dtcfgex("rotate 1 0");
}
}
I have a "NativeMethods" class that contains the interop calls
Code:
// PInvoke declaration for EnumDisplaySettings Win32 API
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
public static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
// PInvoke declaration for ChangeDisplaySettings Win32 API
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
public static extern int ChangeDisplaySettings(ref DEVMODE lpDevMode, int dwFlags);
// helper for creating an initialized DEVMODE structure
public static DEVMODE CreateDevmode()
{
DEVMODE dm = new DEVMODE();
dm.dmDeviceName = new String(new char[32]);
dm.dmFormName = new String(new char[32]);
dm.dmSize = (short)Marshal.SizeOf(dm);
return dm;
}
Note that the "ChangeDisplaySettings" function still exists in my code, but I could never actually get it working right.
The app is as simple as possible. When it runs it gets the screen height, rotates the display accordingly, then exits. Of course, it only works for Nvidia cards.
If you like, I can dump the full source code on my website and post a link.
Hope this helps,
pb