Comment changer la priorité de votre application ?
Mettez les Declaration Suivantes :
Source / Exemple :
Option Explicit
Public Const NORMAL_PRIORITY_CLASS = &H20
Public Const IDLE_PRIORITY_CLASS = &H40
Public Const HIGH_PRIORITY_CLASS = &H80
Public Const REALTIME_PRIORITY_CLASS = &H100
Public Const PROCESS_DUP_HANDLE = &H40
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Declare Function SetPriorityClass& Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long)
' Puis mettez ce code dans votre Module :
Public Sub ChangePriority(dwPriorityClass As Long)
Dim hProcess&
Dim ret&, pid&
pid = GetCurrentProcessId() ' Récupérer Mon No de Process
' Récupérer un Handle pour le Process
hProcess = OpenProcess(PROCESS_DUP_HANDLE, True, pid)
If hProcess = 0 Then
Err.Raise 2, "ChangePriority", "Impossible d'ouvrir le process"
Exit Sub
End If
' Change le priorité
ret = SetPriorityClass(hProcess, dwPriorityClass)
' Fermeture du Handle du Process
Call CloseHandle(hProcess)
If ret = 0 Then
Err.Raise 4, "ChangePriority", "Impossible de Fermer le process"
Exit Sub
End If
End Sub
Private Sub Form_Load()
Timer1.Interval = 2000
Call Timer1_Timer
End Sub
Private Sub Timer1_Timer()
Static Priority&
If Priority = IDLE_PRIORITY_CLASS Then
Priority = HIGH_PRIORITY_CLASS
Label1.Caption = "Priorité HAUTE !"
Else
Label1.Caption = "Priorité RALENTI"
Priority = IDLE_PRIORITY_CLASS
End If
Call ChangePriority(Priority)
End Sub
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.