Solved

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

Posted on 2001-08-22
9
273 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
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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