title: Replace the icon of a VCL form with the icon of another .exe file at runtime?
body: <p>With Delphi XE7, I want to change the icon of the current VCL form (not of the application) at runtime. So I tried this code:</p>
  
  <pre><code>procedure TForm1.LoadExeIcon(const AExeFileName: string);
  var
    Icon: TIcon;
  begin
    Icon := TIcon.Create;
    try
      Icon.Handle := ExtractIcon(HInstance, PWideChar(AExeFileName), 0);
      Self.Icon.Assign(Icon);
    finally
      Icon.Free;
    end;
  end;
  </code></pre>
  
  <p>The changed icon should then be visible on the left top corner of the window (small image format) and in the taskbar (large image format).</p>
  
  <p>It works, but there is a small problem: The new small icon in the top left corner of the window looks blurred, supposedly because the large image from the exe file gets stretched to the smaller size.</p>
  
  <p>This is how the small image looks in the window of the original exe program:  </p>
  
  <p><img src="https://i.stack.imgur.com/VOriv.png" alt="enter image description here"></p>
  
  <p>And this is how the small image looks in the test program after replacement:  </p>
  
  <p><img src="https://i.stack.imgur.com/sSyMz.png" alt="enter image description here"></p>
  
  <p>The large icon in the taskbar looks perfect.</p>
  
  <p>So how can I make the small icon look nice like in the original exe file?</p>
  
  <p>EDIT:</p>
  
  <p>I followed David's advice and here is the working solution. To make the cake really sweet I added an overlay icon to the taskbar icon:</p>
  
  <pre><code>procedure TForm1.LoadExeIcon(const AExeFileName: string);
  // Load Large and Small Icon from Exe file and assign them to the Form Icon
  // Add Overlay to Taskbar Icon
  var
    LIcon: HICON;
    SIcon: HICON;
    OLIcon: TIcon;
    NumberOfIconsInExeFile: Integer;
  begin
    NumberOfIconsInExeFile := ExtractIconEx(PWideChar(AExeFileName), -1, LIcon, SIcon, 0);
    if NumberOfIconsInExeFile &gt; 0 then // if there are any icons in the exe file
    begin
      ExtractIconEx(PWideChar(AExeFileName), 0, LIcon, SIcon, 1);
      SendMessage(Form1.Handle, WM_SETICON, 1, LIcon);
      SendMessage(Form1.Handle, WM_SETICON, 0, SIcon);
    end;
  
    // apply an overlay icon to the taskbar icon with new TTaskbar component:
    OLIcon := TIcon.Create;
    try
      ilTest.GetIcon(0, OLIcon);
      Taskbar1.OverlayIcon.Assign(OLIcon);
      Taskbar1.OverlayHint := 'My Hint'; // does not work?
      Taskbar1.ApplyOverlayChanges;
    finally
      OLIcon.Free;
    end;
  end;
  </code></pre>