powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Delphi [игнор отключен] [закрыт для гостей] / Как отловить событие?
4 сообщений из 4, страница 1 из 1
Как отловить событие?
    #39761954
FIL23
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Добрых суток,

есть вот такой код

Код: pascal
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
 
procedure TfmTemplateOfInventory.DblClick(Sender: TObject);    //èçìåíåíèÿ ðàçìåðà îáüåêòà
var
perHWND:HWND;
begin
if (Sender is TGroupBox) then perHWND:=(sender as TGroupBox).Handle;

  SetWindowLong(perHWND,GWL_STYLE,GetWindowLong(perHWND,GWL_STYLE) xor WS_THICKFRAME);
  SetWindowPos(perHWND,HWND_TOP,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or SWP_DRAWFRAME or SWP_NOACTIVATE);   
end; 



Т.е. при нажатии на компоненту (динамическую (не столь важно), появляется рамка которая позволяет изменять размер компонента.

Хочу получать значения размера рамки в реальном времени. но на событие onmousemove у динамического объекта не срабатывает

Как быть?
...
Рейтинг: 0 / 0
Как отловить событие?
    #39761955
Dimitry Sibiryakov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
FIL23Как быть?

Выкинуть говнокод. После нажатия кнопки мыши захватывать её и рисовать прямоугольник,
например, с помощью DrawFocusRect до отпускания мыши. По отпусканию - присваивать
компоненту новый Rect.
Posted via ActualForum NNTP Server 1.5
...
Рейтинг: 0 / 0
Как отловить событие?
    #39762022
FIL23
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Нашел вот такой компонент

Handles.pas
Код: pascal
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
446.
447.
448.
449.
450.
451.
452.
453.
454.
455.
456.
457.
458.
459.
460.
461.
462.
463.
464.
465.
466.
467.
468.
469.
470.
471.
472.
473.
474.
475.
476.
477.
478.
479.
480.
481.
482.
483.
484.
485.
486.
487.
488.
489.
490.
491.
492.
493.
494.
495.
496.
497.
498.
499.
500.
501.
502.
503.
504.
505.
506.
507.
508.
509.
510.
511.
512.
513.
514.
515.
516.
517.
518.
519.
520.
521.
522.
523.
524.
525.
526.
527.
528.
529.
530.
531.
532.
533.
534.
535.
536.
537.
538.
539.
540.
541.
542.
543.
544.
545.
546.
547.
548.
549.
550.
551.
552.
553.
554.
555.
556.
557.
558.
559.
560.
561.
562.
563.
564.
565.
566.
567.
568.
569.
570.
571.
572.
573.
574.
575.
576.
577.
578.
579.
580.
581.
582.
583.
584.
585.
586.
587.
588.
589.
590.
591.
592.
593.
594.
595.
596.
597.
598.
599.
600.
601.
602.
603.
604.
605.
606.
607.
608.
609.
610.
611.
612.
613.
614.
615.
616.
617.
618.
619.
620.
621.
622.
623.
624.
625.
626.
627.
628.
629.
630.
631.
632.
633.
634.
635.
636.
637.
638.
639.
640.
641.
642.
643.
644.
645.
646.
647.
648.
649.
650.
651.
652.
653.
654.
655.
656.
657.
658.
659.
660.
661.
662.
663.
664.
665.
666.
667.
668.
669.
670.
671.
672.
673.
674.
675.
676.
677.
678.
679.
680.
681.
682.
683.
684.
685.
686.
687.
688.
689.
690.
691.
692.
693.
694.
695.
696.
697.
698.
699.
700.
701.
702.
703.
704.
705.
706.
707.
708.
709.
710.
711.
712.
713.
714.
715.
716.
717.
718.
719.
720.
721.
722.
723.
724.
725.
726.
727.
728.
729.
730.
731.
732.
733.
734.
735.
736.
737.
738.
739.
740.
741.
742.
743.
744.
745.
746.
747.
748.
749.
750.
751.
752.
753.
754.
755.
756.
757.
758.
759.
760.
761.
762.
763.
764.
765.
766.
767.
768.
769.
770.
771.
772.
773.
774.
775.
776.
777.
778.
779.
780.
781.
782.
783.
784.
785.
786.
787.
788.
789.
790.
791.
792.
793.
794.
795.
796.
797.
798.
799.
800.
801.
802.
803.
804.
805.
806.
807.
808.
809.
810.
811.
812.
813.
814.
815.
816.
817.
818.
819.
820.
821.
822.
823.
824.
825.
826.
827.
828.
829.
830.
831.
832.
833.
834.
835.
836.
837.
838.
839.
840.
841.
842.
843.
844.
845.
846.
847.
848.
849.
850.
851.
852.
853.
854.
855.
856.
857.
858.
859.
860.
861.
862.
863.
864.
865.
866.
867.
868.
869.
870.
871.
872.
873.
874.
875.
876.
877.
878.
879.
880.
881.
882.
883.
884.
885.
886.
887.
888.
889.
890.
891.
892.
893.
894.
895.
896.
897.
898.
899.
900.
901.
902.
903.
904.
905.
906.
907.
908.
909.
910.
911.
912.
913.
914.
915.
916.
917.
918.
919.
920.
921.
922.
923.
924.
925.
926.
927.
928.
929.
930.
931.
932.
933.
934.
935.
936.
937.
938.
939.
940.
941.
942.
943.
944.
945.
946.
947.
948.
949.
950.
951.
952.
953.
954.
955.
956.
957.
958.
959.
960.
961.
unit Handles;

{ TStretchHandles is a transparent control to implement runtime grab handles
  for Forms Designer-like projects.  It paints the handles on its own canvas,
  maintains a list of the controls it is supposed to manage, and traps mouse
  and keyboard events to move/resize itself and its child controls.  See the
  accompanying README file for more information.

  Distributed by the author as freeware, please do not sell.

  Anthony Scott
  CIS: 75567,3547                                                              }

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Menus, StdCtrls, Dialogs;
                                       { miscellaneous type declarations }
type
  TDragStyle = (dsMove, dsSizeTopLeft, dsSizeTopRight, dsSizeBottomLeft, dsSizeBottomRight,
                dsSizeTop, dsSizeLeft, dsSizeBottom, dsSizeRight);
  TForwardMessage = (fmMouseDown, fmMouseUp);
  GridValues = 1..32;
  EBadChild = class(Exception);
                                       { TStretchHandle component declaration }
type
  TStretchHandle = class(TCustomControl)
  private
    FDragOffset: TPoint;
    FDragStyle: TDragStyle;
    FDragging: boolean;
    FDragRect: TRect;
    FLocked: boolean;
    FPrimaryColor: TColor;
    FSecondaryColor: TColor;
    FGridX, FGridY: GridValues;
    FChildList: TList;
    procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
    procedure WMGetDLGCode(var Message: TMessage); message WM_GETDLGCODE;
    procedure Rubberband(XPos, YPos: integer; ShowBox: boolean);
    procedure ForwardMessage(FwdMsg: TForwardMessage; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure SetPrimaryColor(Color: TColor);
    procedure SetSecondaryColor(Color: TColor);
    procedure SetGridState(Value: boolean);
    function GetGridState: boolean;
    function GetChildCount: integer;
    function GetChildControl(idx: integer): TControl;
    function GetModifiedRect(XPos, YPos: integer): TRect;
    function PointOverChild(P: TPoint): boolean;
    function XGridAdjust(X: integer): integer;
    function YGridAdjust(Y: integer): integer;
    function IsAttached: boolean;
  protected

    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure KeyDown(var key: Word; Shift: TShiftState); override;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure Paint; override;
    property Canvas;
  public


    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Attach(ChildControl: TControl);
    procedure Detach;
    procedure ReleaseChild(ChildControl: TControl);
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
    procedure BringToFront;
    procedure SendToBack;
    procedure SetColors(Color1, Color2: TColor);
    function IndexOf(ChildControl: TControl): integer;
                                       { new run-time only properties }
    property Attached: boolean read IsAttached;
    property ChildCount: integer read GetChildCount;
    property Children[idx: integer]: TControl read GetChildControl;
  published
                                       { new properties }
    property Color: TColor read FPrimaryColor write SetPrimaryColor default clBlack;
    property SecondaryColor: TColor read FSecondaryColor write SetSecondaryColor default clGray;
    property Locked: boolean read FLocked write FLocked default False;
    property GridX: GridValues read FGridX write FGridX default 8;
    property GridY: GridValues read FGridY write FGridY default 8;
    property SnapToGrid: boolean read GetGridState write SetGridState default False;
                                       { inherited properties }
    property DragCursor;
    property Enabled;
    property Hint;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property Visible;
                                       { defined events }
    property OnClick;
    property OnDblClick;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnKeyDown;
    property OnKeyUp;
    property OnKeyPress;
  end;

procedure Register;
function MinInt(a, b: integer): integer;
function MaxInt(a, b: integer): integer;

implementation
 uses unTemplateOfInventory   ;
procedure Register;
begin
                                       { add the component to the 'Samples' tab }
  RegisterComponents('CyD', [TStretchHandle]);

end;

constructor TStretchHandle.Create(AOwner: TComponent);
begin

  inherited Create(AOwner);
                                       { create storage for child objects }
  FChildList := TList.Create;
                                       { initialize default properties }
  Width := 24;
  Height := 24;
  FPrimaryColor := clBlack;
  FSecondaryColor := clGray;
                                       { a value of 1 is used to effectively disable the snap-to grid }
  FGridX := 1;
  FGridY := 1;
                                       { doesn't do anything until it is Attached to something else }
  Enabled := False;
  Visible := False;

end;

destructor TStretchHandle.Destroy;
begin
                                       { tidy up carefully }                                                                
  FChildList.Free;
  inherited Destroy;

end;

procedure TStretchHandle.CreateParams(var Params: TCreateParams);
begin
                                       { set default Params values }
  inherited CreateParams(Params);
                                       { then add transparency; ensures correct repaint order }
  Params.ExStyle := Params.ExStyle + WS_EX_TRANSPARENT;

end;

procedure TStretchHandle.WMGetDLGCode(var Message: TMessage);
begin
                                       { get arrow key press events }
  Message.Result := DLGC_WANTARROWS;

end;

procedure TStretchHandle.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
                                       { completely fake erase, don't call inherited, don't collect $200 }
  Message.Result := 1;

end;

procedure TStretchHandle.Attach(ChildControl: TControl);
var
  L, T, W, H: integer;
begin
                                       { definitely not allowed! }
  if ChildControl is TForm then
    raise EBadChild.Create('Handles can not be attached to a Form!');
                                       { add child component to unique list managed by TStretchHandle }
  if (ChildControl <> nil) and (FChildList.IndexOf(TObject(ChildControl)) = -1) then
    begin
                                       { make sure new child's Parent matches siblings }
      if (FChildList.Count > 0) and (ChildControl.Parent <> Parent) then
        Detach;
                                       { initialize when first child is attached }
      if FChildList.Count = 0 then
        begin
          Parent := ChildControl.Parent;
                                       { only make it visible now, to avoid color flashing, & accept events }
          FDragRect := Rect(0, 0, 0, 0);
          Enabled := True;
          Visible := True;
          inherited SetBounds(ChildControl.Left - 2, ChildControl.Top - 2, ChildControl.Width + 5, ChildControl.Height + 5);

        end
      else
        begin
                                       { set size to bound all children, plus room for handles }
          L := MinInt(Left, ChildControl.Left - 2);
          T := MinInt(Top, ChildControl.Top - 2);
          W := Maxint(Left + Width - 3, ChildControl.Left + ChildControl.Width) - L + 3;
          H := Maxint(Top + Height - 3, ChildControl.Top + ChildControl.Height) - T + 3;
          inherited SetBounds(L, T, W, H);

        end;
                                       { add to list of active Children }
      FChildList.Add(TObject(ChildControl));
                                       { re-set DragStyle }
      FDragStyle := dsMove;
                                       { use old BringToFront so as not to change Child's Z-order }
      if not (csDesigning in ComponentState) then
        begin
          inherited BringToFront;
                                       { allow us to get Mouse events immediately! }
          SetCapture(Handle);
                                       { get keyboard events }
          if Visible and Enabled then
            SetFocus;
        end;

    end;

end;

procedure TStretchHandle.Detach;
begin
                                       { remove all Child components from list }
  if FChildList.Count > 0 then
    with FChildList do
      repeat
        Delete(0);
      until Count = 0;
                                       { disable & hide StretchHandle }
  FLocked := False;
  Width := 24;
  Height := 24;
  Enabled := False;
  Visible := False;
  Parent := nil;
  FDragRect := Rect(0, 0, 0, 0);
end;

procedure TStretchHandle.ReleaseChild(ChildControl: TControl);
var
  idx, L, T, W, H: integer;
  AControl: TControl;
begin
                                       { delete the Child if it exists in the list }
  idx := FChildList.IndexOf(TObject(ChildControl));
  if (ChildControl <> nil) and (idx >= 0) then
    FChildList.Delete(idx);
                                       { disable & hide StretchHandle if no more children }
  if FChildList.Count = 0 then
    begin
      FLocked := False;
      Enabled := False;
      Visible := False;
      Parent := nil;
      FDragRect := Rect(0, 0, 0, 0);
    end
  else
    begin
                                       { set size to bound remaining children, plus room for handles }
      L := TControl(FChildList.Items[0]).Left - 2;
      T := TControl(FChildList.Items[0]).Top - 2;
      W := TControl(FChildList.Items[0]).Width + 3;
      H := TControl(FChildList.Items[0]).Height + 3;

      for idx := 0 to FChildList.Count - 1 do
        begin
          AControl := TControl(FChildList.Items[idx]);
          L := MinInt(L, AControl.Left - 2);
          T := MinInt(T, AControl.Top - 2);
          W := Maxint(L + W - 3, AControl.Left + AControl.Width) - L + 3;
          H := Maxint(T + H - 3, AControl.Top + AControl.Height) - T + 3;
        end;

      inherited SetBounds(L, T, W, H);

    end;

end;

function TStretchHandle.IndexOf(ChildControl: TControl): integer;
begin
                                       { simply pass on the result... }
  Result := FChildList.IndexOf(TObject(ChildControl));

end;

procedure TStretchHandle.BringToFront;
var
  i: integer;
begin
                                       { do nothing if not Attached }
  if Attached and not Locked then
    begin
                                       { take care of Children first, in Attach order }
      for i := 0 to FChildList.Count - 1 do
        begin
          TControl(FChildList[i]).BringToFront;
        end;
                                       { make sure keyboard focus is restored }
      inherited BringToFront;
      if Visible and Enabled then
        SetFocus;
    end;

end;

procedure TStretchHandle.SendToBack;
var
  i: integer;
begin
                                       { do nothing if not Attached }
  if Attached and not Locked then
    begin
                                       { take care of Children first, in Attach order }
      for i := 0 to FChildList.Count - 1 do
        begin
          TControl(FChildList[i]).SendToBack;
        end;
                                       { Handles stay in front of everything, always }
      inherited BringToFront;
      if Visible and Enabled then
        SetFocus;
    end;

end;

procedure TStretchHandle.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
                                       { only process MouseDown if it is over a Child, else forward }
  if PointOverChild(Point(Left + X, Top + Y)) then
    begin
      if (Button = mbLeft) and not FLocked then
        begin
          FDragOffset := Point(X, Y);
          FDragging := True;
        end;
      inherited MouseDown(Button, Shift, X, Y);
    end
  else
    begin
      Cursor := crDefault;
      SetCursor(Screen.Cursors[Cursor]);
      ForwardMessage(fmMouseDown, Button, Shift, Left + X, Top + Y);
    end;

end;

procedure TStretchHandle.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  ARect: TRect;
begin
                                       { resize, reposition if anything changed }
  if FDragging and (Button = mbLeft) then
    begin
                                       { disallow drop off Parent }
      if (Left + X) < 0 then
        X := -Left;
      if (Top + Y) < 0 then
        Y := -Top;
      if (Left + X) > Parent.Width then
        X := Parent.Width - Left;
      if (Top + Y) > Parent.Height then
        Y := Parent.Height - Top;
                                       { force Paint when size doesn't change but position does }
      if (X <> FDragOffset.X) or (Y <> FDragOffset.Y) then
        begin
          Invalidate;
          ARect := GetModifiedRect(X, Y);
          SetBounds(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
        end;
                                       { clear drag outline }
      RubberBand(0, 0, False);
                                       { seem to need this for keyboard events }
      if Visible and Enabled then
        SetFocus;

      FDragging := False;
      Cursor := crDefault;
      ReleaseCapture;
                                       { perform default processing }
      inherited MouseUp(Button, Shift, X, Y);

    end
  else
    ForwardMessage(fmMouseUp, Button, Shift, Left + X, Top + Y);

end;

procedure TStretchHandle.MouseMove(Shift: TShiftState; X, Y: Integer);
var
  ARect: TRect;
  DragStyle: TDragStyle;
begin
                                       { this may be a move immediately on Attach instead of MouseDown }
  if (ssLeft in Shift) and not FDragging and not FLocked then
    begin
      FDragOffset := Point(X, Y);
      FDragging := True;
    end
                                       { only recognize move after simulated MouseDown }
  else
    begin
                                       { let's not hog mouse events unnecessarily } 
      if not (ssLeft in Shift) then
        ReleaseCapture;
                                       { default to drag cursor only when dragging }
      DragStyle := dsMove;
      Cursor := crDefault;
                                       { disallow resize if multiple children }
      if FChildList.Count = 1 then
        begin

          ARect := GetClientRect;
                                       { so I don't like long nested if statements... }
          if ((Abs(X - ARect.Left) < 5) and (Abs(Y - ARect.Top) < 5)) then
            begin
              DragStyle := dsSizeTopLeft;
              Cursor := crSizeNWSE;
            end;

          if ((Abs(X - ARect.Right) < 5) and (Abs(Y - ARect.Bottom) < 5)) then
            begin
              DragStyle := dsSizeBottomRight;
              Cursor := crSizeNWSE;
            end;

          if ((Abs(X - ARect.Right) < 5) and (Abs(Y - ARect.Top) < 5)) then
            begin
              DragStyle := dsSizeTopRight;
              Cursor := crSizeNESW;
            end;

          if ((Abs(X - ARect.Left) < 5) and (Abs(Y - ARect.Bottom) < 5)) then
            begin
              DragStyle := dsSizeBottomLeft;
              Cursor := crSizeNESW;
            end;

          if ((Abs(X - trunc(ARect.Right - ARect.Left) / 2) < 3) and (Abs(Y - ARect.Top) < 5)) then
            begin
              DragStyle := dsSizeTop;
              Cursor := crSizeNS;
            end;

          if ((Abs(X - trunc(ARect.Right - ARect.Left) / 2) < 3) and (Abs(Y - ARect.Bottom) < 5)) then
            begin
              DragStyle := dsSizeBottom;
              Cursor := crSizeNS;
            end;

          if ((Abs(Y - trunc(ARect.Bottom - ARect.Top) / 2) < 3) and (Abs(X - ARect.Left) < 5)) then
            begin
              DragStyle := dsSizeLeft;
              Cursor := crSizeWE;
            end;

          if ((Abs(Y - trunc(ARect.Bottom - ARect.Top) / 2) < 3) and (Abs(X - ARect.Right) < 5)) then
            begin
              DragStyle := dsSizeRight;
              Cursor := crSizeWE;
            end;

        end;
                                       { if position-locked, override cursor change }
      if FLocked then
        Cursor := crNoDrop;

      if FDragging then
        begin
                                       { disallow drag off Parent }
          if (Left + X) < 0 then
            X := -Left;
          if (Top + Y) < 0 then
            Y := -Top;
          if (Left + X) > Parent.Width then
            X := Parent.Width - Left;
          if (Top + Y) > Parent.Height then
            Y := Parent.Height - Top;
                                       { display cursor & drag outline }
          if FDragStyle = dsMove then
            Cursor := DragCursor;
          SetCursor(Screen.Cursors[Cursor]);
          RubberBand(X, Y, True);

        end
      else
        FDragStyle := DragStyle;

  end;
                                       { perform default processing }
  inherited MouseMove(Shift, X, Y);

end;

procedure TStretchHandle.ForwardMessage(FwdMsg: TForwardMessage; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i: integer;
  Found: boolean;
  Msg: Word;
  ARect: TRect;
  AControl: TControl;
  AMessage: TMessage;
begin
                                       { construct the message to be sent }
  case FwdMsg of
    fmMouseDown:
      case Button of
        mbLeft:
          Msg := WM_LBUTTONDOWN;
        mbMiddle:
          Msg := WM_MBUTTONDOWN;
        mbRight:
          Msg := WM_RBUTTONDOWN;
      end;
    fmMouseUp:
      case Button of
        mbLeft:
          Msg := WM_LBUTTONUP;
        mbMiddle:
          Msg := WM_MBUTTONUP;
        mbRight:
          Msg := WM_RBUTTONUP;
      end;
  end;

  AMessage.WParam := 0;
                                       { determine whether X, Y is over any other windowed control }
  Found := False;
  for i := 0 to Parent.ControlCount - 1 do
    begin
      AControl := TControl(Parent.Controls[i]);
      if (AControl is TWinControl) and not (AControl is TStretchHandle) then
        begin
          ARect := Rect(AControl.Left,
                        AControl.Top,
                        AControl.Left + AControl.Width,
                        AControl.Top + AControl.Height);
                                        { X, Y are relative to Parent }
          if PtInRect(ARect, Point(X, Y)) then
            begin
              Found := True;
              break;
            end;
        end;
    end;
                                        { forward the message to the control if found, else to the Parent }
  if Found then
    begin
      AMessage.LParamLo := X - AControl.Left;
      AMessage.LParamHi := Y - AControl.Top;
      SendMessage(TWinControl(AControl).Handle, Msg, AMessage.WParam, AMessage.LParam);
    end
  else
    begin
      AMessage.LParamLo := X;
      AMessage.LParamHi := Y;
      SendMessage(Parent.Handle, Msg, AMessage.WParam, AMessage.LParam);
    end;

end;

procedure TStretchHandle.KeyDown(var Key: Word; Shift: TShiftState);
begin
                                       { process arrow keys to move/resize Handles & Child, also move siblings }
  case Key of
    VK_UP:
      begin
        Invalidate;
        SetBounds(Left, Top - 1, Width, Height);
      end;
    VK_DOWN:
      begin
        Invalidate;
        SetBounds(Left, Top + 1, Width, Height);
      end;
    VK_LEFT:
      begin
        Invalidate;
        SetBounds(Left - 1, Top, Width, Height);
      end;
    VK_RIGHT:
      begin
        Invalidate;
        SetBounds(Left + 1, Top, Width, Height);
      end;
  end;

  inherited KeyDown(Key, Shift);

end;

function TStretchHandle.GetModifiedRect(XPos, YPos: integer): TRect;
var
  ARect: TRect;
begin
                                       { compute new position/size, depending on FDragStyle}
  case FDragStyle of

    dsSizeTopLeft:
      begin
        ARect.Left := XGridAdjust(Left + (XPos - FDragOffset.X)) - 2;
        ARect.Top := YGridAdjust(Top + (YPos - FDragOffset.Y)) - 2;
        ARect.Right := Width - (ARect.Left - Left);
        ARect.Bottom := Height - (ARect.Top - Top);
      end;

    dsSizeTopRight:
      begin
        ARect.Left := Left;
        ARect.Top := YGridAdjust(Top + (YPos - FDragOffset.Y)) - 2;
        ARect.Right := XGridAdjust(Width + (XPos - FDragOffset.X)) - 3;
        ARect.Bottom := Height - (ARect.Top - Top);
      end;

    dsSizeBottomLeft:
      begin
        ARect.Left := XGridAdjust(Left + (XPos - FDragOffset.X)) - 2;
        ARect.Top := Top;
        ARect.Right := Width - (ARect.Left - Left);
        ARect.Bottom := YGridAdjust(Height + (YPos - FDragOffset.Y)) - 3;
      end;

    dsSizeBottomRight:
      begin
        ARect.Left := Left;
        ARect.Top := Top;
        ARect.Right := XGridAdjust(Width + (XPos - FDragOffset.X)) - 3;
        ARect.Bottom := YGridAdjust(Height + (YPos - FDragOffset.Y)) - 3;
      end;

    dsSizeTop:
      begin
        ARect.Left := Left;
        ARect.Top := YGridAdjust(Top + (YPos - FDragOffset.Y)) - 2;
        ARect.Right := Width;
        ARect.Bottom := Height - (ARect.Top - Top);
      end;

    dsSizeBottom:
      begin
        ARect.Left := Left;
        ARect.Top := Top;
        ARect.Right := Width;
        ARect.Bottom := YGridAdjust(Height + (YPos - FDragOffset.Y)) - 3;
      end;

    dsSizeLeft:
      begin
        ARect.Left := XGridAdjust(Left + (XPos - FDragOffset.X)) - 2;
        ARect.Top := Top;
        ARect.Right := Width - (ARect.Left - Left);
        ARect.Bottom := Height;
      end;

    dsSizeRight:
      begin
        ARect.Left := Left;
        ARect.Top := Top;
        ARect.Right := XGridAdjust(Width + (XPos - FDragOffset.X)) - 3;
        ARect.Bottom := Height;
      end;

  else
                                       { keep size, move to new position }
    ARect.Left := XGridAdjust(Left + (XPos - FDragOffset.X)) - 2;
    ARect.Top := YGridAdjust(Top + (YPos - FDragOffset.Y)) - 2;
    ARect.Right := Width;
    ARect.Bottom := Height;

  end;
                                       { impose a minimum size for sanity }
  if ARect.Right < 5 then
    ARect.Right := 5;
  if ARect.Bottom < 5 then
    ARect.Bottom := 5;

  Result := ARect;

end;

procedure TStretchHandle.Rubberband(XPos, YPos: integer; ShowBox: boolean);
var
  NewRect: TRect;
  PtA, PtB: TPoint;
  ScreenDC: HDC;
begin
                                       { outline is drawn over all windows }
  ScreenDC := GetDC(0);
                                       { erase previous rectangle, if any, & adjust for handle's position }
  if (FDragRect.Left <> 0) or (FDragRect.Top <> 0) or (FDragRect.Right <> 0) or (FDragRect.Bottom <> 0) then
    begin
      PtA := Parent.ClientToScreen(Point(FDragRect.Left + 2, FDragRect.Top + 2));
      PtB := Parent.ClientToScreen(Point(FDragRect.Left + FDragRect.Right - 3, FDragRect.Top + FDragRect.Bottom - 3));
      DrawFocusRect(ScreenDC, Rect(PtA.X, PtA.Y, PtB.X, PtB.Y));
      FDragRect := Rect(0, 0, 0, 0);
    end;
                                       { draw new rectangle unless this is a final erase }
  if ShowBox then
    begin
      NewRect := GetModifiedRect(XPos, YPos);
      PtA := Parent.ClientToScreen(Point(NewRect.Left + 2, NewRect.Top + 2));
      PtB := Parent.ClientToScreen(Point(NewRect.Left + NewRect.Right - 3, NewRect.Top + NewRect.Bottom - 3));
      DrawFocusRect(ScreenDC, Rect(PtA.X, PtA.Y, PtB.X, PtB.Y));
      FDragRect := NewRect;
    end
  else
    begin
      Parent.Repaint;
      Repaint;
    end;


  ReleaseDC(0, ScreenDC);

end;

procedure TStretchHandle.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
var
  WasVisible: boolean;
  i: integer;
  AControl: TControl;
begin
                                       { hide & preserve fixed size in design mode }
  WasVisible := Visible;
  if csDesigning in ComponentState then
    begin
      Visible := False;
      inherited SetBounds(ALeft, ATop, 24, 24);
    end
  else                                 { move child also, if any (but only if not locked) }
    if not FLocked then
      begin
        for i := 0 to FChildList.Count - 1 do
          begin
            AControl := FChildList[i];
            AControl.SetBounds(AControl.Left - Left + ALeft,
                               AControl.Top - Top + ATop,
                               AControl.Width - Width + AWidth,
                               AControl.Height - Height + AHeight);
          end;
        inherited SetBounds(ALeft, ATop, AWidth, AHeight);
      end;
                                       { restore visibility }
  if Visible = False then
    Visible := WasVisible;

end;

procedure TStretchHandle.Paint;
var
   AControl: TControl;
   ARect, BoxRect: TRect;
   i: integer;
begin

  inherited Paint;
                                        { do it differently at design time... }
  if csDesigning in ComponentState then
    begin
      Canvas.Brush.Color := FPrimaryColor;
      BoxRect := Rect(0, 0, 5, 5);
      Canvas.FillRect(BoxRect);
      BoxRect := Rect(19, 0, 24, 5);
      Canvas.FillRect(BoxRect);
      BoxRect := Rect(19, 19, 24, 24);
      Canvas.FillRect(BoxRect);
      BoxRect := Rect(0, 19, 5, 24);
      Canvas.FillRect(BoxRect);
    end
  else
    begin
                                       { set color to primary if only one child, else secondary }
      if FChildList.Count = 1 then
        Canvas.Brush.Color := FPrimaryColor
      else
        Canvas.Brush.Color := FSecondaryColor;
                                       { draw resize handles for each child }
      for i := 0 to FChildList.Count - 1 do
        begin

          AControl := TControl(FChildList.Items[i]);
          ARect := Rect(AControl.Left - Left - 2,
                        AControl.Top - Top - 2,
                        AControl.Left - Left + AControl.Width + 2,
                        AControl.Top - Top + AControl.Height + 2);

          with Canvas do
            begin
                                       { draw corner boxes (assuming Canvas is minimum 5x5) }
              BoxRect := Rect(ARect.Left, ARect.Top, ARect.Left + 5, ARect.Top + 5);
              FillRect(BoxRect);
              BoxRect := Rect(ARect.Right - 5, ARect.Top, ARect.Right, ARect.Top + 5);
              FillRect(BoxRect);
              BoxRect := Rect(ARect.Right - 5, ARect.Bottom - 5, ARect.Right, ARect.Bottom);
              FillRect(BoxRect);
              BoxRect := Rect(ARect.Left, ARect.Bottom - 5, ARect.Left + 5, ARect.Bottom);
              FillRect(BoxRect);
                                       { only for single Children, draw center boxes }
              if FChildList.Count = 1 then
                begin
                  BoxRect := Rect(ARect.Left + trunc((ARect.Right - ARect.Left) / 2) - 2,
                                  ARect.Top,
                                  ARect.Left + trunc((ARect.Right - ARect.Left) / 2) + 3,
                                  ARect.Top + 5);
                  FillRect(BoxRect);
                  BoxRect := Rect(ARect.Left + trunc((ARect.Right - ARect.Left) / 2) - 2,
                                  ARect.Bottom - 5,
                                  ARect.Left + trunc((ARect.Right - ARect.Left) / 2) + 3,
                                  ARect.Bottom);
                  FillRect(BoxRect);
                  BoxRect := Rect(ARect.Left,
                                  ARect.Top + trunc((ARect.Bottom - ARect.Top) / 2) - 2,
                                  ARect.Left + 5,
                                  ARect.Top + trunc((ARect.Bottom - ARect.Top) / 2) + 3);
                  FillRect(BoxRect);
                  BoxRect := Rect(ARect.Right - 5,
                                  ARect.Top + trunc((ARect.Bottom - ARect.Top) / 2) - 2,
                                  ARect.Right,
                                  ARect.Top + trunc((ARect.Bottom - ARect.Top) / 2) + 3);
                  FillRect(BoxRect);
                end;

            end;

        end;

    end;

end;

procedure TStretchHandle.SetPrimaryColor(Color: TColor);
begin
                                       { set single select color, repaint immediately }
  FPrimaryColor := Color;
  Repaint;

end;

procedure TStretchHandle.SetSecondaryColor(Color: TColor);
begin
                                       { set multiple select color, repaint immediately }
  FSecondaryColor := Color;
  Repaint;

end;

procedure TStretchHandle.SetColors(Color1, Color2: TColor);
begin
                                       { set single/multiple select colors, repaint }
  FPrimaryColor := Color1;
  FSecondaryColor := Color2;
  Repaint;

end;

procedure TStretchHandle.SetGridState(Value: boolean);
begin
                                       { a value of 1 effectively disables a grid axis }
  if Value then
    begin
      FGridX := 8;
      FGridY := 8;
    end
  else
    begin
      FGridX := 1;
      FGridY := 1;
    end;

end;

function TStretchHandle.GetGridState: boolean;
begin

  if (FGridX > 1) or (FGridY > 1) then
    Result := True
  else
    Result := False;

end;

function TStretchHandle.GetChildCount: integer;
begin
  Result := FChildList.Count;
end;

function TStretchHandle.GetChildControl(idx: integer): TControl;
begin

  if (FChildList.Count > 0) and (idx >= 0) then
    Result := FChildList[idx]
  else
    Result := nil;

end;

function TStretchHandle.IsAttached: boolean;
begin

  if FChildList.Count > 0 then
    Result := True
  else
    Result := False;

end;

function TStretchHandle.PointOverChild(P: TPoint): boolean;
var
  i: integer;
  ARect: TRect;
  AControl: TControl;
begin
                                       { determine whether X, Y is over any child (for dragging) }
  Result := False;
  for i := 0 to FChildList.Count - 1 do
    begin
      AControl := TControl(FChildList[i]);
      ARect := Rect(AControl.Left - 2,
                    AControl.Top - 2,
                    AControl.Left + AControl.Width + 2,
                    AControl.Top + AControl.Height + 2);
                                       { P is relative to the Parent }
      if PtInRect(ARect, P) then
        begin
          Result := True;
          break;
        end;
    end;

end;

function TStretchHandle.XGridAdjust(X: integer): integer;
begin
  Result := (X DIV FGridX) * FGridX;
end;

function TStretchHandle.YGridAdjust(Y: integer): integer;
begin
  Result := (Y DIV FGridY) * FGridY;
end;

function MinInt(a, b: integer): integer;
begin
  if a < b then
    Result := a
  else
    Result := b;
end;

function MaxInt(a, b: integer): integer;
begin
  if a > b then
    Result := a
  else
    Result := b;
end;

end.




Вот я в этом коде добавил две строчки в процедуру procedure TStretchHandle.Rubberband

В этих строчках я напрямую обращаюсь к компонентам на своей форме.
Код: pascal
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
  if ShowBox then
    begin
      NewRect := GetModifiedRect(XPos, YPos);
      PtA := Parent.ClientToScreen(Point(NewRect.Left + 2, NewRect.Top + 2));
      PtB := Parent.ClientToScreen(Point(NewRect.Left + NewRect.Right - 3, NewRect.Top + NewRect.Bottom - 3));
      DrawFocusRect(ScreenDC, Rect(PtA.X, PtA.Y, PtB.X, PtB.Y));
      FDragRect := NewRect;

      fmTemplateOfInventory.SpinEditWidth.Text:= inttostr(PtB.X-PtA.X);
      fmTemplateOfInventory.SpinEditHeight.Text:= inttostr(PtB.Y-PtA.Y);
    end



Задачу это мою решает, НО!
К сожалению, это конечного же говно код.

Подскажите мне пожалуйста добрые люди , как передать в эту функцию ссылки на мои spinedit'ы? дабы избежать такого плохого кода.

Т.е. как надо дописать данную компоненту? Что почитать ?

Благодарю.
...
Рейтинг: 0 / 0
Как отловить событие?
    #39762033
Dimitry Sibiryakov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
FIL23Т.е. как надо дописать данную компоненту? Что почитать ?

Повторяю ещё раз медленно: компоненту выкинуть, читать MSDN на предмет CaptureMouse(),
DrawFocusRect().
Posted via ActualForum NNTP Server 1.5
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Delphi [игнор отключен] [закрыт для гостей] / Как отловить событие?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]