2009. november 11., szerda
Change the look of Hint Window in the Delphi IDE
Problem/Question/Abstract:
How to change the look of Hint window in Delphi IDE/ in your application
Answer:
You would all have seen the hint window that appears when you focus your cursor on the controls in the Component pages in the delphi ide, (and also in the editor window in case of delphi5 and above). Here is a piece of code that u can use to change the look and feel of the hint window that appears in the delphi ide. You can use this in your application as well.
unit SNHintWindow;
interface
uses
Windows, Messages, Classes, Graphics, Controls, Forms;
type
TSNHintWindow = class(THintWindow)
private
{ Private declarations }
FRegion: THandle;
procedure FreeCurrentRegion;
public
{ Public declarations }
destructor Destroy; override;
procedure ActivateHint(Rect: TRect; const AHint: string); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure Paint; override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Hint Window', [TSNHintWindow]);
end;
destructor TSNHintWindow.Destroy;
begin
FreeCurrentRegion;
inherited Destroy;
end;
procedure TSNHintWindow.FreeCurrentRegion;
{Regions like other API objects should be freed when we have
finished using them. However we cannot delete a region that is
currently set in a window. Therefore in this method I set
the window region to 0 before deleting the region object}
begin
if FRegion <> 0 then
begin
SetWindowRgn(Handle, 0, True);
DeleteObject(FRegion);
FRegion := 0;
end;
end;
procedure TSNHintWindow.ActivateHint(Rect: TRect; const AHint: string);
begin
with Rect do
begin
Left := Left + Canvas.TextWidth('SUBHA'); {Can be any text}
Right := Right + Canvas.TextWidth('SUBHA'); {Can be any text}
Bottom := Bottom + Canvas.TextHeight('Girija'); {Can be any text}
Top := Top + Canvas.TextHeight('Giri'); {Can be any text}
end;
BoundsRect := Rect;
FreeCurrentRegion;
with BoundsRect do
FRegion := CreateRoundRectRgn(0, 0, width, height, width, height);
if FRegion <> 0 then
SetWindowRgn(Handle, FRegion, True);
inherited ActivateHint(Rect, AHint);
end;
procedure TSNHintWindow.CreateParams(var Params: TCreateParams);
{Here we remove the border created on the windows API-level
when the window is created}
begin
inherited CreateParams(Params);
Params.Style := Params.Style and not WS_BORDER;
end;
procedure TSNHintWindow.Paint;
{This methid gets called by wm_paint handler. It is responsible
for painting the hint window}
var
r: TRect;
begin
r := ClientRect; {get bounding rectangle}
Inc(r.Left, 1); {move left side slightly}
Canvas.Brush.Color := clAqua; {Set background color and font color}
Canvas.Font.Color := clFuchsia;
{paint string in the center of the round rect}
DrawText(Canvas.handle, PChar(Caption), Length(Caption), R,
DT_NOPREFIX or DT_WORDBREAK or DT_CENTER or DT_VCENTER);
end;
initialization
Application.ShowHint := False; // destroy old hint window
HintWindowClass := TSNHintWindow; // assign new hint window
Application.ShowHint := True; // create new hint window
end.
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése