Změna priority procesu

Postup:
V deklarační části formuláře zapište:

Private Declare Function CloseHandle Lib "kernel32" _
  (ByVal hObject As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" _
  (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
  ByVal dwProcessId As Long) As Long

Private Declare Function GetWindowThreadProcessId Lib "user32" _
  (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Private Declare Function SetPriorityClass Lib "kernel32" _
  (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long

Private Const REALTIME_PRIORITY_CLASS = &H100
Private Const HIGH_PRIORITY_CLASS = &H80
Private Const NORMAL_PRIORITY_CLASS = &H20
Private Const IDLE_PRIORITY_CLASS = &H40

Na událost Form_Load:
Private Sub Form_Load()

   Dim lRet As Long
   Dim lProcessID As Long
   Dim lProcessHandle As Long

   'Nahrazením me.hwnd handlem na jiné okno
   'změníte prioritu jiné aplikace
   GetWindowThreadProcessId Me.hwnd, lProcessID

   'handle procesu
   lProcessHandle = OpenProcess(0, False, lProcessID)

   'Nastavení priority
   'lRet <> 0 - změna byla úspěšná

   lRet = SetPriorityClass(lProcessHandle, HIGH_PRIORITY_CLASS)

   'Zavření handlu
   lRet = CloseHandle(lProcessHandle)

End Sub

Zpět

Autor: The Bozena