Small icons on desktop conflicts w/ Active Desktop

I find that if I force the desktop into small icons mode and then switch
to Active Desktop, the icons disappear. Querying the desktop listview
reveals that it "thinks" they're still present and inplace, but nothing
brings 'em back except logging off and on again.

WHY does this happen? Can it be prevented? To see the problem, try this
little program:

program Test;
{$APPTYPE CONSOLE}
USES Windows, Messages, commctrl;

function GetLVHan : HWnd;
// Get the handle of the desktop listview
begin
  Result := FindWindowEx(FindWindowEx(FindWindowEx(
    GetDesktopWindow, 0, 'Progman', nil), 0,
    'SHELLDLL_DefView', nil), 0, 'SysListView32', nil);
end;

function ActiveDesktop : Boolean;
begin
  Result := FindWindowEx(FindWindowEx(FindWindowEx(
    GetDesktopWindow, 0, 'Progman', nil), 0,
    'SHELLDLL_DefView', nil), 0, 'Internet Explorer_Server',
    nil) <> 0;
end;

procedure SetListviewStyleSmall(H : HWnd);
VAR S : StyleStruct;
begin
  S.StyleOld := GetWindowLong(H, GWL_STYLE);
  S.StyleNew := S.StyleOld AND NOT LVS_TYPEMASK;
  S.StyleNew := S.StyleNew OR LVS_SMALLICON;
  SetWindowLong(H, GWL_STYLE, S.StyleNew);
  SendMessage(H, WM_STYLECHANGED, GWL_STYLE, Integer(@S));
  ShowWindow(H, SW_SHOWNORMAL);
end;

begin
  IF ActiveDesktop THEN
    begin
      WriteLn('Turn off Active Desktop first.');
      Halt;
    end;
  SetListViewStyleSmall(GetLVHan);
  WriteLn('The desktop listview should now have small icons');
  WriteLn('Switch to Active Desktop and watch them disappear');
  WriteLn('(to get them back, log off and on again)');
  WriteLn;
  WriteLn('WHY does this happen? How can it be prevented?');
end.
--
Neil J. Rubenking
Contributing Technical Editor
PC Magazine