Ver Mensaje Individual
  #4  
Antiguo 03-12-2009
Avatar de rgstuamigo
rgstuamigo rgstuamigo is offline
Miembro
 
Registrado: jul 2008
Ubicación: Santa Cruz de la Sierra-Bolivia
Posts: 1.646
Reputación: 17
rgstuamigo Va por buen camino
Arrow

Aqui te pongo el codigo de un componente (adaptado por mi) descendiente de TMemo que se pone trasparente cuando no tiene el foco..
Código Delphi [-]
unit AlphaMemo;
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

const
  TWM_RGSInvalidate=WM_USER+1;

type
  TAlphaMemo=class(TMemo)
  private
    { Private declarations }
    procedure RgsInvalidate(var Message:TMessage); message
              TWM_RGSInvalidate;
    procedure CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT); message
              CN_CTLCOLOREDIT;
    procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
    procedure WMMove(var Message: TMessage); message WM_MOVE;

  protected
    { Protected declarations }
    FTransparent: boolean;
    procedure CreateWnd; override;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure DoExit; override;
    procedure DoEnter; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    procedure Invalidate; override;

  published
    { Published declarations }
  end;

procedure Register;

implementation

constructor TAlphaMemo.Create(AOwner:TComponent);
begin
inherited create(AOwner);
   ftransparent:=true;
end;

procedure TAlphaMemo.CreateWnd;
begin
inherited CreateWnd;
   if fTransparent then
      begin
       SetWindowLong(Parent.Handle, GWL_STYLE,
       GetWindowLong(Parent.Handle, GWL_STYLE) and not WS_CLIPCHILDREN);
       end;
end;

procedure TAlphaMemo.RgsInvalidate(var Message:TMessage);
var r:TRect;
begin
  if (Parent<>nil) and FTransparent then
    begin
      r:=ClientRect;
      r.TopLeft:=Parent.ScreenToClient(ClientToScreen(r.TopLeft));
      r.BottomRight:=Parent.ScreenToClient(ClientToScreen(r.BottomRight));
      RedrawWindow(Handle,nil,0,RDW_FRAME+RDW_INVALIDATE);
    end;
end;

procedure TAlphaMemo.CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT);
begin
  if FTransparent then
   with Message do
    begin
      SetBkMode(ChildDC,Windows.TRANSPARENT);
      Result:=GetStockObject(HOLLOW_BRUSH)
    end
   else inherited;
end;



procedure TAlphaMemo.WMEraseBkgnd(var Message:TWMERASEBKGND);
begin
  if FTransparent and not (csDesigning in ComponentState) then
      PostMessage(Handle,TWM_RGSInvalidate,0,0)
  else inherited;
end;

procedure TAlphaMemo.WMMove(var message:TMessage);
begin
inherited;
if FTransparent then SendMessage(Handle,TWM_RGSInvalidate,0,0)
  else Invalidate;
end;

procedure TAlphaMemo.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
if (CsDesigning in ComponentState) then exit;
    with Params do
      begin
   ExStyle:=ExStyle or WS_EX_TRANSPARENT;
      end;
end;

procedure TAlphaMemo.DoExit;
begin
inherited;
   FTransparent:=true;
   SetCursor(0);
   RecreateWnd;
end;

procedure TAlphaMemo.DoEnter;
var ExStyle,StdStyle:longint;
begin
inherited;
Ftransparent:=False;
StdStyle:= Windows.GetWindowLong(handle, GWL_EXSTYLE);
ExStyle:= StdStyle and not WS_EX_TRANSPARENT;
Windows.SetWindowLong(Handle, GWL_EXSTYLE, exStyle);
Invalidate;
end;

procedure TAlphaMemo.Invalidate;
begin
if FTransparent then SendMessage(Handle,TWM_RGSInvalidate,0,0)
  else inherited;
end;

procedure Register;
begin
  RegisterComponents('MyComponents', [TAlphaMemo]);
end;

end.
Solo copia y pega el codigo en una nueva unidad ,lo guardas y luego lo instalas.
Saludos...
__________________
"Pedid, y se os dará; buscad, y hallaréis; llamad, y se os abrirá." Mt.7:7

Última edición por rgstuamigo fecha: 03-12-2009 a las 15:53:51.
Responder Con Cita