Source file: /~heha/hs/t_und_m.zip/SRC/ROLLFANG.PAS

{$A+,B-,D+,F-,G+,I-,L+,N-,P+,Q-,R-,S-,T+,V+,X+,Y+}
{$M 8192,0}	{kein Stack, kein Heap}
library rollfang;
{$W-,K+}
{$C MOVEABLE PRELOAD PERMANENT}	{gleiche Attribute wie Unit SYSTEM}
{$D H„lt Maus-Position beim Bet„tigen des Rollbalkens im Balken}
{$R rollfang.res}	{Versions-Info}

uses WinProcs,WinTypes,Win31;

var
 Hook: HHook;
const
 Hold: TRect=(left:-$8000; top:-$8000; right:$7FFF; bottom:$7FFF);

type
 PtrRec=record
  Ofs,Sel:Word;
 end;
 LongRec=record
  lo,hi: Word;
 end;
 WordRec=record
  lo,hi: Byte;
 end;

function min(I1,I2:Integer):Integer;
 inline($58/$5A/$39/$D0/$7C/$01/$92);
	{pop ax; pop dx; cmp ax,dx; jl $+3; xchg dx,ax}
function max(I1,I2:Integer):Integer;
 inline($58/$5A/$39/$D0/$7F/$01/$92);
	{pop ax; pop dx; cmp ax,dx; jg $+3; xchg dx,ax}

function GetMessageHook(code: Integer; wParam:Word; lParam:LongInt):
  LongInt; export;
 const
  ScrollStr:array[0..11] of Char='PPScrollBar'#0;
 var
  msgp: PMsg absolute lParam;
  P: TPoint;
  R: TRect;
  style: LongInt;
  classname: array[0..31] of Char;
 begin
  GetMessageHook:=CallNextHookEx(Hook,code,wParam,lParam);
  case msgp^.message of
   WM_LButtonDown: begin
    GetClassName(msgp^.hwnd,classname,sizeof(classname));
    if (lstrcmpi(classname,ScrollStr+2)=0)		{Standard}
    or (lstrcmpi(classname,ScrollStr)=0) then begin	{MSDraw}
     GetClientRect(msgp^.hwnd,Hold);
    end;
   end;
   WM_NCLButtonDown: begin
    P:=TPoint(msgp^.lparam);
    ScreenToClient(msgp^.hwnd,P);
    GetClientRect(msgp^.hwnd,R);
    case msgp^.wParam of
     HTVScroll: SetRect(Hold,P.x,R.top,P.x,R.bottom);
     HTHScroll: SetRect(Hold,R.left,P.y,R.right,P.y);
    end;
   end;
   WM_MouseMove,WM_LButtonUp: begin
    if Hold.left<>-$8000 then begin
     TPoint(msgp^.lparam).x:=
       min(max(TPoint(msgp^.lparam).x,Hold.left),Hold.right);
     TPoint(msgp^.lparam).y:=
       min(max(TPoint(msgp^.lparam).y,Hold.top),Hold.bottom);
    end;
   end;
   else exit;
  end;
  case msgp^.message of
   WM_LButtonUp,WM_NCLButtonUp: begin
    Hold.left:=-$8000;		{Koordinaten-Fang aufheben!}
   end;
  end;
 end;

procedure WEP;
 begin
  UnhookWindowsHookEx(Hook);
 end;

begin
 Hook:=SetWindowsHookEx(WH_GetMessage,GetMessageHook,HInstance,0);
end.
Detected encoding: UTF-80