程序代码实现启用或禁用Windows 8.1 Tablet的自动旋转功能
方法一:使用SetDisplayAutoRotationPreferences函数功能
#include <Windows.h> /* typedef enum ORIENTATION_PREFERENCE { ORIENTATION_PREFERENCE_NONE = 0x0, ORIENTATION_PREFERENCE_LANDSCAPE = 0x1, ORIENTATION_PREFERENCE_PORTRAIT = 0x2, ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4, ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8 }ORIENTATION_PREFERENCE; */ typedef BOOL (WINAPI *pSDARP)(ORIENTATION_PREFERENCE orientation); pSDARP pARP; int main(int argc, char* argv[]) { pARP = (pSDARP) GetProcAddress( GetModuleHandle(TEXT("user32.dll")), "SetDisplayAutoRotationPreferences"); if( pARP ){ if (atoi(argv[1]) == 0){ pARP( (ORIENTATION_PREFERENCE)(ORIENTATION_PREFERENCE_LANDSCAPE | ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED) ); } if (atoi(argv[1]) == 1){ pARP( (ORIENTATION_PREFERENCE)(ORIENTATION_PREFERENCE_NONE) ); } }else{ printf("System not supported.\t"); return 1; } return 0; }方法二:通过写入注册表Enable来设置。1表示启用自动旋转,0为禁止自动旋转
具体Key的位置如下:
KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AutoRotation
设置Windows 8.1屏幕自动旋转代码, Auto-rotate function code,布布扣,bubuko.com