程序代码实现启用或禁用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
时间: 2024-10-18 03:11:52