FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour BTNBMP disabled
Posts: 128
Joined: Wed Oct 26, 2005 12:18 PM

BTNBMP disabled

Posted: Sat Feb 14, 2009 12:49 AM
Hola, Antonio:

EL siguiente código en Delphi puede ser de utilidad para que tBtnBmp dibuje los botones deshabilitados, sin necesidad de tener que crear imágenes adicionales.

Fuente: http://www.scalabium.com/faq/dct0137.htm



You can use the next my CreateDisabledBitmap procedure where such "disabled" bitmap (Destination parameter) will be created from your original bitmap (Source).

procedure CreateDisabledBitmap(Source, Destination: TBitmap);
const
ROP_DSPDxax = $00E20746;
var
DDB, MonoBmp: TBitmap;
IWidth, IHeight: Integer;
IRect: TRect;
begin
IWidth := Source.Width;
IHeight := Source.Height;

Destination.Width := IWidth;
Destination.Height := IHeight;
IRect := Rect(0, 0, IWidth, IHeight);
Destination.Canvas.Brush.Color := clBtnFace;
Destination.Palette := CopyPalette(Source.Palette);
MonoBmp := nil;
DDB := nil;
try
MonoBmp := TBitmap.Create;
DDB := TBitmap.Create;
DDB.Assign(Source);
DDB.HandleType := bmDDB;

{ Create a disabled version }
with MonoBmp do
begin
Assign(Source);
HandleType := bmDDB;
Canvas.Brush.Color := clBlack;
Width := IWidth;
if Monochrome then
begin
Canvas.Font.Color := clWhite;
Monochrome := False;
Canvas.Brush.Color := clWhite;
end;
Monochrome := True;
end;
with Destination.Canvas do
begin
Brush.Color := clBtnFace;
FillRect(IRect);
Brush.Color := clBtnHighlight;
SetTextColor(Handle, clBlack);
SetBkColor(Handle, clWhite);
BitBlt(Handle, 1, 1, IWidth, IHeight,
MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
Brush.Color := clBtnShadow;
SetTextColor(Handle, clBlack);
SetBkColor(Handle, clWhite);
BitBlt(Handle, 0, 0, IWidth, IHeight,
MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
end;
finally
DDB.Free;
MonoBmp.Free;
end;
Source.Dormant;
end;

Sample of use:

procedure TfrmMain.ButtonClick(Sender: TObject);
var
Destination: TBitmap;
begin
Destination := TBitmap.Create;
try
CreateDisabledBitmap(Image1.Picture.Bitmap, Destination);
Image2.Picture.Bitmap.Assign(Destination);
finally
Destination.Free
end
end;
where Image1 is TImage where you have an original bitmap and TImage2 will a container for created disabled bitmap

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: BTNBMP disabled

Posted: Fri Feb 27, 2009 02:09 PM

Cesar,

FWH proporciona las siguientes funciones:

DRAWGRAYED( hDC, hBitmap, nRow, nCol ) // dibuja el bitmap en gris entramado
DRAWGRAY( hDC, hBitmap, nRow, nCol ) // dibuja el bitmap en tonos de grises

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion