Battery,Signal,DiskInfo,Memory

Battery,Signal,DiskInfo,Memory

Postby Silvio » Sat May 09, 2009 4:38 pm

How I can to show these informations ?
I wanted show it as bar progress into a window
I need your help



Code: Select all  Expand view
#include "FWCE.ch"


Function Test ()

// batteria
 MsgInfo( BatteryLife(), "Batteria" )

// Memoria
 AEval( MemInfo(), { | n | MsgInfo( n ) } )

//diskInfo
AEval( DISKINFO(), { | n | MsgInfo( n ) } )

// Signal
MsgInfo( Signal(), "Segnale" )
return nil


#pragma BEGINDUMP


#ifdef UNICODE
   #define UNDER_CE
#endif

#include <hbapi.h>
#include <windows.h>
#include <aygshell.h>
#include <ntddndis.h>
#include <nuiouser.h>
#include <winioctl.h>
#include <iphlpapi.h>




HB_FUNC( SIGNAL  )
{
int nStrength = 0;
int nQuality = 0;
GetFirstRFEthernetSignalStrength(&nStrength, &nQuality);
hb_retnl( ( long ) nStrength );
}

HRESULT GetSignalStrength(
TCHAR *ptcDeviceName,
int* piSignalStrength,
int* piSignalQuality
)
{ PNDISUIO_QUERY_OID queryOID;
   DWORD  dwBytesReturned = 0;
   UCHAR  QueryBuffer[sizeof(NDISUIO_QUERY_OID) +sizeof(DWORD)];
   HANDLE  ndisAccess = INVALID_HANDLE_VALUE;
   BOOL  retval;
   HRESULT  hr; // Attach to NDISUIO.
   ndisAccess = CreateFile( NDISUIO_DEVICE_NAME,    0, 0, NULL, OPEN_EXISTING,  FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,    INVALID_HANDLE_VALUE );
   if ( ndisAccess == INVALID_HANDLE_VALUE )
   return E_FAIL; // ????
   // Get Signal strength
   queryOID = (PNDISUIO_QUERY_OID)&QueryBuffer[0];
   queryOID->ptcDeviceName = ptcDeviceName;
   queryOID->Oid = OID_802_11_RSSI;
   retval = DeviceIoControl( ndisAccess,  IOCTL_NDISUIO_QUERY_OID_VALUE,  (LPVOID) queryOID,  sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD),  (LPVOID) queryOID,  sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD),  &dwBytesReturned,  NULL);
   if( retval && piSignalStrength && piSignalQuality )
      {
      hr = S_OK;
      *piSignalStrength = *(DWORD *)&queryOID->Data;
      //Here's Microsoft's interpretation
      //of the return value
      if(*piSignalStrength < -90)
         *piSignalQuality = 0; // No signal
      else if(*piSignalStrength < -81)
         *piSignalQuality  = 1; // Very low
      else if(*piSignalStrength < -71)
         *piSignalQuality  = 2; // Low
      else if(*piSignalStrength < -67)
         *piSignalQuality  = 3; // Good
      else if(*piSignalStrength < -57)
         *piSignalQuality  = 4; // Very good
      else   *piSignalQuality  = 5; // Excellent
      }
      else
      {
         hr = E_FAIL;
      }
      CloseHandle( ndisAccess );
      return hr;
   }
   BOOL GetFirstRFEthernetSignalStrength(
      int* pSignalStrength,
      int* pSignalQuality
      )
      { BOOL retval = FALSE;
      // Get the size of the adapters list.
      DWORD size = 0;
      GetAdaptersInfo( NULL, &size );
      // Allocate space for the list.
      IP_ADAPTER_INFO *info =
        (IP_ADAPTER_INFO*)new char[ size ];
        DWORD err;
        if ((err = GetAdaptersInfo(info, &size ))
         == NO_ERROR )
         {
         IP_ADAPTER_INFO *cinfo = info;
         while ( cinfo )
            {
             // Check the interface media type for
             // Ethernet, which both
             // standard Ethernet and RF Ethernet will return.
             if ( cinfo->Type == MIB_IF_TYPE_ETHERNET )
               {
               TCHAR wName[ MAX_ADAPTER_NAME_LENGTH + 4 ];
               MultiByteToWideChar( CP_ACP, 0,    cinfo->AdapterName, -1,     wName,     sizeof( wName ) / sizeof( wName[ 0 ] ) );
               // Try to get the signal strength.
               // If it works, we
               // return the information.
               // If not, we move on.
               if ( GetSignalStrength( wName,
                   pSignalStrength, pSignalQuality ) == S_OK )
                   {
                    retval = TRUE;
                    break;
                    }
                }
                // Go to the next adapter in the list.
                cinfo = cinfo->Next;
                }
               } // Don't forget to delete the allocation.
               delete [] info;
               return retval;
}


HB_FUNC( BATTERYLIFE )
{
   SYSTEM_POWER_STATUS_EX status;

   GetSystemPowerStatusEx( &status, TRUE );

   hb_retnl( ( long ) status.BatteryLifePercent );
}



  HB_FUNC (BATTERYINFO)
{
   BOOL iRet;
   SYSTEM_POWER_STATUS_EX status;
   iRet = GetSystemPowerStatusEx (&status, TRUE);

   hb_reta (9);
   hb_stornl ((INT) status.ACLineStatus, -1, 1);
   hb_stornl ((INT) status.BatteryFlag, -1, 2);
   hb_stornl ((INT) status.BatteryLifePercent, -1, 3);
   hb_stornl ((ULONG) status.BatteryLifeTime, -1, 4);
   hb_stornl ((ULONG) status.BatteryFullLifeTime, -1, 5);
   hb_stornl ((INT) status.BackupBatteryFlag, -1, 6);
   hb_stornl ((INT) status.BackupBatteryLifePercent, -1, 7);
   hb_stornl ((ULONG) status.BackupBatteryLifeTime, -1, 8);
   hb_stornl ((ULONG) status.BackupBatteryFullLifeTime, -1, 9);
}

HB_FUNC (MEMINFO)
{
   MEMORYSTATUS st;
   GlobalMemoryStatus (&st);

   hb_reta (4);
   hb_stornl ((ULONG) st.dwMemoryLoad, -1, 1);
   hb_stornl ((ULONG) st.dwTotalPhys, -1, 2);
   hb_stornl ((ULONG) st.dwTotalVirtual, -1, 3);
   hb_stornl ((ULONG) st.dwAvailVirtual, -1, 4);
}


HB_FUNC (DISKINFO)
{
  BOOL iRet;
  unsigned __int64 iFreeBytesToCaller, iTotalBytes, iFreeBytes;

  iRet = GetDiskFreeSpaceEx(NULL,
  (PULARGE_INTEGER) &iFreeBytesToCaller,
  (PULARGE_INTEGER) &iTotalBytes,
  (PULARGE_INTEGER) &iFreeBytes);
  hb_reta (2);
  hb_stornl ((ULONG) iTotalBytes, -1, 1);
  hb_stornl ((ULONG) iFreeBytes, -1, 2);
}




 
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Return to FiveWin para Pocket PC

Who is online

Users browsing this forum: No registered users and 8 guests