Привожу процедуру прорисовки тени от модальной формы (Window XP). Жду замечаний и советов...
Подключение к форме:
FormShadow:= NewShadowForm(Form1.Form);
Form1.Form.AttachProc(WndProcFormShadow);
unit FmShadow;
interface
uses Windows, Messages, KOL , Variants;
function WndProcFormShadow(Self_: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
function NewShadowForm(pForm: PControl): PControl;
var
FormShadow: PControl;
implementation
var
ShadowSize: Integer = 20;
ShadowColor: TColor = clBlack;
ShadowAlphaBlend: Byte = 120;
function WndProcFormShadow(Self_: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
var Bounds: TRect;
begin
if (Msg.Message = WM_WINDOWPOSCHANGED) or
(Msg.Message = WM_KILLFOCUS) then begin
GetWindowRect(Self_.Handle, Bounds);
SetWindowPos(FormShadow.Handle, Self_.Handle, Bounds.Left + ShadowSize,
Bounds.Top + ShadowSize, Bounds.Right - Bounds.Left,
Bounds.Bottom - Bounds.Top, SWP_NOACTIVATE + SWP_SHOWWINDOW);
end;
Result:= False;
end;
function NewShadowForm(pForm: PControl): PControl;
var r: TRect; aWidth, aHeight: Integer;
Src, Dst: HRGN;
begin
Result:= NewForm(Applet, '');
pForm.CanResize:= False;
pForm.StayOnTop:= True;
pForm.Style := pForm.Style and not WS_MAXIMIZEBOX;
with Result^ do begin
HasBorder:= False;
HasCaption:= False;
Color:= ShadowColor;
GetWindowRect(pForm.Handle, r);
aWidth:= r.Right - r.Left;
aHeight:= r.Bottom - r.Top;
Src:= CreateRectRgn(0, 0, aWidth, aHeight);
Dst:= CreateRectRgn(0, 0, aWidth - ShadowSize, aHeight - ShadowSize);
CombineRgn(Src, Src, Dst, RGN_DIFF);
SetWindowRgn(Handle, Src, True);
AlphaBlend:= ShadowAlphaBlend;
SetWindowPos(Handle, HWND_TOP, r.Left + ShadowSize, r.Top + ShadowSize,
aWidth, aHeight, SWP_NOACTIVATE + SWP_SHOWWINDOW);
DeleteObject(Src);
DeleteObject(Dst);
end;
end;
end.