Leif Asbrink wrote:

1) It would be nice to show the CPU load under
Windows. The system monitor uses up a lot of
resources, particularly during startup or when the window is moved so it would be nice to not
have to use it. Maybe there is a dll somewhere
that could be used to get this info?

Leif,

  I don't know of any DLL tha can do that, but I can offer you the code I use 
in Winrad for that purpose.
Let's hope that the mail system does not wrap lines where it shouldn't, making the code almost unreadable. In any case I can send it to you as an attachment. Let's first try with the mail...

73  Alberto  I2PHD
-----------------------------------------------------
<
 // Somewhere in main.h

  typedef bool  (__stdcall * pfnGetSystemTimes)(__int64* lpIdleTime,
                 __int64* lpKernelTime, __int64* lpUserTime );

  pfnGetSystemTimes GSTaddr;
//----------------------------------------------------------------------------


// Somewhere in main.cpp, during the init phase

// prepare to support GetSystemTimes
    hKernel = LoadLibrary( _T("Kernel32.dll") );
    if(hKernel != NULL)
    {
       GSTaddr = (pfnGetSystemTimes)GetProcAddress(hKernel, "GetSystemTimes" );
       if(GSTaddr == NULL )
       {
          FreeLibrary(hKernel);
          hKernel = NULL;
       }
    }


// This is the routine that computes the CPU loads caused by this programs, and 
by
// all the other programs. The returned cpuTot and cpuProc are expressed in 
percentage.
// This routine works only under Windows XP and Windows 2003
//---------------------------------------------------------------------------
bool  __fastcall TMainForm::getCpuLoad(int &cpuTot, int &cpuProc)
{
   __int64 usr, kern, idle, sys, dusr, dkern, didle, crea, exit, pkern, puser,
           dpkern, dpuser;
   static __int64 last_usr, last_kern, last_idle, last_pkern, last_puser;
   static bool first = true;
   bool res;

   if(!GSTaddr) return false;

   res =  GSTaddr(&idle, &kern, &usr);
   res &= GetProcessTimes(GetCurrentProcess(), (FILETIME*)&crea,
                         (FILETIME*)&exit, (FILETIME*)&pkern, 
(FILETIME*)&puser);

   if(!res) return false;

   if(first)
   {
     last_usr   = usr;
     last_kern  = kern;
     last_idle  = idle;
     last_puser = puser;
     last_pkern = pkern;
     first = false;
     return false;
   }

   dusr   = usr  - last_usr;     last_usr  = usr;
   dkern  = kern - last_kern;    last_kern = kern;
   didle  = idle - last_idle;    last_idle = idle;
   dpkern = pkern - last_pkern;  last_pkern = pkern;
   dpuser = puser - last_puser;  last_puser = puser;

   sys = dusr + dkern;
   if(sys == 0) return false;
   cpuTot  = (int)(((float)sys - didle) * 100. / sys + 0.5);
   cpuProc = (int)((float)(dpkern + dpuser) * 100. / sys + 0.5);
   return true;
}
//---------------------------------------------------------------------------
>


#############################################################
This message is sent to you because you are subscribed to
 the mailing list <linrad@antennspecialisten.se>.
To unsubscribe, E-mail to: <[EMAIL PROTECTED]>
To switch to the DIGEST mode, E-mail to <[EMAIL PROTECTED]>
To switch to the INDEX mode, E-mail to <[EMAIL PROTECTED]>
Send administrative queries to  <[EMAIL PROTECTED]>

Reply via email to