TApplicationIcon (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following code allows you to use a dialog box to redefine the icon for the application at run time. When you click Button1, OpenDialog1 executes and you specify an icon file name. The Icon is then assigned to the application. At run time, click Button1 to select the icon, then minimize the application to see the icon.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  OpenPictureDialog1->DefaultExt = GraphicExtension(__classid(TIcon));
  OpenPictureDialog1->FileName = GraphicFileMask(__classid(TIcon));
  OpenPictureDialog1->Filter = GraphicFilter(__classid(TIcon));
  OpenPictureDialog1->Options.Clear();
  OpenPictureDialog1->Options << ofFileMustExist << ofHideReadOnly << ofNoChangeDir;
  while (true)
  {
	if (OpenPictureDialog1->Execute())
    {
      if (!OpenPictureDialog1->Options.Contains(ofExtensionDifferent))
      {
        Application->Icon->LoadFromFile(OpenPictureDialog1->FileName);
        break;
      }
      else // reset Options to remove ofExtensionDifferent
      {
        OpenPictureDialog1->Options.Clear();
        OpenPictureDialog1->Options << ofFileMustExist << ofHideReadOnly << ofNoChangeDir;
      }
    }
    else // user cancelled
      break;
  }
}

Uses