[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

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

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
brightsea
Asked:
brightsea
1 Solution
 
RickHalleCommented:
You might be able to use this:
http://www.undu.com/Articles/991012d.html

Rick Halle
0
 
RickHalleCommented:
Did that help?
0
 
brightseaAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
RickHalleCommented:
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
 
RickHalleCommented:
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
 
brightseaAuthor Commented:
thanks.
0
 
jeurkCommented:
Hi,
Nice to see that for once an article that I write is usefull ;)
John...
0
 
ginsonicCommented:
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
 
jjradhaCommented:
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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