How to change application icon within taskbar Delphi 2010

12,746

The icon is that of the window associated with the taskbar button. So with Application.MainFormOnTaskbar set to True, it's the main form icon. When False it's the icon of the hidden window of Application. So to have different icon on taskbar from main form, you need MainFormOnTaskbar to be False, and assign different icon to Application.Icon. This seems to be the easy way to work around the issue.

If I recall the VCL only sets one size of icon. In my experience it is better to do the job properly yourself and send WM_SETICON messages directly to set both small and large icons.

As for where your icons reside, link them to your executable as resources. I avoid image lists because I lose control of the raw .ico files, but that's perhaps just me being picky. Feel free to use image lists if you like.

Share:
12,746

Related videos on Youtube

Galvion
Author by

Galvion

I'm just an ordinary web developer for HTML / CSS/ Javascript and also I could develop a little of the desktop applications with Delphi...

Updated on May 25, 2022

Comments

  • Galvion
    Galvion almost 2 years

    I change the icon of my application with my own icon (32x32 16bit EGA) using :

    Project > Option > Applications > Load Icon
    

    The Icon within the taskbar changed very well in many Border Style := bsNone or bsSingle or bsSizeable or bsSizeToolWin or bsToolWindow. But the icon did not change while I use BorderStyle := bsDialog.

    Please do not tell me to use :

    Application.Icon.LoadFromFile(extractfilepath(application.exename) + '\myicon.ico');
    

    Becase I want to submit one EXE file only.

    PS: I use Embarcadero Delphi 2010

    • TLama
      TLama over 10 years
      That's by design. You're not used to use a bsDialog style for your main form. You can use e.g. bsSingle and remove the minimize/maximize buttons to get the same result, but for window with bsDialog style you won't get an icon.
    • LU RD
      LU RD over 10 years
      There is a QC about this, Application and/or Form icon not shown with bsDialog. It was closed as by design.
    • Galvion
      Galvion over 10 years
      @LU RD : it means that we can do nothing about it ?
    • LU RD
      LU RD over 10 years
      Just do as David suggests in his answer. You can have the icon(s) in a resource like a TImageList to avoid loading from disk.
  • M.M
    M.M over 9 years
    In XE5 + windows 7, Application->Icon->LoadFromFile sets all icons to be a resized version of the 32x32 icon; even if your icon file does contain 24x24 (corner), 48x48 (alt-tab, taskbar), 256x256 (desktop).