{
DialogHandle Example
Here is part of the window procedure for Delphi's encapsulation of the Windows search-and-replace common dialog box:
} 
function SearchAndReplaceWndProc(Wnd: HWnd; Msg, WParam: Word; LParam: Longint): Longint;
begin
  try
    case Msg of
      WM_DESTROY: Application.DialogHandle := 0;	{ clear handle on destroy }
      WM_NCACTIVATE:
        if Bool(WParam) then	{ if it's activating... }
          Application.DialogHandle := Wnd;	{ ...assign the handle... }
        else Application.DialogHandle := 0;	{ ...otherwise clear it }
      ...
    end;
    Result := CallDefDialogProc;
  except
    Application.HandleException(nil);
  end;
end; 
