How to load a TImage using task dialog common icons?

女生的网名这么多〃 提交于 2020-05-15 09:09:12

问题


I'm trying to load icons used by Delphi's task dialogs into a TImage control. As I've learned here, I'm using LoadImage function but icons appear lightly different from the ones which are used by the MessageDlg function.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Image1.Picture.Icon.Handle := LoadImage( 0, IDI_WARNING, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE or LR_SHARED );
  MessageDlg('mtWarning', mtWarning, [mbOk], 0);

  Image1.Picture.Icon.Handle := LoadImage( 0, IDI_ERROR, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE or LR_SHARED );
  MessageDlg('mtError', mtError, [mbOk], 0);

  Image1.Picture.Icon.Handle := LoadImage( 0, IDI_INFORMATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE or LR_SHARED );
  MessageDlg('mtInformation', mtInformation, [mbOk], 0);

  Image1.Picture.Icon.Handle := LoadImage( 0, IDI_QUESTION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE or LR_SHARED );
  MessageDlg('mtConfirmation', mtConfirmation, [mbOk], 0);
end;

end.

As you can see, the icons in the TImage are different from the corresponding icon used by the MessageDlg function.

Further tests:

  1. I found out that MessageDlg function uses the same icons obtained by LoadImage when the Enable runtime themes flag is deactivated (in the Project Options).

  2. The MessageDlg function seems to use some constants defined in CommCtrl unit:

{ Task Dialog Common Icons }

{$EXTERNALSYM TD_WARNING_ICON}
TD_WARNING_ICON = MAKEINTRESOURCEW(Word(-1));
{$EXTERNALSYM TD_ERROR_ICON}
TD_ERROR_ICON = MAKEINTRESOURCEW(Word(-2));
{$EXTERNALSYM TD_INFORMATION_ICON} TD_INFORMATION_ICON = MAKEINTRESOURCEW(Word(-3));
{$EXTERNALSYM TD_SHIELD_ICON}
TD_SHIELD_ICON = MAKEINTRESOURCEW(Word(-4));

How can I get the same icons used by the task dialogs?

来源:https://stackoverflow.com/questions/54826050/how-to-load-a-timage-using-task-dialog-common-icons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!