TaskDialog 在我的 Delphi 程序中不工作
TaskDialog not working in my Delphi Program
我正在使用 Delphi 10.4。这是一个 Windows VCL 应用程序。
我想将我所有的 ShowMessage、MessageDlg 和 MessageBox 调用转换为程序中的 TaskDialogs。当我尝试这样做时,我无法让 TaskDialog 显示任何内容。
所以我所做的是创建一个新的最小 VCL 应用程序,只需向其中添加一个按钮和一个 TaskDialog:
这是我的代码:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
TaskDialog1: TTaskDialog;
procedure MyMessageBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
procedure TForm1.MyMessageBox;
begin
Form1.TaskDialog1.Caption := 'My Application';
Form1.TaskDialog1.Title := 'Hello World!';
Form1.TaskDialog1.Text := 'I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ' +
'in the Microsoft Windows Vista operating system. Am I not adorable?';
Form1.TaskDialog1.CommonButtons := [tcbClose];
Form1.TaskDialog1.Execute;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MyMessageBox;
end;
{$R *.dfm}
begin
Application.Run;
end.
效果很好。当 运行 它并按下 Button1 时,我得到:
所以现在我去申请。我在主窗体中添加了一个按钮,并将 MyMessageBox 过程设置为:
procedure TLogoAppForm.MyMessageBox;
begin
ShowMessage('ShowMessage ......................................');
Application.MessageBox('Application.MessageBox ...........................', 'Error', 0);
MessageDlg('MessageDlg ................................', mtWarning, [mbOk], 0);
LogoAppForm.TaskDialog1.Caption := 'My Application';
LogoAppForm.TaskDialog1.Title := 'Hello World!';
LogoAppForm.TaskDialog1.Text := 'I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ' +
'in the Microsoft Windows Vista operating system. Am I not adorable?';
LogoAppForm.TaskDialog1.CommonButtons := [tcbClose];
LogoAppForm.TaskDialog1.Execute;
end;
在我的应用程序中正确按下按钮会依次显示 ShowMessage、MessageBox 和 MessageDlg windows,但在关闭 MessageDlg window 后,TaskDialog 什么也没有出现。
有谁知道可能导致 TaskDialog 在我的应用程序中不起作用的原因以及我该如何解决这个问题?
您必须为 VCL TTaskDialog
启用运行时主题才能工作。转到 Project/Options/Application/Manifest 执行此操作。
我正在使用 Delphi 10.4。这是一个 Windows VCL 应用程序。
我想将我所有的 ShowMessage、MessageDlg 和 MessageBox 调用转换为程序中的 TaskDialogs。当我尝试这样做时,我无法让 TaskDialog 显示任何内容。
所以我所做的是创建一个新的最小 VCL 应用程序,只需向其中添加一个按钮和一个 TaskDialog:
这是我的代码:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
TaskDialog1: TTaskDialog;
procedure MyMessageBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
procedure TForm1.MyMessageBox;
begin
Form1.TaskDialog1.Caption := 'My Application';
Form1.TaskDialog1.Title := 'Hello World!';
Form1.TaskDialog1.Text := 'I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ' +
'in the Microsoft Windows Vista operating system. Am I not adorable?';
Form1.TaskDialog1.CommonButtons := [tcbClose];
Form1.TaskDialog1.Execute;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MyMessageBox;
end;
{$R *.dfm}
begin
Application.Run;
end.
效果很好。当 运行 它并按下 Button1 时,我得到:
所以现在我去申请。我在主窗体中添加了一个按钮,并将 MyMessageBox 过程设置为:
procedure TLogoAppForm.MyMessageBox;
begin
ShowMessage('ShowMessage ......................................');
Application.MessageBox('Application.MessageBox ...........................', 'Error', 0);
MessageDlg('MessageDlg ................................', mtWarning, [mbOk], 0);
LogoAppForm.TaskDialog1.Caption := 'My Application';
LogoAppForm.TaskDialog1.Title := 'Hello World!';
LogoAppForm.TaskDialog1.Text := 'I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ' +
'in the Microsoft Windows Vista operating system. Am I not adorable?';
LogoAppForm.TaskDialog1.CommonButtons := [tcbClose];
LogoAppForm.TaskDialog1.Execute;
end;
在我的应用程序中正确按下按钮会依次显示 ShowMessage、MessageBox 和 MessageDlg windows,但在关闭 MessageDlg window 后,TaskDialog 什么也没有出现。
有谁知道可能导致 TaskDialog 在我的应用程序中不起作用的原因以及我该如何解决这个问题?
您必须为 VCL TTaskDialog
启用运行时主题才能工作。转到 Project/Options/Application/Manifest 执行此操作。