zoukankan      html  css  js  c++  java
  • 获取 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
    ",CString(__FUNCTION__),giOrientation));        // [GetOrientation]Orientation: 0  
    109   return giOrientation;  
    110 }  
  • 相关阅读:
    matlab矩阵中如何去掉重复的行;如何找到相同的行,并找到其位置
    Coursera 机器学习 第9章(下) Recommender Systems 学习笔记
    机器学习基石笔记1——在何时可以使用机器学习(1)
    Coursera 机器学习 第9章(上) Anomaly Detection 学习笔记
    matlab安装过程的被要求的配置程序
    jdk环境变量配置
    Coursera 机器学习 第8章(下) Dimensionality Reduction 学习笔记
    Coursera 机器学习 第8章(上) Unsupervised Learning 学习笔记
    Coursera 机器学习 第7章 Support Vector Machines 学习笔记
    linux服务器---squid限制
  • 原文地址:https://www.cnblogs.com/91program/p/5205097.html
Copyright © 2011-2022 走看看