Solved

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

Posted on 2001-08-22
9
266 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
Comment Utility
You might be able to use this:
http://www.undu.com/Articles/991012d.html

Rick Halle
0
 
LVL 2

Expert Comment

by:RickHalle
Comment Utility
Did that help?
0
 

Author Comment

by:brightsea
Comment Utility
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
 
LVL 2

Expert Comment

by:RickHalle
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Accepted Solution

by:
RickHalle earned 50 total points
Comment Utility
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
Comment Utility
thanks.
0
 
LVL 4

Expert Comment

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

Expert Comment

by:ginsonic
Comment Utility
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
Comment Utility
Very very good!

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

Marcelo Miorelli
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now