Registriert seit: 26. Dez 2005
2 Beiträge
Delphi XE7 Enterprise
|
AW: TCustomControl: Focus erhalten wenn Programm aktiv wird
30. Jul 2016, 13:32
Zum Beispiel:
Delphi-Quellcode:
type
TMyControl = class(TCustomControl)
protected
function MainWndHook(var Message: TMessage): Boolean;
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
constructor TMyControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if not (csDesigning in ComponentState) then
Application.HookMainWindow(MainWndHook);
end;
destructor TMyControl.Destroy;
begin
if not (csDesigning in ComponentState) then
Application.UnhookMainWindow(MainWndHook);
inherited Destroy;
end;
function TMyControl.MainWndHook(var Message: TMessage): Boolean;
begin
case Message.Msg of
CM_ACTIVATE,
CM_DEACTIVATE:
Invalidate;
end;
Result := False;
end;
procedure TMyControl.Paint;
const
Colors: array[Boolean] of TColor = (clSilver, clRed);
begin
Canvas.Brush.Color := Colors[(csDesigning in ComponentState) or Application.Active];
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(ClientRect);
end;
Ondrej Kelle
Geändert von TOndrej (30. Jul 2016 um 14:07 Uhr)
|