Solved

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

Posted on 2001-08-22
9
274 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 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