IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Contribuez Delphi Discussion :

Unité pour changer infobulle des controls


Sujet :

Contribuez Delphi

  1. #1
    Membre éprouvé
    Avatar de Montor
    Homme Profil pro
    Autre
    Inscrit en
    Avril 2008
    Messages
    879
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Avril 2008
    Messages : 879
    Points : 963
    Points
    963
    Par défaut Unité pour changer infobulle des controls
    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

  2. #2
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 447
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 447
    Points : 24 849
    Points
    24 849
    Par défaut
    Merci Montor,

    C'est très interessant, j'ai fait quelque chose d'approchant, mais j'ai abandonné HintWindowClass car je devais afficher un Hint même si un controle Disabled, j'ai donc bidouillé un thread pour afficher le Hint du composant sous la souris, même si Disabled, cela affichait même sur les MenuItem et ComboItem (ce que j'ai désactivé, trop lourd)
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  3. #3
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Hé pas mal...

    J'ai testé sur un TEdit et un TStringGrid, cela fonctionne trés bien.

    En plus on peu jouer avec la couleur de dégradée.

    Faudrait quer tu donne acces au Font.Size et Font.name du text se serait un plus.


    Bravo.

    PS (j'oubliais) : testé sur Delphi 7

  4. #4
    Membre émérite
    Homme Profil pro
    Directeur technique
    Inscrit en
    Mai 2008
    Messages
    2 401
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Directeur technique
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2008
    Messages : 2 401
    Points : 2 304
    Points
    2 304
    Par défaut
    Beau résultat !
    Bon courage ou Bonne Chance (selon le contexte)
    Mon blog sur WordPress

Discussions similaires

  1. [WPF] Changer la couleur pour des controles obligatoires
    Par BenoitM dans le forum Windows Presentation Foundation
    Réponses: 20
    Dernier message: 21/09/2012, 08h41
  2. composant ou une unité pour recadrer/retailler des *.bmp
    Par Henri-gp dans le forum Composants VCL
    Réponses: 2
    Dernier message: 06/04/2009, 16h49
  3. Script pour changer valeur des paramètres régionaux
    Par Foxtrot dans le forum Windows XP
    Réponses: 0
    Dernier message: 14/12/2007, 19h38
  4. [MFC] Pb pour changer la police de controles
    Par mick74 dans le forum MFC
    Réponses: 4
    Dernier message: 14/05/2004, 11h02
  5. Une unité pour gérer des très grands nombres
    Par M.Dlb dans le forum Langage
    Réponses: 2
    Dernier message: 09/09/2003, 12h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo