home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 April / PCpro_2007_04.ISO / files / dsl / NVinst.exe / Scripts / Scripter / BackgroundLowPriority.nvs next >
Encoding:
Text File  |  2007-02-10  |  1.6 KB  |  45 lines

  1. program BackgroundLowPriority;
  2. {
  3. This script automatically sets NetView's priority to below normal 
  4. if NetView is not active and changes it to normal when NetView activated
  5. }
  6. function GetForegroundWindow: Longint; external 'GetForegroundWindow@user32.dll stdcall';
  7. function GetWindowThreadProcessId(wnd:Longint;var pid:Longint): Longint; external 'GetWindowThreadProcessId@user32.dll stdcall';
  8. function GetCurrentProcessId:Longint; external 'GetCurrentProcessId@kernel32.dll stdcall';
  9. function GetCurrentProcess:Longint; external 'GetCurrentProcess@kernel32.dll stdcall';
  10. function SetPriorityClass(prc:longint;prcl:longint):Longint; external 'SetPriorityClass@kernel32.dll stdcall';
  11.  
  12. const NORMAL_PRIORITY_CLASS=       $00000020;
  13. const IDLE_PRIORITY_CLASS=         $00000040;
  14. const HIGH_PRIORITY_CLASS=         $00000080;
  15. const REALTIME_PRIORITY_CLASS=     $00000100;
  16. const BELOW_NORMAL_PRIORITY_CLASS= $00004000;
  17. const ABOVE_NORMAL_PRIORITY_CLASS= $00008000;
  18.  
  19. const UpdateInterval=2000;//in milliseconds
  20. const MY_FOREGROUND_PRIORITY=NORMAL_PRIORITY_CLASS;
  21. const MY_BACKGROUND_PRIORITY=BELOW_NORMAL_PRIORITY_CLASS;
  22.  
  23. var v,v1,v2:integer;
  24.     fwnd,oldfwnd,fpid,mypid:longint;
  25. begin
  26. mypid:=GetCurrentProcessId;
  27. SetTimer(UpdateInterval);
  28. repeat
  29. v:=WaitEvent(v1,v2);
  30. if(v=8)then
  31.  begin
  32.  fwnd:=GetForegroundWindow;
  33.  if fwnd<>oldfwnd then
  34.   begin
  35.   GetWindowThreadProcessId(fwnd,fpid);
  36.   if fpid=mypid then SetPriorityClass(GetCurrentProcess,MY_FOREGROUND_PRIORITY)
  37.                 else SetPriorityClass(GetCurrentProcess,MY_BACKGROUND_PRIORITY);
  38.   oldfwnd:=fwnd;
  39.   end;
  40.  end;
  41. until v=0;
  42. SetTimer(0);
  43. end.
  44.  
  45.