• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 750
  • Last Modified:

Display hint with code, application doesnt have focus

working on a power bar, its a floating bar with buttons,
I need to display the buttons hints even when the application doesnt have focus, but when the mouse is over the control.. seems odd that mouse over fires but the hind is never displayed..

Please help!
0
krazy6284
Asked:
krazy6284
1 Solution
 
dwwangCommented:
What is the code you used to show the hint when mouse moves over?
0
 
MadshiCommented:
Hi,

I've the same problem. I even searched through the Delphi code and I finally found: It is not possible to do what you want without changing the Delphi sources (forms.pas/controls.pas) and recompiling them. It's quite annoying, isn't it!?

Regards, Madshi.
0
 
vladikaCommented:
I think the problem lies in the depth of VCL.

When hint timer expired Delphi calls HintTimerExpired procedure
which call ActivateHint procedure.
ActivateHint check: Is your program foreground or not?
If yes Delphi show hint window.
So, you must modify ActivateHint procedure.

1) copy forms.pas into your project directory
2) find in it ActivateHint procedure
3) modify hint firing condition.
i.e source condition is
  if FShowHint and (FHintControl <> nil) and ForegroundTask and
    (FHintControl = GetHintControl(FindDragTarget(CursorPos, True))) then
you would modify as
  if FShowHint and (FHintControl <> nil) and  
    (FHintControl = GetHintControl(FindDragTarget(CursorPos, True))) then
i.e delete call ForegroundTask function
4) rebuild project
5) enjoy :)

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZifNabCommented:
Or you could just call the hints yourself. I've some code here. But maybe vladika's solution is better.

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.
0
 
elkiorsCommented:
I know I'm shoehorning into someone elses question but it's kinda relevant. Does anyone know how to create multiline hints ?

Darren
0
 
venksCommented:
I am using a component called danhint which shows multi line hints.It is available at Torrys delphi page
venks
0
 
viktornetCommented:
Hello guys!

Vladika: I saw that DanHint and it's pretty cool. I didn't install it, but it seemed quite useful.. There was a demo app, and that's where I took a peek of how it works and so on...


For a multiline hint you could try this one...

Button1.Hint := 'Hello guys! I don''t know what to say. I think this is enough.' + #10#13 +
                          'or probably not . o O Who cares?? =)';

btw- Tom(Zif)'s solution looks fine :-)

Tom: Did you take a look at the website i gave you at your question (to all of you) about that telephony package???

Cheers,
Viktor
0
 
vladikaCommented:
Ok. DanHint is pretty cool. But is does not solve krazy6284's problem.
So, let's use DanHint as hint control and my or ZifNab solution to display the hints when the application does not have focus
:)

0
 
ZifNabCommented:
viktor, yes I know of this site and it's translation of TAPI. But I'm looking for some components which implement this translation in a easier way. A component package with all this features like voice, fax, X-modem, Z-modem protocols, ...
0
 
krazy6284Author Commented:
vladika great idea and works prefect!!

ZifNab nice bit of code there.

Thank you all for your quick comments. however since those were comments I cant give anyone points :(

vladika could you please resubmit your comment as a question.

Regards,
Charlie
0
 
ThaddyCommented:
This is realy easy, and works like a dream:

procedure TForm1.FormCreate(Sender: TObject);
begin
//Assign a hinthandler  
Application.OnHint:=Processhint;
end;


procedure TForm1.processhint(sender: Tobject);
begin
  statusbar1.simpletext:=Getlonghint(Application.hint);
  //Make shure to call refresh
  refresh;
end;

0
 
vladikaCommented:
Thaddy:
Your solution has some problems:
1) It does not display hint window
2) Hint message appears without delay since it fires in Application.Idle method. And hint window must appears only when hint timer expired, i.e. with small delay.
3) Hint message does not hide automatically after small pause.

Your solution is good to display hint message in status bar, but does not approach to display hint window as krazy6284 wants.

0
 
vladikaCommented:
Solution is below
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now