Forms Delphi

Title: Call AnimateWindow the safe way
Question: AnimateWindow is a API which can enhance your GUI by adding special animations to your forms. However, the API is not valid in all operating systems. It is only valid in Windows 98 / 2000 and
This code shows you how to use AnimateWindow when (and only when) it is supported. Without crashing and burning when it is not supported.
Answer:
procedure AnimateSafe(hWnd: HWND; dwTime: DWord; dwFlags: DWord);
type
d = function(a: THandle; b, c: DWord): Boolean; stdcall;
var
e, f: integer;
g: d;
begin
try
e := LoadLibrary('user32.dll');
if e = 0 then
exit
else
begin
g := GetProcAddress(e, 'AnimateWindow');
if @g = nil then
exit
else
begin
g(hWnd, dwTime, dwFlags);
end;
end;
finally
FreeLibrary(e);
end;
end;
//Use AnimateSafe like:
procedure TForm1.FormCreate(Sender: TObject);
begin
AnimateSafe(Handle, 300, AW_BLEND or AW_ACTIVATE);
Self.Invalidate;
end;
(*
dwFlags can be:
AW_SLIDE
Uses slide animation. By default, roll animation is used. This flag is ignored when used with AW_CENTER.
AW_ACTIVATE
Activates the window. Do not use this value with AW_HIDE.
AW_BLEND
Uses a fade effect. This flag can be used only if hwnd is a top-level window.
AW_HIDE
Hides the window. By default, the window is shown.
AW_CENTER
Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
AW_HOR_POSITIVE
Animates the window from left to right. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_HOR_NEGATIVE
Animates the window from right to left. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_POSITIVE
Animates the window from top to bottom. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_NEGATIVE
Animates the window from bottom to top. This flag can be used with roll or slide animation. It is ignored when used with AW_CENTER or AW_BLEND.
*)