1

I'm developing a feature on a Surface Book that can control the Rotation Lock of the device. This involves turning Rotation Lock on/off, as well as disabling it alltogether.

To clarify, my question here is not about turning Rotation Lock ON/OFF, which makes the icon turn blue or neutral.

enter image description here

I'm talking about turning Rotation Lock enabled/disabled, which makes the icon turn grey or neutral.

enter image description here

I've read through several Microsoft documents and online search results, but they all seem to focus on the on/off state of Rotation Lock, not the enable/disable state.

  • I'm aware of the UWP feature for SetAutoRotationPreferences, but that appears to only lock orientations in Tablet mode (not Desktop mode), and doesn't affect the Rotation Lock icon state.
  • I'm aware of the undocument/unsupported Win32 API SetAutoRotation, which works but only to turn the Rotation Lock on/off, not enabled/disabled.
  • I'm aware that the Rotation Lock icon can be manipulated programmatically using the Windows Registry key Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AutoRotation with the ValueName SlateEnable set to 0, but it requires a reboot of the device in order to be applied.
  • I'm aware that SHChangeNotify can be used to refresh the desktop, but I was unable to get it to work. I used the value SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero) if that is any indication I am doing it wrong or not.

Is there any Win32 API feature that can control the Rotation Lock's enable/disable state, or is there any API that can apply the windows registry modification immediately? I'm stuck. Any help would be greatly appreciated.

Tam Bui
  • 2,940
  • 2
  • 18
  • 27
  • Why would you want to do this? Would you restore it when your app loses focus, quits, or crashes? You're changing the behavior of _other apps that you don't own_, and the first time a user tried to do something that rotated (or not) when they expected it to they'd run away from your app and never go back. – 1201ProgramAlarm Jun 09 '20 at 20:42
  • @1201ProgramAlarm I cannot give full disclosure for proprietary reasons, but I just want to clarify that I never stated this was an app. I'm exploring Windows capabilities and wanted to know if this can be done or not, while showing that I have done some research up to this point. If the answer is "No it can't be done", then that information would be useful to me regarding next steps to follow up on. – Tam Bui Jun 09 '20 at 23:39

1 Answers1

1

After submitting the same question to the MSDN forums about this, the consensus appears to be that there is no API that exposes the capability to grey out the 'Rotation Lock' icon. However, the undocumented SetAutoRotation API can toggle the 'Rotation Lock' icon on and off.

Tam Bui
  • 2,940
  • 2
  • 18
  • 27