我找到了针对特定问题的解决方案:with TTaskDialogButtonItem(Buttons.Add) do begin Caption := 'The caption';CommandLinkHint := 'The explanation.'; end; 这并不是很明显,但它有效... - Andreas Rejbrand
1我个人认为,直接针对Win32 Api函数进行编写会更容易,而这些函数使用起来非常简单。 - David Heffernan
@David:是的,也许我应该这样做。 - Andreas Rejbrand
如果你想支持XP,那么你需要降级到其他东西,所以你不管怎样都需要做一些工作。 - David Heffernan
with TTaskDialog.Create(Self) dotry
Caption := 'My Application';
Title := 'Hello World!';
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?';
CommonButtons := [tcbClose];
Execute;
finally
Free;
end;
当然,如果在 Windows XP 下运行,由于没有任务对话框 API,任务对话框将会使程序崩溃。如果禁用了视觉主题,它也无法正常工作。在任何这样的情况下,我们需要坚持使用老式的 MessageBox。因此,在实际应用中,我们需要进行如下操作:
if (Win32MajorVersion >= 6) and ThemeServices.ThemesEnabled thenwith TTaskDialog.Create(Self) dotry
Caption := 'My Application';
Title := 'Hello World!';
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?';
CommonButtons := [tcbClose];
Execute;
finally
Free;
endelse
MessageBox(Handle,
'I am an ordinary MessageBox conveying the same message in order to support' +
'older versions of the Microsoft Windows operating system (XP and below).',
'My Application',
MB_ICONINFORMATION or MB_OK);
with TTaskDialog.Create(Self) dotry
Caption := 'My Application';
Title := 'The Process';
Text := 'Do you want to continue even though [...]?';
CommonButtons := [tcbYes, tcbNo];
MainIcon := tdiNone; // There is no tdiQuestionif Execute thenif ModalResult = mrYes then
beep;
finally
Free;
end;
以下是剩余图标类型的示例(分别为盾牌、警告和错误):
最后,您应该知道可以使用DefaultButton属性在对话框中设置默认按钮。
with TTaskDialog.Create(Self) dotry
Caption := 'My Application';
Title := 'The Process';
Text := 'Do you want to continue even though [...]?';
CommonButtons := [tcbYes, tcbNo];
DefaultButton := tcbNo;
MainIcon := tdiNone;
if Execute thenif ModalResult = mrYes then
beep;
finally
Free;
end;
with TTaskDialog.Create(self) dotry
Title := 'Confirm Removal';
Caption := 'Rejbrand BookBase';
Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]);
CommonButtons := [];
with TTaskDialogButtonItem(Buttons.Add) dobegin
Caption := 'Remove';
ModalResult := mrYes;
end;
with TTaskDialogButtonItem(Buttons.Add) dobegin
Caption := 'Keep';
ModalResult := mrNo;
end;
MainIcon := tdiNone;
if Execute thenif ModalResult = mrYes then
DoDelete;
finally
Free;
end
with TTaskDialog.Create(self) dotry
Title := 'Confirm Removal';
Caption := 'Rejbrand BookBase';
Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]);
CommonButtons := [];
with TTaskDialogButtonItem(Buttons.Add) dobegin
Caption := 'Remove';
CommandLinkHint := 'Remove the book from the catalogue.';
ModalResult := mrYes;
end;
with TTaskDialogButtonItem(Buttons.Add) dobegin
Caption := 'Keep';
CommandLinkHint := 'Keep the book in the catalogue.';
ModalResult := mrNo;
end;
Flags := [tfUseCommandLinks];
MainIcon := tdiNone;
if Execute thenif ModalResult = mrYes then
DoDelete;
finally
Free;
end
with TTaskDialog.Create(self) dotry
Title := 'Confirm Removal';
Caption := 'Rejbrand BookBase';
Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]);
CommonButtons := [];
with TTaskDialogButtonItem(Buttons.Add) dobegin
Caption := 'Remove';
CommandLinkHint := 'Remove the book from the catalogue.';
ModalResult := mrYes;
end;
with TTaskDialogButtonItem(Buttons.Add) dobegin
Caption := 'Keep';
CommandLinkHint := 'Keep the book in the catalogue.';
ModalResult := mrNo;
end;
Flags := [tfUseCommandLinks, tfAllowDialogCancellation];
ExpandButtonCaption := 'Technical information';
ExpandedText := 'If you remove the book item from the catalogue, the corresponding *.book file will be removed from the file system.';
MainIcon := tdiNone;
if Execute thenif ModalResult = mrYes then
DoDelete;
finally
Free;
end
2我总是测试操作系统版本和视觉主题的可用性(是的,如果没有启用Aero,则TTaskDialog在Vista/7上无法工作),如果可能的话,使用TTaskDialog,如果不行则使用普通的MessageBox,就像http://specials.rejbrand.se/TTaskDialog中所示。 TTaskDialog美妙的视觉风格使得这些额外的工作都值得。 (但说实话,我真的感觉像“今天谁还在使用XP?”) - Andreas Rejbrand
我认为责怪 Embarcadero 不能让 TTaskDialog 在 XP 上工作是不明智的,因为 TTaskDialog 只是一个操作系统 API 的包装器,这在 Vista 中是新的。是的,也许如果 TTaskDialog 在 XP 上(或没有视觉主题)进行了一些自定义处理,可以稍微简化开发人员的生活(这种简化如果他们仅使用本机 OS API 就不会存在),但我认为您不应要求包装器这样做。 - Andreas Rejbrand
声明:我在 Embarcadero 工作。但我个人仍然不喜欢那些不能在所有常见的 Windows 版本上工作的组件。如果你想编写你的应用程序,在 XP 上无法工作,没问题。但要记住,stackoverflow 不仅关乎你和你的问题,它也涉及到后来者将会阅读这些信息。所以尽管踩我吧。但其他人可能会出现,并需要了解这一点。 - Warren P
1@Warren,看看Andreas的写作吧。他的例子展示了如何使它在XP上很好地回退。 - Chris Thornton
with TTaskDialogButtonItem(Buttons.Add) do begin Caption := 'The caption';CommandLinkHint := 'The explanation.'; end;
这并不是很明显,但它有效... - Andreas Rejbrand