Author: Tomas Rutkauskas
Is there any API call, Delphi function or trick to show a hint window manually?
Answer:
This should get you started:
1 unit HintSelfNoTimer;
2
3 interface
4
5 uses
6 Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, ExtCtrls;
8
9 const
10 UM_EXITPROC = WM_USER + 42;
11
12 type
13 TFrmHintSelfNoTimer = class(TForm)
14 ComboBox1: TComboBox;
15 Edit1: TEdit;
16 procedure Edit1Exit(Sender: TObject);
17 procedure FormCreate(Sender: TObject);
18 procedure Edit1KeyPress(Sender: TObject; var Key: Char);
19 private
20 FActive: boolean;
21 FHint: THintWindow;
22 procedure AppMessage(var AMessage: TMsg; var Handled: Boolean);
23 procedure UMExitProc(var TheMsg: TMessage); message UM_EXITPROC;
24 procedure KillHint;
25 public
26 end;
27
28 var
29 FrmHintSelfNoTimer: TFrmHintSelfNoTimer;
30
31 implementation
32
33 {$R *.DFM}
34
35 procedure TFrmHintSelfNoTimer.AppMessage(var AMessage: TMsg; var Handled: Boolean);
36 begin
37 if (AMessage.message = WM_LBUTTONDOWN) or
38 (AMessage.message = WM_RBUTTONDOWN) then
39 if Assigned(FHint) and FHint.Visible then
40 KillHint;
41 end;
42
43 procedure TFrmHintSelfNoTimer.UMExitProc(var TheMsg: TMessage);
44 begin
45 Edit1.SetFocus;
46 end;
47
48 procedure TFrmHintSelfNoTimer.KillHint;
49 begin
50 FActive := false;
51 if Assigned(FHint) then
52 begin
53 FHint.ReleaseHandle;
54 FHint.Free;
55 FHint := nil;
56 end;
57 end;
58
59 procedure TFrmHintSelfNoTimer.Edit1Exit(Sender: TObject);
60 var
61 thePoint: TPoint;
62 theRect: TRect;
63 theString: string;
64 begin
65 if Edit1.Text <> '42' then
66 begin
67 thePoint.X := Edit1.Left;
68 thePoint.Y := Edit1.Top - 24;
69 with theRect do
70 begin
71 topLeft := ClientToScreen(thePoint);
72 Right := Left + 150;
73 Bottom := Top + 18;
74 end;
75 theString := 'The answer is 42 y''know!';
76 FHint := THintWindow.Create(self);
77 FHint.ActivateHint(theRect, theString);
78 FActive := true;
79 PostMessage(Handle, UM_EXITPROC, 0, 0);
80 end;
81 end;
82
83 procedure TFrmHintSelfNoTimer.FormCreate(Sender: TObject);
84 begin
85 Application.OnMessage := AppMessage;
86 end;
87
88 procedure TFrmHintSelfNoTimer.Edit1KeyPress(Sender: TObject; var Key: Char);
89 begin
90 if Assigned(FHint) and FHint.Visible then
91 KillHint;
92 end;
93
94 end.
|