Link to home
Start Free TrialLog in
Avatar of Edo082297
Edo082297

asked on

Refreshing appearance of a hint

Hello everybody,

   When the cursor is over a control, it displays a hint if ShowHint is true (and there is a hint!). Once the hint has disappeared (the hint timer has expired), it will not reappear until the mouse leaves the control and returns over it to prompt it once again. I have a listbox where I do some fancy hint manipulation according to the index that the mouse point is over. I would like to see the hint reappear every time the mouse stops moving for a moment. With this in mind, I would like a solution that does not involve tricks which I can come up with myself: I want to know what message I can send the listbox, or what I should override in my own custom TAlwaysDisplayHintEvenWhenHintHasAlreadyShown so that this will work.

Regards, and have a particularly good day.

Edo
Avatar of ZifNab
ZifNab

Hi Edo,

 I'm not sure if it's the same for your case, but if you want to change the appereance of the Hint, you've to make a descendant of THintWindow. I propose that you have a look at its properties etc. There are also a lot of free-source-codes on Torry's, DSP, etc.

 If you still need some more help after that, just ask and I'll help you when I'm back (if I can offcourse), perhaps somebody else can already help you before.

regards, Zif.
Avatar of Edo082297

ASKER

Hiya Brad,
  No, I'm happy with the physical appearance of the hint. It's just that the control occupies a large part of the form, and I want the hint to keep reappearing when the mouse hovers over an item in it, and not just once as when the mouse goes over the control and then remains within its constituent rect.

Edo
Then, you've to recall the hint again. Or make a descendant that displays longer then the normal hint.

here is a code to let the hint appear and remove it manually :
 
Is it possible to call the  Hint method directly?
I've a case where I want to click on a Button, and the Hint for
another component (eg, an edit box) will appear for 1 second or
so, and then it will disappear after the button is released. I
saw something like "ActivateHint" but it seemed that I
couldn't make a direct call.
A:
 function RevealHint (Control: TControl): THintWindow;
{----------------------------------------------------------------}
{ Pops up Hint window for the specified Control, and returns a   }
{ reference to the hint object so it may subsequently be removed }
{ with RemoveHint (see below).                                   }
{----------------------------------------------------------------}
 var
   ShortHint: string;
   AShortHint: array[0..255] of Char;
   HintPos: TPoint;
   HintBox: TRect;
 begin
   { Create the window: }
   Result := THintWindow.Create(Control);

   { Get first half of hint up to '|': }
   ShortHint := GetShortHint(Control.Hint);

   { Calculate Hint Window position & size: }
   HintPos := Control.ClientOrigin;
   Inc(HintPos.Y, Control.Height + 6);    <<<< See note below
   HintBox := Bounds(0, 0, Screen.Width, 0);
   DrawText(Result.Canvas.Handle,
       StrPCopy(AShortHint, ShortHint), -1, HintBox,
       DT_CALCRECT or DT_LEFT or DT_WORDBREAK or DT_NOPREFIX);
   OffsetRect(HintBox, HintPos.X, HintPos.Y);
   Inc(HintBox.Right, 6);
   Inc(HintBox.Bottom, 2);

   { Now show the window: }
   Result.ActivateHint(HintBox, ShortHint);
 end; {RevealHint}

 procedure RemoveHint (var Hint: THintWindow);
{----------------------------------------------------------------}
{ Releases the window handle of a Hint previously popped up with }
{ RevealHint.                                                    }
{----------------------------------------------------------------}
 begin
   Hint.ReleaseHandle;
   Hint.Free;
   Hint := nil;
 end; {RemoveHint}

The line marked <<<< above is the one that positions the hint
window below the control.  This could obviously be altered if
you want a different position for some reason.

Regards, Zif.
ASKER CERTIFIED SOLUTION
Avatar of ZifNab
ZifNab

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Zif
   Sorry it took so long for me to respond, I have been quite busy with work, we're just about to release a new version. You will be happy to know that a version of your code above made it into the next release. The only suggestion I have is to set the hint color before calling it - hint.color := application.hintcolor. (Off the top of my head). That way the hint appears homogenous with the rest of the application. (That being said, I don't know why it is not the same color as hints appearing in Windows... where is it getting that weird shade of yellow from, or is that just a function of my peculiar settings?)
  Thankyou for your help.

Regards,
Edo



Glad I could help. See you!