问题
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:
I found out that
MessageDlg
function uses the same icons obtained byLoadImage
when the Enable runtime themes flag is deactivated (in the Project Options).The
MessageDlg
function seems to use some constants defined inCommCtrl
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