標籤:style color 使用 os io re c cti
程式碼實現啟用或禁用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