delphi - How to change hint text while hint is shown in TBalloonHint? -


before used thint, , working code:

procedure tmainform.formcreate(sender: tobject); begin   application.onshowhint := appshowhint; end;  procedure tmainform.appshowhint(var hintstr: string; var canshow: boolean; var hintinfo: controls.thintinfo); begin   hintinfo.reshowtimeout := 1; end; 

now use tballoonhint , want change hint text when hint shown. above procedure not triggered.

i changing hint text each second, when user enters control, hint shown , want update hint text each second, when user not moving mouse.

how achieve tballoonhint?

tballoonhint not support functionality. following code (delphi xe3) adds it.

cons:

  • cpu load - every call tballoonhint.showhint creates new tcustomhintwindow
  • flickering when redrawing

type   tmyhintwindow = class(thintwindow)   public     function calchintrect(maxwidth: integer; const ahint: string;       adata: tcustomdata): trect; override;     function shouldhidehint: boolean; override;   end;  var balloonhint: tballoonhint;     _hintpos: tpoint;  function tmyhintwindow.calchintrect(maxwidth: integer; const ahint: string;   adata: tcustomdata): trect; begin   result := rect(0,0,0,0); end;  function tmyhintwindow.shouldhidehint: boolean; begin   result := true;   balloonhint.free; balloonhint := nil; end;  procedure tmainform.formcreate(sender: tobject); begin   hintwindowclass := tmyhintwindow;   application.onshowhint := appshowhint; end;  procedure tmainform.appshowhint(var hintstr: string; var canshow: boolean; var hintinfo: thintinfo); begin   hintinfo.reshowtimeout := 1;    if not assigned(balloonhint)   begin     balloonhint := tballoonhint.create(self);     _hintpos := point(maxint, maxint);   end;    if (_hintpos <> hintinfo.hintpos) or (balloonhint.description <> hintstr)   begin     _hintpos := hintinfo.hintpos;     balloonhint.description := hintstr;     balloonhint.showhint(_hintpos);   end; end; 

another ways:

  • rewrite tmyhintwindow.calchintrect , .paint taking code tballoonhint

  • rewrite tmyhintwindow using tooltip controls

add: use tooltip control. try set hintinfo.reshowtimeout := 25.

uses windows, vcl.controls, system.classes, winapi.commctrl, winapi.messages;  type   ttooltiphintwindow = class(thintwindow)   private     tooltipwnd: hwnd;     tooltipinfo: ttoolinfo;     tooltiptext: string;     tooltippos: tpoint;   public     constructor create(aowner: tcomponent); override;     destructor destroy; override;     procedure activatehint(rect: trect; const ahint: string); override;     function calchintrect(maxwidth: integer; const ahint: string; adata: tcustomdata): trect; override;     function shouldhidehint: boolean; override;   end;  implementation  procedure ttooltiphintwindow.activatehint(rect: trect; const ahint: string); begin   inherited;   if (tooltiptext <> ahint)   begin // update text     tooltiptext := ahint;     tooltipinfo.lpsztext := pchar(tooltiptext);     sendmessage(tooltipwnd, ttm_updatetiptext, 0, lparam(@tooltipinfo));   end;   if (tooltippos <> rect.topleft)   begin // update position     tooltippos := rect.topleft;     sendmessage(tooltipwnd, ttm_trackposition, 0, pointtolparam(tooltippos));   end;   // show   sendmessage(tooltipwnd, ttm_trackactivate, wparam(true), lparam(@tooltipinfo)); end;  function ttooltiphintwindow.calchintrect(maxwidth: integer; const ahint: string;   adata: tcustomdata): trect; begin   result := rect(0,0,0,0); end;  constructor ttooltiphintwindow.create(aowner: tcomponent); var font, boldfont: hfont;     logfont: tlogfont; begin   inherited;   // create tooltip   tooltipwnd := createwindowex(ws_ex_topmost or ws_ex_transparent,     tooltips_class, nil,     tts_noprefix or tts_alwaystip or tts_balloon,     0, 0, 0, 0, 0, 0, hinstance, nil);   // set bold font   font := sendmessage(tooltipwnd, wm_getfont, 0, 0);   if (font <> 0)   begin     if getobject(font, sizeof(logfont), @logfont) > 0     begin       logfont.lfweight := fw_bold;       boldfont := createfontindirect(logfont);       sendmessage(tooltipwnd, wm_setfont, boldfont, 0);     end;   end;   // set maximum width   sendmessage(tooltipwnd, ttm_setmaxtipwidth, 0 , 400);   // init   fillchar(tooltipinfo, sizeof(tooltipinfo), 0);   tooltipinfo.cbsize := sizeof(tooltipinfo);   tooltipinfo.uflags := ttf_track or ttf_transparent;   tooltipinfo.uid := 1;   sendmessage(tooltipwnd, ttm_addtool, 0, lparam(@tooltipinfo)); end;  destructor ttooltiphintwindow.destroy; begin   destroywindow(tooltipwnd);   inherited; end;  function ttooltiphintwindow.shouldhidehint: boolean; begin   inherited;   // hide   sendmessage(tooltipwnd, ttm_trackactivate, wparam(false), lparam(@tooltipinfo));   tooltippos := point(maxint, maxint);   tooltiptext := ''; end; 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -