1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| {*------------------------------------------------------------------------------
Unité permettant de griser une form lorsqu'elle appelle un showmodal pour
en afficher une autre
@Author tiki06 (Avec l'aide de Sub0)
@Version 02-août-2006 Version initiale
-------------------------------------------------------------------------------}
Unit UGriserForm;
Interface
Uses Windows, Forms, Types, Graphics;
const
PIXELCOUNTMAX = 32768;
WS_EX_LAYERED = $80000;
type
pRGBArray = ^TRGBArray;
TRGBArray = ARRAY[0..PIXELCOUNTMAX-1] OF TRGBTriple;
Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap);
Function CustomShowModal(Fenetre: TForm):integer;
implementation
{*------------------------------------------------------------------------------
Fonction pour fusioner la form et l'image grisé
@param FusionForm Form a fusioner
@param BmpGrise Bitmap de l'image grisé
-------------------------------------------------------------------------------}
Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap);
Var
Size : PSIZE;
TopLeft, BmpTopLeft : TPoint;
Blend : TBlendFunction;
Begin
With FusionForm Do
Begin
SetWindowLong(Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) Or WS_EX_LAYERED);
New(Size);
Size.cx := Width;
Size.cy := Height;
TopLeft := BoundsRect.TopLeft;
BmpTopLeft := Point(0, 0);
With Blend Do Begin
BlendOp := 0;
BlendFlags := 0;
SourceConstantAlpha := 255;
AlphaFormat := 0;
End;
BmpGrise.PixelFormat := pf32bit;
UpdateLayeredWindow(Handle, GetDC(0), @TopLeft, Size,
BmpGrise.Canvas.handle, @BmpTopLeft, 0, @Blend, 2);
End;
End;
{*----------------------------------------------------------------------------
Fonction pour afficher une fenêtre en showmodal et griser celle qui est
active pendant l'appel du showmodal
@param Fenetre Form a afficher en Showmodal
-----------------------------------------------------------------------------}
Function CustomShowModal(Fenetre: TForm):integer;
var
WindowHandle : THandle;
deviceContext : HDC;
BitmapForm : Tbitmap;
icolor : integer;
r,g,b : byte;
iheight,iwidth : integer;
RowOriginal : pRGBArray;
FormGrise : TForm;
PosLeft,PosTop,Delta : Integer;
begin
WindowHandle:= Screen.ActiveForm.Handle;
deviceContext:= GetWindowDC(WindowHandle);
try
BitmapForm := Tbitmap.Create;
BitmapForm.PixelFormat := pf24bit;
BitmapForm.Width := Screen.ActiveForm.Width;
BitmapForm.Height := Screen.ActiveForm.Height;
BitBlt(BitmapForm.Canvas.Handle, 0, 0, BitmapForm.Width, BitmapForm.Height,
deviceContext, 0, 0, SRCCOPY);
finally
ReleaseDC(WindowHandle, deviceContext);
end;
for iHeight := 0 to BitmapForm.height-1 do
begin
RowOriginal := pRGBArray(BitmapForm.Scanline[iHeight]);
for iWidth := 0 to BitmapForm.width-1 do
begin
r:=RowOriginal[iWidth].rgbtRed;
g:=RowOriginal[iWidth].rgbtGreen;
b:=RowOriginal[iWidth].rgbtBlue;
icolor:=(r+g+b) div 3;
RowOriginal[iWidth].rgbtRed := icolor;
RowOriginal[iWidth].rgbtGreen := icolor;
RowOriginal[iWidth].rgbtBlue := icolor;
end;
end;
FormGrise := Tform.Create(Screen.ActiveForm);
FormGrise.Name := 'GrayscaleForm';
FormGrise.Caption := Screen.ActiveForm.Caption;
if Screen.ActiveForm.FormStyle = FsMdiChild then
begin
PosTop := Screen.ActiveForm.ClientOrigin.Y-(Screen.ActiveForm.Height-Screen.ActiveForm.ClientHeight);
PosLeft := Screen.ActiveForm.ClientOrigin.X-(Screen.ActiveForm.Width-Screen.ActiveForm.ClientWidth);
Delta := round((Application.mainform.Width-Application.MainForm.ClientWidth)/2)+ Screen.ActiveForm.BorderWidth;
if Screen.ActiveForm.BorderStyle in [bsSingle,bsToolWindow] then
Dec(Delta);
FormGrise.Top := PosTop+Delta;
FormGrise.left := PosLeft+Delta;
end
else
Begin
FormGrise.Top := Screen.ActiveForm.Top;
FormGrise.Left := Screen.ActiveForm.Left;
end;
FormGrise.Width := Screen.ActiveForm.Width;
FormGrise.Height := Screen.ActiveForm.Height;
FormGrise.DoubleBuffered := True;
FormGrise.BorderIcons := Screen.ActiveForm.BorderIcons;
FormGrise.BorderStyle := Screen.ActiveForm.BorderStyle;
FormGrise.Show;
FusionerImage(FormGrise,BitmapForm);
FormGrise.BringToFront;
BitmapForm.Free;
Result:=Fenetre.ShowModal;
if FormGrise<>nil then FormGrise.Release;
end;
End. |
Partager