Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How cat I get percentage of free Windows resources?
Message
 
À
05/02/1999 08:45:51
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00184306
Message ID:
00184346
Vues:
16
>Hi, All!
>
>Is there an API call to get the percentage of current amount of free Windows resources (System, GDI and User)?
>
>Any help appreciated.
>
Hi Uri,

I think GlobalMemoryStatus is the call you're looking for. Here's the code:
DECLARE GlobalMemoryStatus IN Win32API;
  STRING @lpMemstatus
lcmemstatus = IntegerToString(32) + REPLICATE(CHR(0), 28)
= GlobalMemoryStatus(@lcmemstatus)
lnPctFree = StringToInteger(SUBSTR(lcmemstatus, 5, 4)) && Pct. Free
lnTotalPhys = StringToInteger(SUBSTR(lcmemstatus, 9, 4)) && Total Physical
lnFreePhys = StringToInteger(SUBSTR(lcmemstatus, 13, 4)) && Free Physical
lnbytespage = StringToInteger(SUBSTR(lcmemstatus, 17, 4)) && Bytes of Paging File
lnfreepage = StringToInteger(SUBSTR(lcmemstatus, 21, 4)) && free bytes of Paging File
lnuserbytes = StringToInteger(SUBSTR(lcmemstatus, 25, 4)) && Total user bytes
lnfreeuser = StringToInteger(SUBSTR(lcmemstatus, 29)) && Free user bytes

FUNCTION IntegerToString
    
  LPARAMETER pnInteger, pnbytes
    
  LOCAL lcresult, lnbytes, lnmask,;
    lninteger, lni, lnchar
  lcresult = ""
  IF PCOUNT() = 2
    lnbytes = pnbytes
  ELSE
    * Default to DWORD
    lnbytes = 4
  ENDIF
  lninteger = pnInteger
  lnmask = 255
  FOR lni = 1 TO lnbytes
    lnchar = BITAND(lninteger, lnmask)
    lcresult = lcresult + CHR(lnchar)
    lninteger = BITRSHIFT(lninteger, 8)
  NEXT
  RETURN lcresult
ENDFUNC


FUNCTION StringToInteger
    
  LPARAMETER pcstring, plsigned
    
  LOCAL lnresult, lnlast, lni, llsigned,;
    lnmsb, lnmax
  lnresult = 0
  lnlast = LEN(pcstring)
  * Return Signed Integer?
  IF PCOUNT() = 2
    llsigned = plsigned
  ELSE
    llsigned = .F.
  ENDIF
  FOR lni = 1 TO lnlast
    lnresult = lnresult + ASC(SUBSTR(pcstring, lni, 1)) * (256 ^ (lni - 1))
  NEXT
  IF llsigned
    lnmsb = (lnlast * 8) - 1
    IF BITTEST(lnresult, lnmsb)
      lnmax = (2 ^ (lnmsb + 1))
      lnresult = lnresult - lnmax
    ENDIF
  ENDIF
  RETURN lnresult
ENDFUNC
hth,
George

Ubi caritas et amor, deus ibi est
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform