locked
求助:如何获取PPC的运行电流大小? RRS feed

答案

  • 最近正好写了个~
     
    //电源信息
     static  DWORD   WINAPI CxoPowerChangeListen(void * temp_p);
     void    InitCxoPowerNotify();
     
     
     
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void InitCxoPowerNotify()
    {
     MSGQUEUEOPTIONS  options  =  {0};
     DWORD dwErr;
     
     options.dwSize  =  sizeof(MSGQUEUEOPTIONS); 
     options.dwFlags  =  0; 
     options.dwMaxMessages  =  QUEUE_ENTRIES; 
     options.cbMaxMessage  =  sizeof(POWER_BROADCAST)  +  MAX_NAMELEN; 
     options.bReadAccess  =  TRUE;
     
     g_hMsgQ  =  CreateMsgQueue(NULL,  &options); 
     
     if(!g_hMsgQ)
     {
      dwErr=GetLastError();
      NKDbgPrintfW(L"CreateMsgQueue failed\r\n");
      RETAILMSG(1,  (TEXT("CreateMessageQueue  ERROR:%d\n"),  dwErr)); 
      return; 
     }
     
     HANDLE hNotifications  =  RequestPowerNotifications(g_hMsgQ, POWER_NOTIFY_ALL);  
     if  (!hNotifications)
     { 
      dwErr  =  GetLastError(); 
      RETAILMSG(1,  (TEXT("RequestPowerNotifications  ERROR:%d\n"),  dwErr)); 
      StopPowerNotifications(g_hMsgQ);
      return;
     } 
     
     CreateThread(NULL, 0, CxoPowerChangeListen, NULL, 0, NULL);
    }
     
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    DWORD WINAPI CxoPowerChangeListen(void * temp_p)
    {
     UCHAR  buf[QUEUE_SIZE]; 
     unsigned long nRead = 0, flags = 0, res = 0;
     while(1)
     {
      DWORD dwRes = WaitForSingleObject(g_hMsgQ,INFINITE);
      if(dwRes==WAIT_OBJECT_0)
      {
       memset(&buf,  0,  QUEUE_SIZE); 
       if (ReadMsgQueue(g_hMsgQ, &buf, QUEUE_SIZE, &nRead, INFINITE, &flags))
       {
        PPOWER_BROADCAST  pb  =  (PPOWER_BROADCAST)&buf;
        PPOWER_BROADCAST_POWER_INFO  ppbpi  =  (PPOWER_BROADCAST_POWER_INFO)  pb->SystemPowerState;
     

        switch (pb->Message)
        {
         //接受系统电源状态改变的通知。例如,当系统从On到Suspend
        case PBT_TRANSITION:
         RETAILMSG(1,(L"Power Notification Message: PBT_TRANSITION\n"));
         RETAILMSG(1,(L"Flags: %lx", pb->Flags));
         RETAILMSG(1,(L"Length: %d", pb->Length));
         if (pb->Length)
         {
          RETAILMSG(1,(L"SystemPowerState: %s\n", pb->SystemPowerState));
         }
         break;
     
         //当系统resume的时候接收通知
        case PBT_RESUME:
         RETAILMSG(1,(L"Power Notification Message: PBT_RESUME\n"));
         //SystemIdleTimerReset
         break;
     
         
         //当系统在AC和电池之间切换的时候接收通知
        case PBT_POWERSTATUSCHANGE:
         {
          RETAILMSG(1,(L"Power Notification Message: PBT_POWERSTATUSCHANGE\n"));
     
          PPOWER_BROADCAST_POWER_INFO ppbpi =
           (PPOWER_BROADCAST_POWER_INFO) pb->SystemPowerState;
          m_stCeSystemInfo.PowerState = ppbpi->bACLineStatus;
         }
         break;
     
         //当系统电池级数变化时接收通知
        case PBT_POWERINFOCHANGE:
         {
          RETAILMSG(1,(L"Power Notification Message: PBT_POWERINFOCHANGE\n"));
          PPOWER_BROADCAST_POWER_INFO ppbpi =
           (PPOWER_BROADCAST_POWER_INFO) pb->SystemPowerState;
          if (ppbpi)
          {
           RETAILMSG(1,(L"Length: %d", pb->Length));
           RETAILMSG(1,(L"BatteryLifeTime = %d\n",ppbpi->dwBatteryLifeTime));
           RETAILMSG(1,(L"BatterFullLifeTime = %d\n",
            ppbpi->dwBatteryFullLifeTime));
           RETAILMSG(1,(L"BackupBatteryLifeTime = %d\n",
            ppbpi->dwBackupBatteryLifeTime));
           RETAILMSG(1,(L"BackupBatteryFullLifeTime = %d\n",
            ppbpi->dwBackupBatteryFullLifeTime));
           RETAILMSG(1,(L"ACLineStatus = %d\n",ppbpi->bACLineStatus));
           RETAILMSG(1,(L"BatteryFlag = %d\n",ppbpi->bBatteryFlag));
           RETAILMSG(1,(L"BatteryLifePercent = %d\n",
            ppbpi->bBatteryLifePercent));
           RETAILMSG(1,(L"BackupBatteryFlag = %d\n",
            ppbpi->bBackupBatteryFlag));
           RETAILMSG(1,(L"BackupBatteryLifePercent = %d\n",
            ppbpi->bBackupBatteryLifePercent));
     
           m_stCeSystemInfo.BatteryLifePercent = ppbpi->bBackupBatteryLifePercent;
          }
          break;
         }
     
        default:
         break;
        }
       }
      }
     }
    }
     
     
     
    2008年11月29日 6:08

全部回复

  • 最近正好写了个~
     
    //电源信息
     static  DWORD   WINAPI CxoPowerChangeListen(void * temp_p);
     void    InitCxoPowerNotify();
     
     
     
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void InitCxoPowerNotify()
    {
     MSGQUEUEOPTIONS  options  =  {0};
     DWORD dwErr;
     
     options.dwSize  =  sizeof(MSGQUEUEOPTIONS); 
     options.dwFlags  =  0; 
     options.dwMaxMessages  =  QUEUE_ENTRIES; 
     options.cbMaxMessage  =  sizeof(POWER_BROADCAST)  +  MAX_NAMELEN; 
     options.bReadAccess  =  TRUE;
     
     g_hMsgQ  =  CreateMsgQueue(NULL,  &options); 
     
     if(!g_hMsgQ)
     {
      dwErr=GetLastError();
      NKDbgPrintfW(L"CreateMsgQueue failed\r\n");
      RETAILMSG(1,  (TEXT("CreateMessageQueue  ERROR:%d\n"),  dwErr)); 
      return; 
     }
     
     HANDLE hNotifications  =  RequestPowerNotifications(g_hMsgQ, POWER_NOTIFY_ALL);  
     if  (!hNotifications)
     { 
      dwErr  =  GetLastError(); 
      RETAILMSG(1,  (TEXT("RequestPowerNotifications  ERROR:%d\n"),  dwErr)); 
      StopPowerNotifications(g_hMsgQ);
      return;
     } 
     
     CreateThread(NULL, 0, CxoPowerChangeListen, NULL, 0, NULL);
    }
     
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    DWORD WINAPI CxoPowerChangeListen(void * temp_p)
    {
     UCHAR  buf[QUEUE_SIZE]; 
     unsigned long nRead = 0, flags = 0, res = 0;
     while(1)
     {
      DWORD dwRes = WaitForSingleObject(g_hMsgQ,INFINITE);
      if(dwRes==WAIT_OBJECT_0)
      {
       memset(&buf,  0,  QUEUE_SIZE); 
       if (ReadMsgQueue(g_hMsgQ, &buf, QUEUE_SIZE, &nRead, INFINITE, &flags))
       {
        PPOWER_BROADCAST  pb  =  (PPOWER_BROADCAST)&buf;
        PPOWER_BROADCAST_POWER_INFO  ppbpi  =  (PPOWER_BROADCAST_POWER_INFO)  pb->SystemPowerState;
     

        switch (pb->Message)
        {
         //接受系统电源状态改变的通知。例如,当系统从On到Suspend
        case PBT_TRANSITION:
         RETAILMSG(1,(L"Power Notification Message: PBT_TRANSITION\n"));
         RETAILMSG(1,(L"Flags: %lx", pb->Flags));
         RETAILMSG(1,(L"Length: %d", pb->Length));
         if (pb->Length)
         {
          RETAILMSG(1,(L"SystemPowerState: %s\n", pb->SystemPowerState));
         }
         break;
     
         //当系统resume的时候接收通知
        case PBT_RESUME:
         RETAILMSG(1,(L"Power Notification Message: PBT_RESUME\n"));
         //SystemIdleTimerReset
         break;
     
         
         //当系统在AC和电池之间切换的时候接收通知
        case PBT_POWERSTATUSCHANGE:
         {
          RETAILMSG(1,(L"Power Notification Message: PBT_POWERSTATUSCHANGE\n"));
     
          PPOWER_BROADCAST_POWER_INFO ppbpi =
           (PPOWER_BROADCAST_POWER_INFO) pb->SystemPowerState;
          m_stCeSystemInfo.PowerState = ppbpi->bACLineStatus;
         }
         break;
     
         //当系统电池级数变化时接收通知
        case PBT_POWERINFOCHANGE:
         {
          RETAILMSG(1,(L"Power Notification Message: PBT_POWERINFOCHANGE\n"));
          PPOWER_BROADCAST_POWER_INFO ppbpi =
           (PPOWER_BROADCAST_POWER_INFO) pb->SystemPowerState;
          if (ppbpi)
          {
           RETAILMSG(1,(L"Length: %d", pb->Length));
           RETAILMSG(1,(L"BatteryLifeTime = %d\n",ppbpi->dwBatteryLifeTime));
           RETAILMSG(1,(L"BatterFullLifeTime = %d\n",
            ppbpi->dwBatteryFullLifeTime));
           RETAILMSG(1,(L"BackupBatteryLifeTime = %d\n",
            ppbpi->dwBackupBatteryLifeTime));
           RETAILMSG(1,(L"BackupBatteryFullLifeTime = %d\n",
            ppbpi->dwBackupBatteryFullLifeTime));
           RETAILMSG(1,(L"ACLineStatus = %d\n",ppbpi->bACLineStatus));
           RETAILMSG(1,(L"BatteryFlag = %d\n",ppbpi->bBatteryFlag));
           RETAILMSG(1,(L"BatteryLifePercent = %d\n",
            ppbpi->bBatteryLifePercent));
           RETAILMSG(1,(L"BackupBatteryFlag = %d\n",
            ppbpi->bBackupBatteryFlag));
           RETAILMSG(1,(L"BackupBatteryLifePercent = %d\n",
            ppbpi->bBackupBatteryLifePercent));
     
           m_stCeSystemInfo.BatteryLifePercent = ppbpi->bBackupBatteryLifePercent;
          }
          break;
         }
     
        default:
         break;
        }
       }
      }
     }
    }
     
     
     
    2008年11月29日 6:08
  •  hans_online 写:
    最近正好写了个~
     
    //电源信息
     static  DWORD   WINAPI CxoPowerChangeListen(void * temp_p);
     void    InitCxoPowerNotify();
     
     
     
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void InitCxoPowerNotify()
    {
     MSGQUEUEOPTIONS  options  =  {0};
     DWORD dwErr;
     
     options.dwSize  =  sizeof(MSGQUEUEOPTIONS); 
     options.dwFlags  =  0; 
     options.dwMaxMessages  =  QUEUE_ENTRIES; 
     options.cbMaxMessage  =  sizeof(POWER_BROADCAST)  +  MAX_NAMELEN; 
     options.bReadAccess  =  TRUE;
     
     g_hMsgQ  =  CreateMsgQueue(NULL,  &options); 
     
     if(!g_hMsgQ)
     {
      dwErr=GetLastError();
      NKDbgPrintfW(L"CreateMsgQueue failed\r\n");
      RETAILMSG(1,  (TEXT("CreateMessageQueue  ERROR:%d\n"),  dwErr)); 
      return; 
     }
     
     HANDLE hNotifications  =  RequestPowerNotifications(g_hMsgQ, POWER_NOTIFY_ALL);  
     if  (!hNotifications)
     { 
      dwErr  =  GetLastError(); 
      RETAILMSG(1,  (TEXT("RequestPowerNotifications  ERROR:%d\n"),  dwErr)); 
      StopPowerNotifications(g_hMsgQ);
      return;
     } 
     
     CreateThread(NULL, 0, CxoPowerChangeListen, NULL, 0, NULL);
    }
     
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    DWORD WINAPI CxoPowerChangeListen(void * temp_p)
    {
     UCHAR  buf[QUEUE_SIZE]; 
     unsigned long nRead = 0, flags = 0, res = 0;
     while(1)
     {
      DWORD dwRes = WaitForSingleObject(g_hMsgQ,INFINITE);
      if(dwRes==WAIT_OBJECT_0)
      {
       memset(&buf,  0,  QUEUE_SIZE); 
       if (ReadMsgQueue(g_hMsgQ, &buf, QUEUE_SIZE, &nRead, INFINITE, &flags))
       {
        PPOWER_BROADCAST  pb  =  (PPOWER_BROADCAST)&buf;
        PPOWER_BROADCAST_POWER_INFO  ppbpi  =  (PPOWER_BROADCAST_POWER_INFO)  pb->SystemPowerState;
     

        switch (pb->Message)
        {
         //接受系统电源状态改变的通知。例如,当系统从On到Suspend
        case PBT_TRANSITION:
         RETAILMSG(1,(L"Power Notification Message: PBT_TRANSITION\n"));
         RETAILMSG(1,(L"Flags: %lx", pb->Flags));
         RETAILMSG(1,(L"Length: %d", pb->Length));
         if (pb->Length)
         {
          RETAILMSG(1,(L"SystemPowerState: %s\n", pb->SystemPowerState));
         }
         break;
     
         //当系统resume的时候接收通知
        case PBT_RESUME:
         RETAILMSG(1,(L"Power Notification Message: PBT_RESUME\n"));
         //SystemIdleTimerReset
         break;
     
         
         //当系统在AC和电池之间切换的时候接收通知
        case PBT_POWERSTATUSCHANGE:
         {
          RETAILMSG(1,(L"Power Notification Message: PBT_POWERSTATUSCHANGE\n"));
     
          PPOWER_BROADCAST_POWER_INFO ppbpi =
           (PPOWER_BROADCAST_POWER_INFO) pb->SystemPowerState;
          m_stCeSystemInfo.PowerState = ppbpi->bACLineStatus;
         }
         break;
     
         //当系统电池级数变化时接收通知
        case PBT_POWERINFOCHANGE:
         {
          RETAILMSG(1,(L"Power Notification Message: PBT_POWERINFOCHANGE\n"));
          PPOWER_BROADCAST_POWER_INFO ppbpi =
           (PPOWER_BROADCAST_POWER_INFO) pb->SystemPowerState;
          if (ppbpi)
          {
           RETAILMSG(1,(L"Length: %d", pb->Length));
           RETAILMSG(1,(L"BatteryLifeTime = %d\n",ppbpi->dwBatteryLifeTime));
           RETAILMSG(1,(L"BatterFullLifeTime = %d\n",
            ppbpi->dwBatteryFullLifeTime));
           RETAILMSG(1,(L"BackupBatteryLifeTime = %d\n",
            ppbpi->dwBackupBatteryLifeTime));
           RETAILMSG(1,(L"BackupBatteryFullLifeTime = %d\n",
            ppbpi->dwBackupBatteryFullLifeTime));
           RETAILMSG(1,(L"ACLineStatus = %d\n",ppbpi->bACLineStatus));
           RETAILMSG(1,(L"BatteryFlag = %d\n",ppbpi->bBatteryFlag));
           RETAILMSG(1,(L"BatteryLifePercent = %d\n",
            ppbpi->bBatteryLifePercent));
           RETAILMSG(1,(L"BackupBatteryFlag = %d\n",
            ppbpi->bBackupBatteryFlag));
           RETAILMSG(1,(L"BackupBatteryLifePercent = %d\n",
            ppbpi->bBackupBatteryLifePercent));
     
           m_stCeSystemInfo.BatteryLifePercent = ppbpi->bBackupBatteryLifePercent;
          }
          break;
         }
     
        default:
         break;
        }
       }
      }
     }
    }
     
     
     




    太高深了,能不能做成一个可执行的插件
    2008年12月9日 13:46
  • 你好!可以参考codeproject上的一个帖子,Windows Mobile Power Management

     

    2008年12月12日 13:55
    版主