Unité pour changer infobulle des controls...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
unit UPersoHint;
interface
uses
  Windows, Messages, SysUtils,Classes, Graphics, Controls, Forms;
type
  TPersoHintWindow = class(THintWindow)
  protected
    procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
    procedure Paint; override;
    procedure NCPaint(DC: HDC); override;
  public
    constructor Create(AOwner: TComponent); override;
    procedure ActivateHint(Rect: TRect; const AHint: string);override;
  end;
var
  StartColor:TColor;
  EndColor:TColor;
implementation
type
    COLOR16 = Word;
    TTriVertex = packed record
      x: Longint;
      y: Longint;
      Red: COLOR16;
      Green: COLOR16;
      Blue: COLOR16;
      Alpha: COLOR16;
    end;
function GradientFill(DC: HDC; Vertex: PTriVertex; NumVertex: ULONG; Mesh: Pointer; NumMesh, Mode: ULONG): BOOL; stdcall;external 'msimg32.dll';
{not mine}
procedure Antialiasing(Bmp: TBitmap; Percent: Integer);
type
  TRGBTripleArray = array[0..32767] of TRGBTriple;
  PRGBTripleArray = ^TRGBTripleArray;
var
  SL, SL2: PRGBTripleArray;
  l, m, p: Integer;
  R, G, B: TColor; v: Single;
  R1, R2, G1, G2, B1, B2: Byte;
begin
  Bmp.PixelFormat :=pf24bit;
  with Bmp.Canvas do
  begin   v:=  50 / (Percent + 50);
    Brush.Style  := bsClear;
    Pixels[1, 1] := Pixels[1, 1];
    for l := 0 to Bmp.Height - 1 do
    begin
      SL := Bmp.ScanLine[l];
      for p := 1 to Bmp.Width - 1 do
      begin
        R1 := SL[p].rgbtRed;
        G1 := SL[p].rgbtGreen;
        B1 := SL[p].rgbtBlue;
 
        // Left
        if (p < 1) then m := Bmp.Width
        else
          m := p - 1;
        R2 := SL[m].rgbtRed;
        G2 := SL[m].rgbtGreen;
        B2 := SL[m].rgbtBlue;
        if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
        begin
          R := Round(R1 + (R2 - R1) * v);
          G := Round(G1 + (G2 - G1) *v);
          B := Round(B1 + (B2 - B1) * v);
          SL[m].rgbtRed := R;
          SL[m].rgbtGreen := G;
          SL[m].rgbtBlue := B;
        end;
 
        //Right
        if (p > Bmp.Width - 2) then m := 0
        else
          m := p + 1;
        R2 := SL[m].rgbtRed;
        G2 := SL[m].rgbtGreen;
        B2 := SL[m].rgbtBlue;
        if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
        begin
          R := Round(R1 + (R2 - R1) * v);
          G := Round(G1 + (G2 - G1) * v);
          B := Round(B1 + (B2 - B1) * v);
          SL[m].rgbtRed := R;
          SL[m].rgbtGreen := G;
          SL[m].rgbtBlue := B;
        end;
 
        if (l < 1) then m := Bmp.Height - 1
        else
          m := l - 1;
        //Over
        SL2 := Bmp.ScanLine[m];
        R2  := SL2[p].rgbtRed;
        G2  := SL2[p].rgbtGreen;
        B2  := SL2[p].rgbtBlue;
        if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
        begin
          R := Round(R1 + (R2 - R1) *v);
          G := Round(G1 + (G2 - G1) * v);
          B := Round(B1 + (B2 - B1) * v);
          SL2[p].rgbtRed := R;
          SL2[p].rgbtGreen := G;
          SL2[p].rgbtBlue := B;
        end;
 
        if (l > Bmp.Height - 2) then m := 0
        else
          m := l + 1;
        //Under
        SL2 := Bmp.ScanLine[m];
        R2  := SL2[p].rgbtRed;
        G2  := SL2[p].rgbtGreen;
        B2  := SL2[p].rgbtBlue;
        if (R1 <> R2) or (G1 <> G2) or (B1 <> B2) then
        begin
          R := Round(R1 + (R2 - R1) * v);
          G := Round(G1 + (G2 - G1) * v);
          B := Round(B1 + (B2 - B1) * v);
          SL2[p].rgbtRed := R;
          SL2[p].rgbtGreen := G;
          SL2[p].rgbtBlue := B;
        end;
      end;
    end;
  end;
end;
constructor TPersoHintWindow.Create(AOwner: TComponent);
begin
   inherited Create(AOwner);
   StartColor:=clWhite;
   EndColor:=$00EFDACA;
end;
 
procedure TPersoHintWindow.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
begin
  Msg.Result :=1;
end;
 
procedure TPersoHintWindow.Paint;
 procedure Cplt(Var AVertex:TTriVertex;AColor:TColor);
  begin
     AVertex.Red:=GetRValue(AColor) shl 8;
     AVertex.Green:=GetGValue(AColor)shl 8;
     AVertex.Blue:=GetBValue(AColor)shl 8;
     AVertex.Alpha:=0;
  end;
var
 Sz:TSize;
 S:string;
 vertex:array[0..1] of TTriVertex;
 gTri    :TGradientRect;
 bmp:TBitmap;
begin
 S:= Caption;
 
 bmp:=TBitmap.Create;
 with bmp do
 try
    Sz:= Canvas.TextExtent(S);
    Width  :=Sz.cx+8;
    Height :=Sz.cy+6;
 
    Cplt(vertex[0],StartColor);
    vertex[0].X:=0;
    vertex[0].Y:=0;
    Cplt(vertex[1],EndColor);
    vertex[1].X:=Width ;
    vertex[1].Y:=Height;
    gTri.UpperLeft := 0;
    gTri.LowerRight := 1;
    GradientFill(Canvas.handle,@vertex , 2, @gTri, 1, GRADIENT_FILL_RECT_V);
 
 
    Canvas.Brush.Style:=bsClear;
 
    Canvas.TextOut(4,2,S);
    Antialiasing(bmp,5);
 
    Self.Width  :=Width;
    Self.Height :=Height;
    Self.Canvas.Draw(0,0,bmp);
 
 finally
   bmp.Free();
 end;
 
end;
 
procedure TPersoHintWindow.ActivateHint(Rect: TRect; const AHint: string);
begin
   if not IsWindowvisible(Self.Handle) then
  inherited;
 
end;
 
procedure TPersoHintWindow.NCPaint(DC: HDC);
begin
  with TCanvas.Create do
   begin
       Handle :=DC;
       Brush.Color :=clblack;
       fillrect(cliprect);
 
   free;
   end;
 
 
end;
 
initialization
 if not (csDesigning in Application.ComponentState) then
 HintWindowClass := TPersoHintWindow;
end.
utilisation
ajouter le nom de l'unité dans le uses