unit EditExt;
interface
uses
StdCtrls, Classes, Windows;
type
TCustomEditExtention =
class helper for TCustomEdit
private
function GetAlignmentValue: TAlignment;
procedure SetAlignmentValue(InVal: TAlignment);
function GetNumbersOnlyValue: Boolean;
procedure SetNumbersOnlyValue(InVal: Boolean);
function GetTextHintValue: String;
procedure SetTextHint(InVal: String);
published
property Alignment: TAlignment read GetAlignmentValue write SetAlignmentValue;
property NumbersOnly: Boolean read GetNumbersOnlyValue write SetNumbersOnlyValue;
property TextHint: String read GetTextHintValue write SetTextHint;
end;
const
ECM_FIRST = $1500;
EM_SETCUEBANNER = ECM_FIRST + 1;
EM_GETCUEBANNER = ECM_FIRST + 2;
implementation
function TCustomEditExtention.GetAlignmentValue: TAlignment;
var
wh, al: Integer;
begin
wh := GetWindowLong(Self.Handle, GWL_STYLE);
if (wh and ES_CENTER) = ES_CENTER then
result := taCenter
else if (wh and ES_CENTER) = ES_RIGHT then
result := taRightJustify
else
result := taLeftJustify;
end;
procedure TCustomEditExtention.SetAlignmentValue(InVal: TAlignment);
var
wh, al: Integer;
begin
case InVal of
taRightJustify:
al := ES_RIGHT;
taCenter:
al := ES_CENTER;
else
al := ES_LEFT;
end;
wh := GetWindowLong(Self.Handle, GWL_STYLE);
SetWindowLong(Self.Handle, GWL_STYLE, (wh and $FFFFFFFC) or al);
Self.Refresh;
end;
function TCustomEditExtention.GetNumbersOnlyValue: Boolean;
var
wh: Integer;
al: Integer;
begin
wh := GetWindowLong(Self.Handle, GWL_STYLE);
result := ((wh and ES_NUMBER) = ES_NUMBER);
end;
procedure TCustomEditExtention.SetNumbersOnlyValue(InVal: Boolean);
var
wh: Integer;
al: Integer;
begin
if InVal then
al := ES_NUMBER
else
al := 0;
wh := GetWindowLong(Self.Handle, GWL_STYLE);
SetWindowLong(Self.Handle, GWL_STYLE, (wh and $FFFFDFFF) or al);
Self.Refresh;
end;
function TCustomEditExtention.GetTextHintValue: String;
const
Buf_Size = 512;
var
w: PWideChar;
begin
result := '';
w := AllocMem(Buf_Size);
try
SendMessage(Self.handle, EM_GETCUEBANNER, WParam(w), LParam(Buf_Size));
result := WideCharToString(w);
finally
FreeMem(w);
end;
end;
procedure TCustomEditExtention.SetTextHint(InVal: String);
var
w: WideString;
begin
w := InVal;
SendMessage(Self.handle, EM_SETCUEBANNER, 1, LParam(PWideChar(w)));
Self.Refresh;
end;
end.
|