翔 羽
翔 羽

Reputation: 227

How to get the screen auto-rotate's status?

How to get the screen auto-rotate's status (disable or enable) by Regetry or ACPI in windows8?

I need to disable screen auto-rotate, and I will use winkey + O to change the screen auto-rotate control.

Does anyone have similar experiences?

Upvotes: 3

Views: 7215

Answers (5)

Katie
Katie

Reputation: 1270

The registry and Windows+O hotkey work at the system level, tweaking a user setting. Applications aren't supposed to mess with it. There is an application-level way to set autorotation preferences, and once the user closes your app or switches to a different one, then their existing settings (or the other app's) take over.

MSDN has a good example of using the relevant APIs here: https://code.msdn.microsoft.com/windowsapps/Auto-Rotation-Preferences-87ae2902

If your app has only one autorotation preference that it keeps throughout its lifetime, then it is simplest to just set it in your manifest. There are a few options there that you don't get with the APIs such as supporting both landscape and landscape flipped.

Upvotes: 1

Nick Shaw
Nick Shaw

Reputation: 2113

Another alternative, and this is the one that seems to work consistently on my tablet. Check this registry key. You can also change the key and the device will immediately pick up the change:

Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AutoRotation

Setting: Enable

It's a DWORD, so set to 0 to disable auto-rotate or 1 to enable auto-rotate.

Now, if only I could find a way to force the app to work in Landscape mode only!...

Upvotes: 0

Nick Shaw
Nick Shaw

Reputation: 2113

This MSDN example appears to do the job, using what looks like an 'official' API call, SetDisplayAutoRotationPreferences, which is in User32.dll (not kernel.dll as the example states) and is defined in WinUser.h.

The advantage of this example over the other suggestions is that it first checks whether auto-rotation is supported and enabled first.

Upvotes: 1

user882729
user882729

Reputation: 104

Below maybe helpful if you want to change auto-rotate status:

//C++
typedef BOOL (WINAPI* SETAUTOROTATION)(BOOL bEnable);

SETAUTOROTATION SetAutoRotation = (SETAUTOROTATION)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), (LPCSTR)2507);
if(SetAutoRotation != NULL)
{
  SetAutoRotation(TRUE);
}

or

//C#
[DllImport("user32.dll", EntryPoint = "#2507")]
extern static bool SetAutoRotation(bool bEnable);

SetAutoRotation(true);

Upvotes: 5

翔 羽
翔 羽

Reputation: 227

I found the answer.

        public enum tagAR_STATE : uint
        {
            AR_ENABLED = 0x0,
            AR_DISABLED = 0x1,
            AR_SUPPRESSED = 0x2,
            AR_REMOTESESSION = 0x4,
            AR_MULTIMON = 0x8,
            AR_NOSENSOR = 0x10,
            AR_NOT_SUPPORTED = 0x20,
            AR_DOCKED = 0x40,
            AR_LAPTOP = 0x80
        }

[DllImport("user32.dll")]
public static extern bool GetAutoRotationState(ref tagAR_STATE input);

Hope that can help the other people.

Upvotes: 1

Related Questions