• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

I want to know how to make a hint come up above the text cursor position (caret) regardless of which application im in.

I want to know how to make a hint come up above the text cursor position (caret) regardless of which application im in.
Is there a way to do that? how?

Many thanks,

Ben
0
Alpha_AI
Asked:
Alpha_AI
1 Solution
 
TheRealLokiSenior DeveloperCommented:
here's a quick demo I wrote for you

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    bShowHintIn2Seconds: TButton;
    cbFollowMouse: TCheckBox;
    Timer1: TTimer;
    Memo1: TMemo;
    procedure bShowHintIn2SecondsClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    HintW: THintWindow;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.bShowHintIn2SecondsClick(Sender: TObject);
begin
  Timer1.Interval := 2000;
  Timer1.Enabled := true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
 R1, R2: TRect;
 mousepos: tpoint;
 hinttext: string;
begin
  Timer1.Enabled := false;
  if not assigned(HintW) then
  begin
    hinttext := memo1.Lines.Text;
    HintW := THintWindow.Create(Form1);
    R1 := HintW.CalcHintRect(150, hinttext, NIL);
    mousepos := Mouse.CursorPos;

    R2.Top := Mouse.CursorPos.y - R1.Bottom - 4;
    R2.Left := mousepos.x;
    R2.Bottom := R2.Top + R1.Bottom;
    R2.Right := R2.Left + R1.Right;
    R2.Bottom := Mouse.CursorPos.y;
    HintW.Hint := hinttext;
    HintW.Parent := nil; //Form1;
    HintW.Color:= clInfoBk;
    HintW.ActivateHint(R2, hinttext);
    if cbFollowMouse.Checked then
    begin
      Timer1.Interval := 100;
      Timer1.Enabled := true;
    end
    else
    begin
      Timer1.Interval := 2000; // stay active for 2 seconds before disappearing
      Timer1.Enabled := true;
    end;
  end
  else if cbFollowMouse.Checked then
  begin // stay alive until unchecked
    mousepos := Mouse.CursorPos;
    HintW.Top := Mouse.CursorPos.y - HintW.Height - 4;
    HintW.Left := mousepos.x;
    Timer1.Interval := 100;
    Timer1.Enabled := true;
  end
  else
  begin // 2 seconds are up, and we are not following mouse, so close the hint
    FreeAndNil(HintW);
  end;
end;

end.


**** FORM FOLLOWS ****

object Form1: TForm1
  Left = 249
  Top = 107
  Width = 390
  Height = 261
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object bShowHintIn2Seconds: TButton
    Left = 24
    Top = 16
    Width = 129
    Height = 25
    Caption = 'bShowHintIn2Seconds'
    TabOrder = 0
    OnClick = bShowHintIn2SecondsClick
  end
  object cbFollowMouse: TCheckBox
    Left = 172
    Top = 16
    Width = 97
    Height = 17
    Caption = 'cbFollowMouse'
    TabOrder = 1
  end
  object Memo1: TMemo
    Left = 28
    Top = 72
    Width = 129
    Height = 93
    Lines.Strings = (
      'This is the hint'
      'text for you')
    TabOrder = 2
  end
  object Timer1: TTimer
    Enabled = False
    Interval = 2000
    OnTimer = Timer1Timer
    Left = 172
    Top = 44
  end
end

hth, Loki
0

Featured Post

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!

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