Autor Beitrag
uruz
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 21.01.04 15:22 
Aloha he, ich hab wieder mal was ganz ganz tolles gebastelt *gg*

Ich habe eine Komponente von TPanel abgeleitet, die im MouseEnter "aufpoppt" und einen formatierten Text in einem RichEdit darstellen kann. Im "Normalzustand", also wenn ned gerade die Maus darueber ist, schrumpft das Panel bis auf einen bestimmten Headerbereich zusammen. Dazu habe ich natuerlich - wie nicht anders zu erwarten - die messages CM_MOUSEENTER und CM_MOUSELEAVE genutzt.

folgende Probleme habe ich nun allerdings:
- wenn ich meiner Komponente ein Popupmenu zu weise und dieses aufpoppt, ich den mauszeiger nun irgendwo anders (jedenfalls weg von meiner Komponente) hinlenke und dorthin klicke, dann schliesst sich mein Popupmenu, aber meine Komponente bleibt geoeffnet. Nun ja... dem will ich abhilfe schaffen...

- wenn ein anderes Fenster (einer beliebigen Anwendung) meine Komponente teilweise bedeckt, wird das "Aufpoppen" meiner Komponente nach wie vor ausgefuehrt, auch wenn meine Anwendung nicht den Fokus hat. Wenn ich nun den Mauszeiger von meiner "gestretchten" Komponente ueber die teilweise verdeckte Seite hinweg aus dem Umriss meiner Komponente bewege, bleibt die Komponente nach wie vor gestretched. Hierbei moechte ich zum einen, dass meine Komponente am besten gar ned aufpoppt, wenn das Fenster, in dem sie sich befindet, nicht den fokus hat... und wenn das ned moeglich sein sollte, dass sich die Komponente wieder zusammenzieht, sobald der Mauszeiger sie wirklich verlaesst... egal ob auf ein anderes Formular oder wo immer auch hin !

vielen dank fuer eure Hilfe

uruz

ausblenden volle Höhe Delphi-Quelltext
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:
{******************************************************************************}
procedure TrdInfoPanel.CMMouseEnter(var AMsg: TMessage);
var
  x, y   : integer;
  temp   : TPoint;
begin
  if not Enabled then exit;

  x := Self.ScreenToClient(Mouse.CursorPos).x;
  y := Self.ScreenToClient(Mouse.CursorPos).y;

  if not FIsOver then begin

    FIsOver := true;

    if FAutoStretch then begin
      Height := StretchHeight;
      BringToFront;
    end;

    if Assigned(FOnMouseOver) then
      FOnMouseOver(Self, x, y);
  end;
end;


{******************************************************************************}
procedure TrdInfoPanel.CMMouseLeave(var AMsg: TMessage);
var
  x, y : integer;
begin
  if not Enabled then exit;

  x := Self.ScreenToClient(Mouse.CursorPos).x;
  y := Self.ScreenToClient(Mouse.CursorPos).y;

  if   IntInRange(x, 0, Self.Width - 1)
   and IntInRange(y, 0, Self.Height - 1) then begin

  end else begin
    if FIsOver then begin
      FIsOver := false;

      if FAutoStretch then begin
        Height := ShrinkHeight;
      end;

      if Assigned(FOnMouseOut) then
        FOnMouseOut(Self, x, y);
    end;
  end;
end;


Moderiert von user profile iconMotzi: Code- durch Delphi-Tags ersetzt
uruz
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 22.01.04 08:50 
Titel: ... zwei grosse schritte weiter ;o)
nu ja... bin dann gestern noch um einiges weitergekommen... quelltext siehe weiter unten...

allerdings stehe ich nun wieder vor einem anderen problem... irgendwie kriegt die komponente nicht immer mit, wenn der mauszeiger sie verlaesst... insbesondere... wenn ich den mauszeiger langsam (!) ueber den rand der komponente hinausziehe...

also... ich habe ein wenig im internet gestoebert und folgende funktionen gefunden

ausblenden volle Höhe Delphi-Quelltext
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:
{******************************************************************************}
function FindTopMostWinControlAtPos(
                                                 { The parent at the top of the}
                                                 { control tree                }
                                    Parent : TWinControl;
                                                 { The "hit" test point in     }
                                                 { screen coordinates          }
                                    Pt     : TPoint
                                  ): TWinControl;
var
  i : integer;
  c : TControl;
begin
  result := nil;

  if Parent.Visible then begin
    i := Parent.ControlCount -1;
                                                 { Check children first        }
    while (i >= 0) and (result = nil) do begin
      c := Parent.Controls[i];
                                                 { Recursively descend         }
      if c is TWinControl then
        result := FindTopMostWinControlAtPos(c as TWinControl, Pt);

      i := i -1;
    end;
                                                 { Check Parent control last   }
    if result = nil then begin
                                                 { Convert to local coords     }
      Pt := Parent.ScreenToClient(Pt);
      if   (Pt.X >= 0) and (Pt.X < Parent.Width)
       and (Pt.Y >= 0) and (Pt.Y < Parent.Height) then
                                                 { Found it!                   }
        result := Parent;
    end;
  end;
end;

{******************************************************************************}
function GetTopMostControlAtScreenCoords(
                                                 { Screen coords for "hit" test}
                                         Pt             : TPoint;
                                                 { Indicates, if disabled      }
                                                 { controls are included       }
                                         Allow_Disabled : boolean
                                        ): TControl;
var
  wc : TWinControl;
begin
  result := FindDragTarget(Pt, Allow_Disabled);

  if   (result <> nil)
   and (result is TWinControl)
   and Allow_Disabled then
  begin
                                                 { Check for disabled child    }
                                                 { windowed controls           }
    wc     := FindTopMostWinControlAtPos((result as TWinControl), Pt);
                                                 { Can't happen - honest guv!  }
    if wc = nil then
      abort;
                                                 { Convert to local coords     }
    Pt     := wc.ScreenToClient(Pt);
    result := wc.ControlAtPos(Pt, True);
    if result = nil then
    result := wc;
  end;
end;


habe daraufhin mal meine Events angepasst... bzw. noch das WM_MouseMove ergaenzt...

ausblenden volle Höhe Delphi-Quelltext
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:
{******************************************************************************}
procedure TrdInfoPanel.CMMouseEnter(var AMsg: TMessage);
var
  x, y  : integer;
  temp  : TPoint;
  ctrl  : TControl;
begin
  if not Enabled then exit;

  ctrl := GetTopMostControlAtScreenCoords(Mouse.CursorPos, true);
  if   (ctrl = TControl(Self))
   or  (ctrl = "untergeordnete Komponenten")
   and not FIsOver then begin

    x := Self.ScreenToClient(Mouse.CursorPos).x;
    y := Self.ScreenToClient(Mouse.CursorPos).y;

    FIsOver := true;

    if FAutoStretch then begin
      Height := StretchHeight;
      BringToFront;
    end;

    if Assigned(FOnMouseOver) then
      FOnMouseOver(Self, x, y);
  end;
end;

{******************************************************************************}
procedure TrdInfoPanel.CMMouseLeave(var AMsg: TMessage);
var
  x, y : integer;
  ctrl : TControl;
begin
  if not Enabled then exit;

  ctrl := GetTopMostControlAtScreenCoords(Mouse.CursorPos, true);
  if   (ctrl <> TControl(Self))
   and (ctrl <> "untergeordnete Komponenten")
   or  not FIsOver then begin

    x := Self.ScreenToClient(Mouse.CursorPos).x;
    y := Self.ScreenToClient(Mouse.CursorPos).y;

    FIsOver := false;

    if FAutoStretch then begin
      Height := ShrinkHeight;
    end;

    if Assigned(FOnMouseOut) then
      FOnMouseOut(Self, x, y);
  end;
end;

(******************************************************************************)
procedure TrdInfoPanel.WMMouseMove(var AMsg: TMessage);
var
  ctrl : TControl;
begin
  inherited;

  ctrl := GetTopMostControlAtScreenCoords(Mouse.CursorPos, true);
  if   (ctrl <> TControl(Self))
   and (ctrl <> "untergeordnete Komponenten") then begin
    CMMouseLeave(AMsg);
  end;
end;
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 22.01.04 10:11 
Hab sowas ähnliches auch mal gemacht.. ich hab das damals über die Messages WM_MOUSEHOVER und WM_MOUSELEAVE gemacht, die bekommt man allerdings nur über die API-Funktion TrackMouseEvent... schau dir die vielleicht mal hier an...

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
uruz
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 22.01.04 16:41 
auch dieser fehler ist nun behoben :)

allerdings... lag es an etwas anderem... ich habe auf diesem infopanel unter anderem eine TRichEdit- Komponente untergebracht mit Align = alClient... wenn ich nun am rechten Rand oder am unteren Rand des Panels das Panel verlassen habe, hat das Panel das verlassen nicht immer mitbekommen. Habe mich gefragt woran das liegt und habe die BevelWidth mal auf 2 erweitert... und siehe da... es klappt !!

keine Ahnung, warum und wieso... aber es erfuellt nun seinen Zweck !

uruz