获取 WinCE 移动设备屏幕旋转方向

获取 WinCE 移动设备屏幕旋转方向,分别从系统提供的接口和注册表获取。如果都获取不到,则采用默认值。

  1 #ifndef DMDO_ZERO  
  2 #define DMDO_ZERO     0  
  3 #endif  
  4 #ifndef DMDO_90  
  5 #define DMDO_90       1  
  6 #endif  
  7 #ifndef DMDO_180  
  8 #define DMDO_180      2  
  9 #endif  
 10 #ifndef DMDO_270  
 11 #define DMDO_270      4  
 12 #endif  
 13   
 14 //direction flags  
 15 #define DIR_SWAPXY          0x001  
 16 #define DIR_MIRRORLEFTRIGHT 0x002  
 17 #define DIR_MIRRORUPDOWN    0x004  
 18   
 19 static int giOrientation = -1;  
 20   
 21 #define TARGET_WINCE  
 22 int GetOrientation()  
 23 {  
 24 #if defined(TARGET_WINCE)  
 25   if(giOrientation < 0)  
 26   {  
 27     HKEY Key;  
 28     // context *p = NULL;  
 29     char Buffer[256];  
 30     DEVMODE *Mode = (DEVMODE *)Buffer;    // 一个比较复杂的结构体, 定义请参看 MSDN  
 31   
 32     Mode->dmSize = 192;  
 33     Mode->dmFields = 0x01000000L;  
 34   
 35   
 36     static LONG (WINAPI *FuncChangeDisplaySettingsEx)(LPCTSTR,LPDEVMODE,HWND,DWORD,LPVOID) = NULL;  
 37   
 38     HINSTANCE CoreDLL = LoadLibrary(_T("coredll.dll"));  
 39     if (CoreDLL)  
 40     {  
 41       *(FARPROC *)&FuncChangeDisplaySettingsEx = GetProcAddress(CoreDLL,_T("ChangeDisplaySettingsEx"));  
 42     }  
 43   
 44     if(FuncChangeDisplaySettingsEx &&  
 45       0 == FuncChangeDisplaySettingsEx(NULL, Mode, NULL, CDS_TEST, NULL))  
 46     {  
 47       Mode->dmFields = 0x00800000L;  
 48       FuncChangeDisplaySettingsEx(NULL, Mode, NULL, CDS_TEST, NULL);  
 49   
 50       switch((&Mode->dmDisplayFrequency)[1]) //(Mode->dmDisplayOrientation)  
 51       {  
 52       case DMDO_ZERO:  
 53         giOrientation = 0;  
 54         break;  
 55       case DMDO_90:  
 56         giOrientation = DIR_SWAPXY | DIR_MIRRORUPDOWN;  
 57         break;  
 58       case DMDO_270:  
 59         giOrientation = DIR_SWAPXY | DIR_MIRRORLEFTRIGHT;  
 60         break;  
 61       case DMDO_180:  
 62         giOrientation = DIR_MIRRORUPDOWN | DIR_MIRRORLEFTRIGHT;  
 63         break;  
 64       default:  
 65         // giOrientation = 0;  
 66         break;  
 67       }  
 68     }  
 69   
 70     if(giOrientation < 0 && ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\GDI\\ROTATION"), 0, KEY_READ, &Key))  
 71     {  
 72       DWORD dwValue;  
 73       DWORD dwRegSize = sizeof(dwValue);  
 74       DWORD dwRegType;  
 75   
 76       if(ERROR_SUCCESS == RegQueryValueEx(Key, _T("Angle"), 0, &dwRegType, (LPBYTE) &dwValue, &dwRegSize))  
 77       {  
 78         switch(dwValue)  
 79         {  
 80         case 0:  
 81           giOrientation = 0;  
 82           break;  
 83         case 90:  
 84           giOrientation = DIR_SWAPXY | DIR_MIRRORUPDOWN;  
 85           break;  
 86         case 270:  
 87           giOrientation = DIR_SWAPXY | DIR_MIRRORLEFTRIGHT;  
 88           break;  
 89         case 180:  
 90           giOrientation = DIR_MIRRORUPDOWN | DIR_MIRRORLEFTRIGHT;  
 91           break;  
 92         default:  
 93           // giOrientation = 0;  
 94           break;  
 95         }  
 96       }  
 97   
 98       RegCloseKey(Key);  
 99     }  
100   
101     if(giOrientation < 0)  
102       giOrientation = 0;  
103   }  
104 #else  
105   giOrientation = 0;  
106 #endif  
107   
108   RETAILMSG(1,(L"[%s]Orientation: %d\r\n",CString(__FUNCTION__),giOrientation));        // [GetOrientation]Orientation: 0  
109   return giOrientation;  
110 }  

 

posted @ 2016-02-21 16:06  91program  阅读(461)  评论(0编辑  收藏  举报