Ver Mensaje Individual
  #1  
Antiguo 11-11-2008
Avatar de aeff
aeff aeff is offline
Miembro
 
Registrado: oct 2006
Ubicación: Cuba, Guantánamo
Posts: 348
Reputación: 18
aeff Va camino a la fama
Crear un TButton con un skin

saludos, quisiera que me ayudaran a crear un componente heredado del TButton y que se le pueda aplicar un skin, bueno, hasta el momento este skin consiste en rellenar la region del control con un color y pintar un simple rectángulo sobre esa region, para lo cual obtengo el HDC del objeto y se lo asigno al Handle de un objeto TCanvas dentro del nuevo componente, lo que ocurre es que cuando puslo el nuevo TButton ya no se repinta más, ¿por qué será?, ¿me pueden dar una ayuda con esto?

aqui les va el código que he implementado hasta el momento:

Código Delphi [-]
type
 TXButton = class (TButton)
    protected
      FLastWndProc: TWndMethod;
      procedure NewWndProc(var Message: TMessage);
    public
      Canvas: TCanvas;
      constructor Create(aOwner: TComponent); override;
      procedure Click; override;
  end;
 
(...)
 
  constructor TXButton.Create(aOwner: TComponent);
  begin
    Inherited;
    Canvas := TCanvas.Create;
    FLastWndProc := WindowProc;
    WindowProc := NewWndProc;
  end;
  procedure TXButton.Click;
  begin
    inherited;
  end;
  procedure TXButton.NewWndProc(var Message: TMessage);
  var
    DC: HDC;
    vPaintStruct: TPaintStruct;
    procedure Draw();
    begin
      Canvas.Handle := DC;
      Canvas.Brush.Color := RGB(25, 190, 240);
      Canvas.FillRect(Canvas.ClipRect);
      Canvas.Rectangle(5,5, 25 , 15);
    end;
  begin
    case  Message.Msg of
      WM_PAINT:
        begin
          DC := BeginPaint(Handle, vPaintStruct);
          Draw();
          EndPaint(Handle, vPaintStruct);
        end;
       WM_LBUTTONDOWN: begin DRaw(); FLastWndProc(Message); DRaw();end;
       WM_LBUTTONUP: begin DRaw();FLastWndProc(Message); DRaw();end;
       WM_MOUSEMOVE: begin DRaw(); FLastWndProc(Message);DRaw(); end;
       CM_MOUSELEAVE: begin DRaw(); FLastWndProc(Message); DRaw(); end;
       else     FLastWndProc(Message);
    end;
  end;

aqui está como yo creo el objeto en tiempo de ejecución, en el evento OnClick de un button:

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  //
    aBtn :=TXButton.Create(Self);
    aBtn.Parent := self;
    aBtn.Left := 50;
    aBtn.Top:=50;
end;


muchas gracias de antemano, espero recivir ayuda !
saludos!

aeff!
Responder Con Cita