There is a PNG image that I put on the form. Naturally, before this form do "puff". Then I call UpdateLayeredWindow with all the necessary parameters. Everything is wonderful. Both the form is shown and PNG is applied as it should be.
BUT
One day, I decided to print something like Caption for this form. I just brought the text to a pre-prepared bitmap, and then again used UpdateLayeredWindow . To my surprise, the displayed text became “transparent” for clicks. That is, if my window is over any text editor, then when you hover the mouse over the text, the cursor takes the form as you type text.
Actually, the question is : is it really possible to display the text correctly on the Layered-window or is it impossible in principle. Note: GDI + does not even consider.
An example of how this looks is given below.
The brown background is my PNG image. If you need to - tell me, I'll post it here.
Decision
Perhaps there is a better solution to the problem described, but so far I have found only that.
Suppose that we have a ready bitmap bitmap and it also has transparency. Then we load this bitmap into an instance of the TBitmap class and make a copy of it onto a third-party bitmap. After that, we display text, pictures, etc. on the made copy, then we call the CopyAlphaChannel procedure to restore the transparency of the pixels overwritten by the output of text, pictures, etc. In the end, we need to copy the resulting image to the original bitmap and pass it as one of the parameters for the UpdateLayeredWindow function.
Sample code:
procedure TForm1.Button1Click(Sender: TObject); var OutBmp, B: TBitmap; begin // Здесь уже должны быть сделаны все приготовления для вывода OutBmp с помощью функции UpdateLayeredWindow // Создаем наш битмап для вывода текста B := TBitmap.Create; B.Width := OutBmp.Width; B.Height := OutBmp.Height; B.PixelFormat := pf32bit; // Делаем копию оригинального битмапа B.Canvas.Draw(0, 0, OutBmp); // Выводим текст, например B.Canvas.Brush.Style := bsClear; B.Canvas.Font.Style := [fsBold]; B.Canvas.Font.Color := clYellow; B.Canvas.Font.Size := 11; B.Canvas.TextOut(4, 4, 'Simple txt string'); B.Canvas.Brush.Style := bsSolid; // Собственно, цель этого куска кода - восстановление затертой альфы CopyAlphaChannel(OutBmp, B); // Копируем буфер обратно на оригинал OutBmp.Canvas.Draw(0, 0, B); B.Free; // Далее OutBmp передается как один из параметров для UpdateLayeredWindow end; Now it's up to the alpha channel copy procedure:
procedure CopyAlphaChannel(ABmpIn, ABmpOut: TBitmap); type TRGBAArray = array[Word] of TRGBQuad; PRGBAArray = ^TRGBAArray; var X: Integer; Y: Integer; RowIn: PRGBAArray; RowOut: PRGBAArray; begin // ABmpIn - битмап, содержащий альфа-канал if not Assigned(ABmpIn) or not Assigned(ABmpOut) then Exit; for Y:=0 to ABmpIn.Height - 1 do begin RowIn := ABmpIn.ScanLine[Y]; RowOut := ABmpOut.ScanLine[Y]; for X:=0 to ABmpIn.Width - 1 do RowOut[X].rgbReserved := RowIn[X].rgbReserved; end; end; 