home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d56 / RMCTL.ZIP / rmCornerGrip.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-22  |  5KB  |  197 lines

  1. {================================================================================
  2. Copyright (C) 1997-2001 Mills Enterprise
  3.  
  4. Unit     : rmCornerGrip
  5. Purpose  : Allow for a working "Size Grip" to be placed on the components
  6.            owner form.
  7. Date     : 10-26-2000
  8. Author   : Ryan J. Mills
  9. Version  : 1.80
  10. ================================================================================ }
  11.  
  12. unit rmCornerGrip;
  13.  
  14. interface
  15.  
  16. {$I CompilerDefines.INC}
  17.  
  18. uses
  19.   Windows, Messages, Classes, forms, Controls;
  20.  
  21. type
  22.   TrmCornerGrip = class(TComponent)
  23.   private
  24.     { Private declarations }
  25.     OldWndProc: TFarProc;
  26.     NewWndProc: Pointer;
  27.  
  28.     fHeight : integer;
  29.     fWidth : integer;
  30.     fCanPaint : boolean;
  31.  
  32.     procedure HookWndProc(var AMsg: TMessage);
  33.     procedure HookWin;
  34.     procedure UnhookWin;
  35.     procedure setHeight(const Value: integer);
  36.     procedure setwidth(const Value: integer);
  37.   protected
  38.     { Protected declarations }
  39.     procedure Paint;
  40.     function GripRect:TRect;
  41.     function GripTestRect:TRect;
  42.   public
  43.     { Public declarations }
  44.     constructor create(AOwner : TComponent); override;
  45.     destructor destroy; override;
  46.   published
  47.     { Published declarations }
  48.     property Height:integer read fheight write setHeight default 15;
  49.     property Width :integer read fWidth write setwidth default 20;
  50.   end;
  51.  
  52. implementation
  53.  
  54. Uses rmglobalComponentHook, Graphics;
  55.  
  56. type
  57.     TWinControlInvasion = class(TWinControl)
  58.     end;
  59.  
  60. { TrmCornerGrip }
  61.  
  62. constructor TrmCornerGrip.create(AOwner: TComponent);
  63. begin
  64.   inherited;
  65.   fHeight := 15;
  66.   fwidth := 20;
  67.   fCanPaint := true;
  68.   HookWin;
  69. end;
  70.  
  71. destructor TrmCornerGrip.destroy;
  72. begin
  73.   UnhookWin;
  74.   inherited;
  75. end;
  76.  
  77. procedure TrmCornerGrip.HookWin;
  78. begin
  79.   if csdesigning in componentstate then exit;
  80.   if not assigned(NewWndProc) then
  81.   begin
  82.     OldWndProc := TFarProc(GetWindowLong(TForm(Owner).handle, GWL_WNDPROC));
  83.     {$ifdef BD6}
  84.     NewWndProc := Classes.MakeObjectInstance(HookWndProc);
  85.     {$else}
  86.     NewWndProc := MakeObjectInstance(HookWndProc);
  87.     {$endif}
  88.     SetWindowLong(TForm(Owner).handle, GWL_WNDPROC, LongInt(NewWndProc));
  89.     PushOldProc(TForm(Owner), OldWndProc);
  90.   end;
  91. end;
  92.  
  93. procedure TrmCornerGrip.UnhookWin;
  94. begin
  95.   if csdesigning in componentstate then exit;
  96.   if assigned(NewWndProc) then
  97.   begin
  98.     SetWindowLong(TForm(Owner).handle, GWL_WNDPROC, LongInt(PopOldProc(TForm(Owner))));
  99.     if assigned(NewWndProc) then
  100.     {$ifdef BD6}
  101.        Classes.FreeObjectInstance(NewWndProc);
  102.     {$else}
  103.        FreeObjectInstance(NewWndProc);
  104.     {$endif}
  105.     NewWndProc := nil;
  106.     OldWndProc := nil;
  107.   end;
  108. end;
  109.  
  110. procedure TrmCornerGrip.HookWndProc(var AMsg: TMessage);
  111. var
  112.    wPt : TPoint;
  113.    wRect : TRect;
  114. begin
  115.   case AMsg.msg of
  116.     wm_destroy:
  117.        begin
  118.           AMsg.Result := CallWindowProc(OldWndProc, Tform(Owner).handle, AMsg.Msg, AMsg.wParam, AMsg.lParam);
  119.           UnHookWin;
  120.           exit;
  121.        end;
  122.     wm_NCHitTest:
  123.        begin
  124.           wPt.x := aMsg.lParam and $0000FFFF;
  125.           wPT.y := (amsg.lparam and $FFFF0000) shr 16;
  126.           wRect := GripTestRect;
  127.           if ptInRect(wRect,wPT) then
  128.           begin
  129.              AMsg.Result := HTBOTTOMRIGHT;
  130.              Paint;
  131.              exit;
  132.           end
  133.        end;
  134.     WM_ENTERSIZEMOVE:
  135.        begin
  136.           fCanPaint := False;
  137.           Tform(Owner).Repaint;
  138.        end;
  139.   end;
  140.  
  141.   AMsg.Result := CallWindowProc(OldWndProc, Tform(Owner).handle, AMsg.Msg, AMsg.wParam, AMsg.lParam);
  142.  
  143.   case AMsg.msg of
  144.     WM_EXITSIZEMOVE:
  145.     begin
  146.        fCanPaint := true;
  147.        Paint;
  148.     end;
  149.     WM_ERASEBKGND:
  150.      begin
  151.         paint;
  152.      end;
  153.   end;
  154. end;
  155.  
  156. procedure TrmCornerGrip.Paint;
  157. var
  158.    wRect : TRect;
  159. begin
  160.    if csdesigning in componentstate then exit;
  161.    if not fCanPaint then exit;
  162.  
  163.    wrect := GripRect;
  164.    wRect.Left := wRect.Left;
  165.    wRect.Top := wRect.top;
  166.    Tform(Owner).Update;
  167.    DrawFrameControl(Tform(Owner).Canvas.handle, wRect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP)
  168. end;
  169.  
  170. procedure TrmCornerGrip.setHeight(const Value: integer);
  171. begin
  172.   fheight := Value;
  173.   Paint;
  174. end;
  175.  
  176. procedure TrmCornerGrip.setwidth(const Value: integer);
  177. begin
  178.   fWidth := Value;
  179.   Paint;
  180. end;
  181.  
  182. function TrmCornerGrip.GripRect: TRect;
  183. begin
  184.    result := TForm(Owner).ClientRect;
  185.    result.top := result.bottom - fHeight;
  186.    result.Left := result.right - fWidth;
  187. end;
  188.  
  189. function TrmCornerGrip.GripTestRect: TRect;
  190. begin
  191.    result := TForm(Owner).BoundsRect;
  192.    result.top := result.bottom - fHeight;
  193.    result.Left := result.right - fWidth;
  194. end;
  195.  
  196. end.
  197.