title: Switch Application.Mainform at runtime and invoke MainformOnTaskBar cause flickering on Windows Taskbar
body: <p>I am using Delphi 2010 to build a Win32 GUI application running on Windows XP/Vista and Windows 7.</p>
  
  <p>Basically, the Application.MainForm is a read only property and can't be changed at runtime once the first form is created via Application.CreateForm:</p>
  
  <pre><code>begin
    Application.Initialize;
    Application.MainFormOnTaskbar := True;
    Application.CreateForm(TForm1, Form1);
    Application.CreateForm(TForm2, Form2);
    Application.Run;
  end.
  </code></pre>
  
  <p>The above example will make Form1 as application's mainform.  It will show on Windows 7 taskbar's thumbnail preview.</p>
  
  <p>Setting Application.MainFormOnTaskBar to true at runtime allow us to enjoy Windows aero theme features.</p>
  
  <p>I need to switch the application's mainform at runtime.  For example, set Form2 as main form.  I use following code to make it work:</p>
  
  <pre><code>procedure SetAsMainForm(aForm:TForm);
  var
    P:Pointer;
  begin
    Application.MainFormOnTaskBar := False;
    try
      P := @Application.Mainform;
      Pointer(P^) := aForm;
      aForm.Show;
    finally
      Application.MainFormOnTaskBar := True;
    end;
  end;
  
  procedure TForm1.Button1Click(Sender: TObject);
  begin
    SetAsMainForm(Form2);
  end;
  </code></pre>
  
  <p>Execute Button1.Click will make Form2 as mainform and update the Windows' taskbar thumbnail preview.  However, the Taskbar may flicker on the switching.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Is there any way to away such flickering?</li>
  <li>Is it safe to set Application.MainformOnTaskBar := False and set it to True again in runtime? </li>
  </ol>