home *** CD-ROM | disk | FTP | other *** search
- program BackgroundLowPriority;
- {
- This script automatically sets NetView's priority to below normal
- if NetView is not active and changes it to normal when NetView activated
- }
- function GetForegroundWindow: Longint; external 'GetForegroundWindow@user32.dll stdcall';
- function GetWindowThreadProcessId(wnd:Longint;var pid:Longint): Longint; external 'GetWindowThreadProcessId@user32.dll stdcall';
- function GetCurrentProcessId:Longint; external 'GetCurrentProcessId@kernel32.dll stdcall';
- function GetCurrentProcess:Longint; external 'GetCurrentProcess@kernel32.dll stdcall';
- function SetPriorityClass(prc:longint;prcl:longint):Longint; external 'SetPriorityClass@kernel32.dll stdcall';
-
- const NORMAL_PRIORITY_CLASS= $00000020;
- const IDLE_PRIORITY_CLASS= $00000040;
- const HIGH_PRIORITY_CLASS= $00000080;
- const REALTIME_PRIORITY_CLASS= $00000100;
- const BELOW_NORMAL_PRIORITY_CLASS= $00004000;
- const ABOVE_NORMAL_PRIORITY_CLASS= $00008000;
-
- const UpdateInterval=2000;//in milliseconds
- const MY_FOREGROUND_PRIORITY=NORMAL_PRIORITY_CLASS;
- const MY_BACKGROUND_PRIORITY=BELOW_NORMAL_PRIORITY_CLASS;
-
- var v,v1,v2:integer;
- fwnd,oldfwnd,fpid,mypid:longint;
- begin
- mypid:=GetCurrentProcessId;
- SetTimer(UpdateInterval);
- repeat
- v:=WaitEvent(v1,v2);
- if(v=8)then
- begin
- fwnd:=GetForegroundWindow;
- if fwnd<>oldfwnd then
- begin
- GetWindowThreadProcessId(fwnd,fpid);
- if fpid=mypid then SetPriorityClass(GetCurrentProcess,MY_FOREGROUND_PRIORITY)
- else SetPriorityClass(GetCurrentProcess,MY_BACKGROUND_PRIORITY);
- oldfwnd:=fwnd;
- end;
- end;
- until v=0;
- SetTimer(0);
- end.
-
-