Accueil > > > CHARGE DU CPU
CHARGE DU CPU
Information sur la source
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
Historique
- 29 novembre 2005 16:09:11 :
- Rajout des mots clés
Sources du même auteur
Sources de la même categorie
Commentaires et avis
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
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
LISTER KEYS.KEYLISTER KEYS.KEY par Onin42
Cliquez pour lire la suite par Onin42
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|