HintWindowClass

Résolu
Caribensila Messages postés 2527 Date d'inscription jeudi 15 janvier 2004 Statut Membre Dernière intervention 16 octobre 2019 - 27 nov. 2007 à 18:48
Caribensila Messages postés 2527 Date d'inscription jeudi 15 janvier 2004 Statut Membre Dernière intervention 16 octobre 2019 - 27 nov. 2007 à 23:07
Salut à tous,


L'application que je développe a besoin de deux styles de bulle d'aide différents. Les bulles classiques de Windows, et des bulles perso (avec image).

Jusque là, ça va.

Mais je voudrais que le style des bulles change en fonction du Tag du compo survolé. C'est là que ça se gâte car cela fonctionne, mais avec un temps de retard. Ce qui fait que souvent le bon style n'est pas appliqué au bon Tag.


Voici comment je pensais m'y prendre (code simplifié) :



implementation


{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);

begin

Application.OnShowHint := DoShowHint;

end;


procedure TForm1.DoShowHint(var HintStr: String ; var CanShow: Boolean; var HintInfo: THintInfo);

begin

if HintInfo.HintControl.Tag = 0 then HintWindowClass := TClassicHint;

if HintInfo.HintControl.Tag = 1 then begin

  HintWindowClass := TPersonalHint;

  HintInfo.HintData := Image1.Picture.Bitmap;

end;


end;


END.




==========================================



Et voici mes classes de Hint :



type

TClassicHint = Class(THintWindow)

end;


TPersonalHint = Class(THintWindow)

private

  fBmp : TBitmap;

protected

  procedure Paint; override;

public

  Constructor Create(AOwner : TComponent); override;

  Destructor Destroy; override;

  Function CalcHintRect(MaxWidth: Integer; Const AHint: String; AData: Pointer): TRect; override;

end;


implementation


uses Unit1;


Constructor TPersonalHint.Create(AOwner : TComponent);

begin

Inherited Create(AOwner);

fBmp := TBitmap.Create;

try

  fBmp.Height := 0;

  fBmp.Width := 0;

  fBmp.Canvas.Font := Canvas.Font;

  fBmp.Transparent := true;

except FreeAndNil(fBmp); end;

end;


destructor TPersonalHint.Destroy;

begin

FreeAndNil(fBmp);

inherited;

end;


Function TPersonalHint.CalcHintRect(MaxWidth: Integer; Const AHint: String; AData: Pointer): TRect;

var 
MonBmp : TBitmap;

Begin

Result := Inherited CalcHintRect(MaxWidth,AHint,AData);

if Assigned(AData) then begin

  MonBmp := TBitmap.Create;

  try

    MonBmp.Assign(AData);

    fBmp.Height := MonBmp.Height;

    fBmp.Width := MonBmp.Width + Result.Right;

    fBmp.Canvas.Draw(0,0,MonBmp);

     fBmp.Canvas.TextOut(MonBmp.Width+2,0,AHint);

    Result.Right := fBmp.Width;

    Result.Bottom := fBmp.Height;

  finally MonBmp.Free; end; end

else begin

  fBmp.Height := 0;

end;

end;


procedure TPersonalHint.Paint;

begin

if fBmp.Height <> 0 then begin

  Caption := '';

  Canvas.Draw(0, 0, fBmp);

end;

inherited;


end;


END.




=====================================================

( dsl pour la longueur )

Je ne comprends pas pourquoi ça ne fonctionne pas correctement. J'ai dû m'y prendre comme un manche. Si quelqu'un pouvait me mettre sur la voie...


Merci

6 réponses

Cirec Messages postés 3833 Date d'inscription vendredi 23 juillet 2004 Statut Modérateur Dernière intervention 18 septembre 2022 50
27 nov. 2007 à 22:21
La raison est très simple :

Quand tu "interceptes" DoShowHint
La variable HintInfo (qui contient un membre nommé HintWindowClass)
a été initialisé juste avant avec la valeur de HintWindowClass
(Je sais c'est pas très claire)
Mais c'est la valeur de HintInfo.HintWindowClass qui est pise en compte.
Donc quand tu fais : HintWindowClass := TPersonalHint;
ce sera effectivement pour le prochain appel !!!!

Pour modifier le HintWindowClass courant il faut passer par :
HintInfo.HintWindowClass

Voilà j'espère avoir éclairé ta lanterne

 
@+
Cirec

<hr siz="" />
3
Utilisateur anonyme
27 nov. 2007 à 20:35
Salut jeune homme,

Bon je viens de tester ton souce : le hint s'affiche bien. Et question de temps je ne vois pas de différence avec un hint classique.

 Par contre ton TImage n'a aucun effet (et j'ai bien utilisé un BitMap). J'ai juste testé que ton hint perso était bien appelé par contre j'ai pas cherché à percé plus sur le pourquoi du comment : je te laisse le plaisir

@++
0
Utilisateur anonyme
27 nov. 2007 à 20:52
Bon j'ai rien dis : j'ai bien l'image par contre c'est long. Après un test le problème vient de TPersonalHint.CalcHintRect(MaxWidth: Integer; Const AHint: String; AData: Pointer): TRect;

Function TPersonalHint.CalcHintRect(MaxWidth: Integer; Const AHint: String; AData: Pointer): TRect;
var  MonBmp : TBitmap;
Begin
Result := Inherited CalcHintRect(MaxWidth,AHint,AData);
SHOWMESSAGE('TEST');
if Assigned(AData) then begin
  MonBmp := TBitmap.Create;
  try
    MonBmp.Assign(AData);
    fBmp.Height := MonBmp.Height;
    fBmp.Width := MonBmp.Width + Result.Right;
    fBmp.Canvas.Draw(0,0,MonBmp);
     fBmp.Canvas.TextOut(MonBmp.Width+2,0,AHint);
    Result.Right := fBmp.Width;
    Result.Bottom := fBmp.Height;
  finally MonBmp.Free; end; end
else begin
  fBmp.Height := 0;
end;
end;

Fait le test et tu vera le temps que mettra le showmessage pour apparaitre : plusieurs secondes.

La solution :

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnShowHint := DoShowHint;
Application.HintPause := 0; //L'affichage sera instantané
end;

Et hop c'est instantané
0
Caribensila Messages postés 2527 Date d'inscription jeudi 15 janvier 2004 Statut Membre Dernière intervention 16 octobre 2019 18
27 nov. 2007 à 20:59
Salut pépé,

Je me suis mal expliqué.
Quand je parle de temps de retard, je veux dire que, par exemple, quand on survole un compo qui devrait afficher un hint perso, il affiche un hint classique... Par contre, quand on survole juste après un autre compo qui devrait afficher un hint perso, là il affiche bien un hint perso... Et après, si on survole un compo qui devrait afficher un hint classique, j'ai encore un hint perso, etc...
Teste un peu plus, tu comprendras...
C'est pas le Application.HintPause qui m'emm...

J'sens que je vais devenir fou avec ce bidule ! ! !






J'ai cherché partout. Même sur des sites chinois où j'ai failli y laisser ma peau!
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Caribensila Messages postés 2527 Date d'inscription jeudi 15 janvier 2004 Statut Membre Dernière intervention 16 octobre 2019 18
27 nov. 2007 à 22:05
Problème réglé chez moi aussi, du coup! 
Ca fonctionne à merveille!

Même si je ne comprends pas bien le pourquoi du comment. Mais je vais y réfléchir et je vous lâche le coude en attendant.

Merci à tous deux pour le temps que vous avez consacré à mon problème.
0
Caribensila Messages postés 2527 Date d'inscription jeudi 15 janvier 2004 Statut Membre Dernière intervention 16 octobre 2019 18
27 nov. 2007 à 23:07
Mais si, Cirec, c'est très clair!
Merci beaucoup.
0
Rejoignez-nous