Solved

how to show hint window when the window is not active?

Posted on 2001-08-22
9
276 Views
Last Modified: 2010-04-06
When my form is not active and I move mouse on a button, I want to show the hint window of the button.How can I do?
0
Comment
Question by:brightsea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 2

Expert Comment

by:RickHalle
ID: 6416576
You might be able to use this:
http://www.undu.com/Articles/991012d.html

Rick Halle
0
 
LVL 2

Expert Comment

by:RickHalle
ID: 6420015
Did that help?
0
 

Author Comment

by:brightsea
ID: 6420494
Thank you,RickHalle.
But my question isn't that.I sad hint window is the hint when I set the Hint property of the button and I set ShowHint := true.
Maybe you can tell me the message to show the hint.
thanks.
0
Technology Partners: 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!

 
LVL 2

Expert Comment

by:RickHalle
ID: 6420524
The catch is the active window part. You can fire the hint fairly easy using the Application.OnHint event and put it wherever you want. The problem I see is that the hint will not fire if the window is not active. I noticed the sample in the link I provided shows a hint window for the form even if it is not active. If you could instead get the hint for the control the cursor was over then you could show the hint for that control. (Instead of the xy coordinates) I know it is not a direct answer but it appeared that with a bit of work it could be coerced into working for buttons also. I played with it a little and was able to get it to pop up a hint window over the buttons by moving the form mousemove stuff to the button mousemove. When I did the window was flashing so it needed more work to find out why and then load the tip into it for the control(button).

Rick Halle
0
 
LVL 2

Accepted Solution

by:
RickHalle earned 50 total points
ID: 6420546
Here is a modified unit for the sample code found at the above link that will display the button hint even if the window is not active. For Button1 you will need to add the mousemove event and set showhint to false.

unit Unit1;

interface

uses
     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
     StdCtrls, ExtCtrls, Buttons;
//if you are using commctrls, place it before windows

type
     TForm1 = class(TForm)
          SpeedButton1: TSpeedButton;
          Button1: TButton;
          Label1: TLabel;
          procedure FormCreate(Sender: TObject);
          procedure Button1Click(Sender: TObject);
          procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
     private
          { Private declarations }
          hwHint: THintWindow;
          procedure MouseLeavesTheForm(var m: TMessage); message WM_MOUSELEAVE;
          procedure UpdateTracking;
     public
          { Public declarations }
     end;

var
     Form1: TForm1;
     isTracking: boolean;
     evtTrack: tagTRACKMOUSEEVENT;

implementation

{$R *.DFM}

//we handle the message telling us that the mouse left the form

procedure TForm1.MouseLeavesTheForm(var m: TMessage);
begin
     inherited;
     hwHint.ReleaseHandle;
     isTracking := False;
     m.Result := 1;
end;

//check if the cursor is no longer over the background
//eg. he is over a button or something

procedure TForm1.UpdateTracking;
var
     P: TPoint;
begin
     GetCursorPos(P);
     if not (FindDragTarget(P, True) = Button1) then
          Perform(WM_MOUSELEAVE, 0, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     with evtTrack do
     begin
          cbSize := sizeOf(tagTRACKMOUSEEVENT);
          dwFlags := TME_LEAVE;
          hwndTrack := Button1.Handle;
          dwHoverTime := HOVER_DEFAULT;
     end;
     hwHint := THintWindow.Create(Button1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     Close;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
     with evtTrack do
     begin
          cbSize := sizeOf(tagTRACKMOUSEEVENT);
          dwFlags := TME_CANCEL and TME_LEAVE;
          hwndTrack := form1.Handle;
          dwHoverTime := HOVER_DEFAULT;
     end;
     if not TrackMouseEvent(evtTrack) then
          MessageDlg('Arg ! Could not unregister the event tracking.', mtError, [mbOK], 0);
end;

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
     pt: TPoint;
     sText: string;
begin
     if not isTracking then
     begin
          if not TrackMouseEvent(evtTrack) then
               MessageDlg('Sorry, I' + #39 + 'm not in the mood of tracking' + #13 + #10 + 'your stupid events.', mtError, [mbOK], 0);
          isTracking := True;
     end;

     getCursorPos(pt);
     sText := Button1.Hint;
     hwHint.ActivateHint(Rect(pt.x + 10, pt.y + 10, pt.x + hwHint.Canvas.TextWidth(sText) + 19,
          pt.y + hwHint.Canvas.TextHeight(sText) + 10), sText);

     UpdateTracking;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
     pt: TPoint;
begin
     if not isTracking then
     begin
          if not TrackMouseEvent(evtTrack) then
               MessageDlg('Sorry, I' + #39 + 'm not in the mood of tracking' + #13 + #10 + 'your stupid events.', mtError, [mbOK], 0);
          isTracking := True;
     end;

     getCursorPos(pt);
     UpdateTracking;
end;

end.


Rick Halle
0
 

Author Comment

by:brightsea
ID: 6420629
thanks.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 6425311
Hi,
Nice to see that for once an article that I write is usefull ;)
John...
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6435201
Small fix jeurk - BTW nice trick :)

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
 Y: Integer);
var
    pt,P: TPoint;
    sText: string;
begin
    if not isTracking then
    begin
         if not TrackMouseEvent(evtTrack) then
              MessageDlg('Sorry, I' + #39 + 'm not in the mood of tracking' + #13 + #10 + 'your stupid events.', mtError, [mbOK], 0);
         isTracking := True;
    end;
    GetCursorPos(P);
    if  (FindDragTarget(P, True) = Button1) then begin
    getCursorPos(pt);
    sText := Button1.Hint;
    hwHint.ActivateHint(Rect(pt.x + 10, pt.y + 10, pt.x + hwHint.Canvas.TextWidth(sText) + 19,
         pt.y + hwHint.Canvas.TextHeight(sText) + 10), sText);

    UpdateTracking;
    end
    else hwHint.ReleaseHandle;
end;
0
 

Expert Comment

by:jjradha
ID: 15020962
Very very good!

I was just wondering how to show hints in c#?
does anybody know about that?

Marcelo Miorelli
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question