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.
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).
public static extern bool dtcfgex(string nvCommand);
I have a "NativeMethods" class that contains the interop calls
private static void UpdateCurrentSettings()
// helper to update the UI with current settings
DEVMODE dm = NativeMethods.CreateDevmode();
bool bSuccess = false;
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");
Note that the "ChangeDisplaySettings" function still exists in my code, but I could never actually get it working right.
// PInvoke declaration for EnumDisplaySettings Win32 API
public static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
// PInvoke declaration for ChangeDisplaySettings Win32 API
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);
dm.dmFormName = new String(new char);
dm.dmSize = (short)Marshal.SizeOf(dm);
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,