begin process at 2012 02 13 04:54:07
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Système

 > CHARGE DU CPU

CHARGE DU CPU


 Information sur la source

Note :
7,5 / 10 - par 4 personnes
7,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Système Classé sous :cpu, processeur Niveau :Débutant Date de création :01/08/2001 Date de mise à jour :29/11/2005 16:09:10 Vu / téléchargé :6 672 / 698

Auteur : Willi

Ecrire un message privé
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (8)
Ajouter un commentaire et/ou une note


 Description

Ce code vous permet de connaitre la charge du CPU en temps réel.
Ce code n'est pas de moi

Source

  • Option Explicit
  • ' api declaration to get the cursors position
  • Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  • ' declare type to store the coordinates
  • Private Type POINTAPI
  • X As Long
  • Y As Long
  • End Type
  • ' api declarations for our CPU meter
  • Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long
  • Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long
  • Const REG_DWORD = 4
  • Const HKEY_DYN_DATA = &H80000006
  • Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
  • Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  • Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  • Private Type LARGE_INTEGER
  • lowpart As Long
  • highpart As Long
  • End Type
  • ' api declarations to raise our form
  • Private Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
  • Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  • Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
  • Const DFC_BUTTON = 4
  • Const DFCS_BUTTON3STATE = &H10
  • Private Type RECT
  • Left As Long
  • Top As Long
  • Right As Long
  • Bottom As Long
  • End Type
  • ' api declarations to make form stay on top
  • Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  • Const SWP_NOMOVE = &H2
  • Const SWP_NOSIZE = &H1
  • Const SWP_SHOWWINDOW = &H40
  • Const HWND_TOPMOST = -1
  • Const HWND_NOTTOPMOST = -2
  • Private Sub Form_Load()
  • ' set the two timer intervals
  • tmrFormMove.Interval = 1
  • tmrCpuStatus.Interval = 500 'used 500 cause our program needs resources too
  • ' color the background shape and picturebox
  • shpBack.BackColor = RGB(0, 10, 90)
  • shpBack.BorderColor = RGB(0, 10, 90)
  • picStatus.BackColor = RGB(130, 130, 170)
  • ' raise our form
  • RaiseForm
  • ' initialize our CPU meter
  • InitCPU
  • End Sub
  • Private Sub RaiseForm()
  • Dim R As RECT
  • Me.ScaleMode = vbPixels
  • SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
  • DrawFrameControl Me.hdc, R, DFC_BUTTON, DFCS_BUTTON3STATE
  • OffsetRect R, 0, 22
  • End Sub
  • Private Sub InitCPU()
  • Dim lData As Long
  • Dim lType As Long
  • Dim lSize As Long
  • Dim hKey As Long
  • Dim Qry As String
  • Qry = RegOpenKey(HKEY_DYN_DATA, "PerfStats\StartStat", hKey)
  • If Qry <> 0 Then
  • MsgBox "Could not open registery!"
  • End
  • End If
  • lType = REG_DWORD
  • lSize = 4
  • Qry = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0, lType, lData, lSize)
  • Qry = RegCloseKey(hKey)
  • End Sub
  • Private Sub tmrFormMove_Timer()
  • Dim Point As POINTAPI
  • ' get the cursorposition
  • GetCursorPos Point
  • ' multiply the coordinates to convert twips to pixel and place the form
  • Me.Left = Point.X * 15 + 200
  • Me.Top = Point.Y * 15 + 150
  • ' make our form stay on top
  • SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE
  • End Sub
  • Private Sub tmrCpuStatus_Timer()
  • Dim lData As Long
  • Dim lType As Long
  • Dim lSize As Long
  • Dim hKey As Long
  • Dim Qry As String
  • Dim Status As Long
  • Qry = RegOpenKey(HKEY_DYN_DATA, "PerfStats\StatData", hKey)
  • If Qry <> 0 Then
  • MsgBox "Could not open registery!"
  • End
  • End If
  • lType = REG_DWORD
  • lSize = 4
  • Qry = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0, lType, lData, lSize)
  • Status = Int(lData)
  • ' show CPU usage in Label
  • lblStatus.Caption = Status & "%"
  • ' show CPU usage in our selfmade progressbar
  • ' when CPU usage is over 80% then color the status red
  • If Status < 80 Then
  • picStatus.Line (Status, 0)-(0, 10), RGB(255, 245, 85), BF
  • Else
  • picStatus.Line (Status, 0)-(0, 10), RGB(245, 10, 0), BF
  • End If
  • picStatus.Line (Status, 0)-(100, 10), RGB(130, 130, 170), BF
  • Qry = RegCloseKey(hKey)
  • End Sub
Option Explicit

' api declaration to get the cursors position
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

' declare type to store the coordinates
Private Type POINTAPI
    X As Long
    Y As Long
End Type

' api declarations for our CPU meter
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long

Const REG_DWORD = 4
Const HKEY_DYN_DATA = &H80000006

Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private Type LARGE_INTEGER
    lowpart As Long
    highpart As Long
End Type

' api declarations to raise our form
Private Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long

Const DFC_BUTTON = 4
Const DFCS_BUTTON3STATE = &H10

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

' api declarations to make form stay on top
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const SWP_SHOWWINDOW = &H40
Const HWND_TOPMOST = -1
Const HWND_NOTTOPMOST = -2


Private Sub Form_Load()

    ' set the two timer intervals
    tmrFormMove.Interval = 1
    tmrCpuStatus.Interval = 500 'used 500 cause our program needs resources too
    
    ' color the background shape and picturebox
    shpBack.BackColor = RGB(0, 10, 90)
    shpBack.BorderColor = RGB(0, 10, 90)
    picStatus.BackColor = RGB(130, 130, 170)
    
    ' raise our form
    RaiseForm
    
    ' initialize our CPU meter
    InitCPU
    
End Sub


Private Sub RaiseForm()
    
    Dim R As RECT
    
    Me.ScaleMode = vbPixels
    SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
    DrawFrameControl Me.hdc, R, DFC_BUTTON, DFCS_BUTTON3STATE
    OffsetRect R, 0, 22

End Sub


Private Sub InitCPU()

    Dim lData As Long
    Dim lType As Long
    Dim lSize As Long
    Dim hKey As Long
    Dim Qry As String
    
    Qry = RegOpenKey(HKEY_DYN_DATA, "PerfStats\StartStat", hKey)
    
    If Qry <> 0 Then
            MsgBox "Could not open registery!"
        End
    End If
    
    lType = REG_DWORD
    lSize = 4
    
    Qry = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0, lType, lData, lSize)
    Qry = RegCloseKey(hKey)

End Sub


Private Sub tmrFormMove_Timer()
    
    Dim Point As POINTAPI
    
    ' get the cursorposition
    GetCursorPos Point

    ' multiply the coordinates to convert twips to pixel and place the form
    Me.Left = Point.X * 15 + 200
    Me.Top = Point.Y * 15 + 150
    
     ' make our form stay on top
    SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE
    
End Sub


Private Sub tmrCpuStatus_Timer()

    Dim lData As Long
    Dim lType As Long
    Dim lSize As Long
    Dim hKey As Long
    Dim Qry As String
    Dim Status As Long
                  
    Qry = RegOpenKey(HKEY_DYN_DATA, "PerfStats\StatData", hKey)
                
    If Qry <> 0 Then
            MsgBox "Could not open registery!"
        End
    End If
                
    lType = REG_DWORD
    lSize = 4
                
    Qry = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0, lType, lData, lSize)
    
    Status = Int(lData)

    ' show CPU usage in Label
    lblStatus.Caption = Status & "%"
    
    ' show CPU usage in our selfmade progressbar
    ' when CPU usage is over 80% then color the status red
    If Status < 80 Then
    picStatus.Line (Status, 0)-(0, 10), RGB(255, 245, 85), BF
    Else
    picStatus.Line (Status, 0)-(0, 10), RGB(245, 10, 0), BF
    End If
    picStatus.Line (Status, 0)-(100, 10), RGB(130, 130, 170), BF
    
    Qry = RegCloseKey(hKey)

End Sub
 


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

29 novembre 2005 16:09:11 :
Rajout des mots clés

 Sources du même auteur

Source avec Zip Source .NET (Dotnet) LISTVIEW SUPPORT TRI MULTI-COLONNES PAR MÉTHODES D'EXTENSION...
Source avec Zip Source avec une capture Source .NET (Dotnet) ROTATION D'ÉCRAN
Source avec Zip Source avec une capture Source .NET (Dotnet) IMAPI2 - GRAVER UN CD AUDIO
Source avec Zip Source avec une capture Source .NET (Dotnet) CONTRÔLES COLOR PICKER: WHEEL COLOR PICKER - SCREEN COLOR PI...
Source avec Zip Source .NET (Dotnet) [.NET3.5] EXTENSION METHODS: SUR LES CLASSES SYSTEM.IO

 Sources de la même categorie

Source avec Zip Source avec une capture AUTORISER/REFUSER L'EXECUTION DE PROCESSUS par pierreh51
Source avec Zip Source .NET (Dotnet) CLONE/FORK DES FLUX DE LA CONSOLE : PERMETTRE LA REDIRECTION... par ShareVB
Source avec Zip Source .NET (Dotnet) DÉFRAGMENTER UN FICHIER par ShareVB
Source avec Zip Source .NET (Dotnet) ECRAN DE VEILLE : DÉTECTER LE LANCEMENT/DÉCLENCHER/EMPÊCHER par ShareVB
Source avec Zip Source avec une capture DESACTIVER / ACTIVER LES MISES EN VEILLES PC par Arsena

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture CPU LIMITER - LIMITEZ L'UTILISATION DU PROCESSEUR DE CHAQUE ... par MadM@tt
Source avec Zip Source avec une capture TEMPS PROCESSEURS TOTAL ET PAR UNITÉ (API NATIVE) par draluorg
Source avec Zip Source avec une capture CLASSE POUR RÉCUPERER L'UTILISATION CPU D'UN PROCESSUS par draluorg
Source avec Zip Source avec une capture CPU_LED, SURVEILLEZ LE FONCTIONNEMENT DE VOTRE PROCESSEUR GR... par Frank9321
Source avec Zip Source avec une capture CPULIGHT : SURVEILLEZ LE FONCTIONNEMENT DE VOTRE PROCESSEUR ... par MadM@tt

Commentaires et avis

Commentaire de DavidT le 25/02/2003 01:04:19

J'suis sur XP et j'ai une erreur "Could Not open registry" !!!

Commentaire de DavidT le 06/03/2003 00:31:58

Moi aussi...

Commentaire de DiJiTooL le 01/08/2003 04:06:43

me too :(

Commentaire de mouff le 01/09/2003 15:56:42

idem..

Commentaire de azerty25 le 06/12/2003 13:36:38

idem

Commentaire de JLN le 21/05/2004 10:49:03

marche pas sous xp !

Commentaire de olivierdubuisson le 30/12/2004 15:03:13

Je suis sous 2000, idem

Commentaire de amylee1984 le 21/02/2006 22:22:14

salut c'est bien , je te donne 10 , c'est ce que je cherche
bon courage willi

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

cpu temperature [ par dido1987 ] bonjour j'ai un processeur type Intel avec des capteur du température DTS mon bios affiche bien la temperature du processeur alos je veux extraire la détection vitesse CPU et carte son [ par begi ] je cherche à connaitre la vitesse du processeur et le modéle de la carte sonmerci :-)begi Détection température CPU et carte Mère [ par EDSOFT ] J'aimerais pouvoir afficher la température du CPU et de la carte mère en VB.MERCI d'avance. Température CPU [ par Pat ] Je recherche le moyen de récupérer la température du CPU dans une application VB.Merci d'avance... Partage des ressources Processeur dispo ! [ par RVTT ] Bonjour,Voilà, je lance un FilesCopy depuis VB et comme la tache est longue (70 Mo sur un reseau...) J'voudrai afficher une petite annim mais celle-ci !! Nom et puissance du processeur? !! [ par jemax ] Salut, si quelqu'un sait comment je peux faire pour trouver quel type de processeur est utilisé et sa puissance, je suis preneur.Merci d'avance VB5 fonctionne-t-il bien avec processeur Duron et Athlon? [ par JacBeau ] Un ami a des problèmes avec VB5 depuis qui a acheté son nouvel ordinateur un Duron 800.Les programmeur qui ont un processeur AMD (Duron ou Athlon) ont numéro de processeur [ par patou1000 ] Comment peut on récupérer le numéro du processeur, quelqu'un peut il me renseigner? svp un numero special dans le BIOS ou CPU [ par benzm ] benzmSVP exist il un numero speciale et unique pour chaque BIOS d un PC c a d le numero se distinct d un PC a un autre meme que ces deux PC sont de la


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,905 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales