// Getestet mit D4 unter WinME //
Hints
anders anzeigen:
//
------------------------------------------------------------- type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen}
public
procedure DisplayHint(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DisplayHint(Sender: TObject);
begin
Label1.caption := Application.Hint;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.caption := '';
Application.OnHint := DisplayHint;
Button1.Hint := 'Button1 Hint-Test';
Button1.ShowHint := false;
Panel1.Hint := 'Panel1 Hint-Test';
Panel1.Showhint := false;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen}
public
procedure DisplayHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DisplayHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
begin
if HintInfo.HintControl = Button1 then
HintInfo.HintColor := cllime
else
if HintInfo.HintControl = Panel1 then
HintInfo.HintColor := $6699FF
else
if HintInfo.HintControl = Memo1 then
HintInfo.HintColor := $FF80FF;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnShowHint := DisplayHint;
Button1.Hint := 'Button1 Hint Test';
Button1.ShowHint := true;
Panel1.Hint := 'Panel1 Hint Test';
Panel1.ShowHint := true;
Memo1.Hint := 'Memo1 Hint Test';
Memo1.ShowHint := true;
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen}
public
procedure DisplayHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DisplayHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
begin
HintInfo.HintMaxWidth := 1; {das längste Wort bestimmt die Breite}
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnShowHint := DisplayHint;
Button1.Hint := 'Dieser Text wird auch umgebrochen';
Button1.ShowHint := true;
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen}
public
procedure DisplayHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DisplayHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
begin
dec(HintInfo.HintPos.y, 30); // Hint nach oben verschieben
inc(HintInfo.HintPos.x, 30); // Hint nach rechts verschieben
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnShowHint := DisplayHint;
Button1.Hint := 'Button1-Hint';
Button1.ShowHint := true;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen}
public
procedure DisplayHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DisplayHint(var HintStr: string; var CanShow: Boolean;
var HintInfo: THintInfo);
begin
HintInfo.ReshowTimeout := Application.HintHidePause;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.HintPause := 0;
Application.OnShowHint := DisplayHint;
Button1.Hint := 'Button1-Hint';
Button1.ShowHint := true;
Panel1.Hint := 'Panel1-Hint';
Panel1.ShowHint := true;
end;
type
TForm1 = class(TForm)
Panel1: TPanel;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ListBox1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
private
{ Private-Deklarationen}
public
procedure DisplayHint(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var MyHint: THintWindow;
procedure TForm1.DisplayHint(Sender: TObject);
var
p: TPoint;
r: TRect;
begin
if Application.Hint = '' then MyHint.ReleaseHandle
else begin
getcursorpos(p);
if WindowfromPoint(p) = Listbox1.handle then begin
r := MyHint.CalcHintRect(screen.width, Application.Hint, nil);
offsetrect(r, p.x, p.y + 30);
MyHint.ActivateHint(r, Application.Hint);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyHint := THintWindow.create(nil);
MyHint.Color := Application.HintColor;
Application.OnHint := DisplayHint;
Listbox1.Items.add('Zeile 1');
Listbox1.Items.add('Zeile 2');
Listbox1.Items.add('Zeile 3');
ListBox1.ShowHint := false;
Panel1.Hint := 'Das ist Panel 1';
Panel1.ShowHint := true;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MyHint.free;
end;
procedure TForm1.ListBox1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
var i: integer;
begin
i := Listbox1.ItemAtPos(point(x, y), true);
if i >= 0 then
Listbox1.Hint := Listbox1.Items[i]
else Listbox1.Hint := '';
end;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen}
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
TMyHintWindow = class(THintWindow)
protected
r: TRect;
dc: HDC;
procedure WMPaint(var m: TMessage); message WM_NCPaint;
end;
procedure TMyHintWindow.WMPaint(var m: TMessage);
begin
dc := getwindowdc(handle);
r := boundsrect;
drawedge(dc, r, EDGE_BUMP, BF_RECT or BF_MONO);
releasedc(handle, dc);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HintWindowClass := TMyHintWindow;
Panel1.Hint := 'Panel';
Panel1.Showhint := true;
Button1.Hint := 'Button';
Button1.Showhint := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// und wieder zurückstellen
HintWindowClass := THintWindow;
end;
// 8.
Schriftart und -größe ändern
procedure TForm1.FormCreate(Sender: TObject);
var x: integer;
begin
for x := 0 to Application.Componentcount - 1 do
if Application.Components[x] is THintWindow then begin
with THintWindow(Application.Components[x]).Canvas.Font
do begin
Name := 'Courier New';
Size := 16;
end;
break;
end;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen}
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
TMyHintWindow = class(THintWindow)
protected
r: TRect;
constructor Create(AOwner: TComponent); override;
procedure paint; override;
end;
constructor TMyHintWindow.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Canvas.Brush.Color := clBlack;
Canvas.Font.Name := 'Courier New';
Canvas.Font.Size := 18;
Canvas.Font.Color := clYellow;
Canvas.Font.Style := [fsItalic, fsBold];
end;
procedure TMyHintWindow.Paint;
begin
r := Clientrect;
canvas.FillRect(r);
offsetrect(r, 2, 2);
DrawText(Canvas.handle, pchar(Caption), -1, r, dt_left or dt_noprefix or
dt_wordbreak);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HintWindowClass := TMyHintWindow;
Panel1.Hint := 'Panel-Hint';
Panel1.Showhint := true;
Button1.Hint := 'Button-Hint';
Button1.Showhint := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// und wieder zurückstellen
HintWindowClass := THintWindow;
end;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen}
public
procedure DisplayHint(Sender: TObject);
procedure aus;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
TMyHintWindow = class(THintWindow)
protected
procedure paint; override;
end;
var
MyHint: THintWindow;
r: TRect;
rgn: HRgn;
WErweitern, SErweitern: integer;
procedure TMyHintWindow.Paint;
begin
rgn := CreateEllipticRgn(3, 3, width - 2, height - 2);
setwindowRgn(MyHint.handle, rgn, true);
canvas.ellipse(2, 2, width - 4, height - 4);
canvas.textout(WErweitern + 2, SErweitern + 2, Application.Hint);
end;
procedure TForm1.DisplayHint(Sender: TObject);
begin
if Application.Hint = '' then aus
else begin
r := MyHint.CalcHintRect(250, Application.Hint, nil);
WErweitern := MyHint.Canvas.Font.Size * 2;
SErweitern := r.right div r.bottom;
inflaterect(r, WErweitern, SErweitern);
Timer1.interval := Application.Hintpause;
end;
end;
procedure TForm1.aus;
begin
Timer1.interval := 0;
MyHint.ReleaseHandle;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.interval := 0;
MyHint := TMyHintWindow.create(nil);
MyHint.Color := Application.HintColor;
Application.OnHint := DisplayHint;
Panel1.Hint := 'Das ist ein Test für den Hint von Panel 1';
Panel1.ShowHint := false;
Button1.Hint := 'Das ist Button 1';
Button1.ShowHint := false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
p: TPoint;
begin
if Integer(Timer1.interval) = Application.HintHidePause then aus
else begin
getcursorpos(p);
offsetrect(r, p.x, p.y + 32 + SErweitern div 2);
Timer1.interval := Application.HintHidePause;
MyHint.ActivateHint(r, Application.Hint);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MyHint.free;
end;
//
------------------------------------------------------------- type
TShadowedHintWindow = class(THintWindow)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
var
Form1: TForm1;
implementation
procedure TShadowedHintWindow.CreateParams(var Params: TCreateParams);
begin
inherited;
if (Win32Platform = VER_PLATFORM_WIN32_NT) and
((Win32MajorVersion > 5) or
((Win32MajorVersion = 5) and (Win32MinorVersion >= 1))) then
Params.WindowClass.Style := Params.WindowClass.Style or $20000;
end;
initialization
HintWindowClass := TShadowedHintWindow;
end.
//
------------------------------------------------------------- type
TMyHintWindow = class(THintWindow)
public
r: TRect;
constructor Create(AOwner: TComponent); override;
procedure Paint; override;
end;
constructor TMyHintWindow.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Canvas.Brush.Color := clyellow;
end;
procedure TMyHintWindow.Paint;
begin
r := Clientrect;
Canvas.FillRect(r);
Canvas.Font.Color := clblue;
offsetrect(r, 2, 2);
DrawText(Canvas.handle, pchar(Caption), -1, r, dt_left or dt_noprefix or
dt_wordbreak);
end;
var
lgf: TLogFont;
NewFont: THandle;
procedure TForm2.FormCreate(Sender: TObject);
begin
HintWindowClass := TMyHintWindow;
lgf.lfFaceName := 'Times New Roman';
lgf.lfWeight := FW_Bold;
lgf.lfHeight := 18;
lgf.lfItalic := 1;
NewFont := CreateFontIndirect(lgf);
Screen.HintFont.handle := NewFont;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if NewFont > 0 then
DeleteObject(NewFont)
end;
|





