Uso el código de este artículo http://melander.dk/articles/alphasplash/ para mostrar un mapa de bits de 32 bits en un formulario, pero cuando intento utilizar un mapa de bits de color sólido en lugar de una imagen, no se recibe el mensaje WM_NCHITTEST y No puedo mover el formulario. Si uso 32 imágenes de mapa de bits el código funciona bien. ¿Qué me falta aquí?WM_NCHITTEST no funciona en formato WS_EX_LAYERED
Este es el código
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
protected
{ Private declarations }
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
public
{ Public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
BlendFunction: TBlendFunction;
BitmapPos: TPoint;
BitmapSize: TSize;
exStyle: DWORD;
Bitmap: TBitmap;
begin
// Enable window layering
exStyle := GetWindowLongA(Handle, GWL_EXSTYLE);
if (exStyle and WS_EX_LAYERED = 0) then
SetWindowLong(Handle, GWL_EXSTYLE, exStyle or WS_EX_LAYERED);
Bitmap := TBitmap.Create;
try
//Bitmap.LoadFromFile('splash.bmp'); //if I use a image the code works fine
Bitmap.PixelFormat := pf32bit;
Bitmap.SetSize(Width, Height);
Bitmap.Canvas.Brush.Color:=clRed;
Bitmap.Canvas.FillRect(Rect(0,0, Bitmap.Width, Bitmap.Height));
// Position bitmap on form
BitmapPos := Point(0, 0);
BitmapSize.cx := Bitmap.Width;
BitmapSize.cy := Bitmap.Height;
// Setup alpha blending parameters
BlendFunction.BlendOp := AC_SRC_OVER;
BlendFunction.BlendFlags := 0;
BlendFunction.SourceConstantAlpha := 255;
BlendFunction.AlphaFormat := AC_SRC_ALPHA;
UpdateLayeredWindow(Handle, 0, nil, @BitmapSize, Bitmap.Canvas.Handle,
@BitmapPos, 0, @BlendFunction, ULW_ALPHA);
Show;
finally
Bitmap.Free;
end;
end;
procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
begin
Message.Result := HTCAPTION;
end;
end.
+1, no entiendo lo que significa, pero estoy seguro de que sabes :-) Solo estaba tomando este problema por mi intuición. – TLama
Muchas gracias. – Salvador
@TLama - ¡No estés tan seguro! He votado a favor de su respuesta porque pensé lo mismo para usted. Realmente, no soy un experto, pero está claramente documentado en 'BLENDFUNCTION'. Mi punto de vista es que tu respuesta también fue correcta. El único problema con esto fue que produjo una imagen con valores alfa arbitrarios, pero en un mapa de bits de un solo color no hay problema. –