MessageDlg显示信息图标,而不是确认 [英] MessageDlg shows information icon instead of confirmation

查看:293
本文介绍了MessageDlg显示信息图标,而不是确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Win 7上,MessageDlg显示信息图标而不是确认图标(问号)。
这里是代码:

On Win 7, MessageDlg shows information icon instead of confirmation icon (question mark). Here is the code:

MessageDlg('Are you sure you want to delete this file?'+ CRLF+ FileName, mtConfirmation, [mbYes, mbNo], 0)= mrYes

我做错了什么? p>

What am I doing wrong?

推荐答案

首先,注意一个简单的解决方法是使用Windows API MessageBox 功能代替:

First, notice that a simple workaround is to use the Windows API MessageBox function instead:

MessageBox(Handle, 'This is a test.', 'Test', MB_ICONQUESTION or MB_YESNO)

MessageBox http://privat.rejbrand.se/MessageBoxQMark.png

但为什么不 MessageDlg 工作?那么, MessageDlg 做了两件可能的事情之一。如果可能,它使用Windows Vista + Task对话框,即操作系统是Windows Vista或更高版本主题已启用 UseLatestCommonDialogs 全局变量为 true (默认值)。如果没有,VCL实际上会创建一个自定义的 TForm ,并手动添加所有按钮,标签和图标(如果您问我 - 为什么不简单地使用 MessageBox ?)。

But why doesn't MessageDlg work? Well, MessageDlg does one of two possible things. It uses the Windows Vista+ Task Dialog, if possible, that is, it the OS is Windows Vista or later and themes are enabled and the UseLatestCommonDialogs global variable is true (the default). If not, the VCL actually creates a custom TForm and adds all buttons, labels, and icons manually (which is a bit odd if you ask me -- why not simply use MessageBox?).

最后一个方法支持问号图标。确实,尝试

The last approach supports the question-mark icon. Indeed, try

UseLatestCommonDialogs := false;
MessageDlg('This is a test', mtConfirmation, [mbYes, mbNo], 0);

MessageDlg http://privat.rejbrand.se/MessageDlgQMark.png

但是这样看起来很丑陋。请不要这样做它是愚蠢来创建一个自定义消息对话框,而不是使用本地操作系统对话框!

But this looks so ugly! Please don't do this! It is stupid to create a custom message dialog instead of using the native OS dialogs!

然而,不幸的是,任务对话框不支持问号图标( 作为预定义图标 )。这不是限制 TTaskDialog 包装器,而是Windows任务对话框API的限制。例如,请参阅官方文档。有 TD_ERROR_ICON TD_WARNING_ICON TD_INFORMATION_ICON ,但没有问号图标。

Unfortunately, however, the Task Dialog does not support the question-mark icon (as a pre-defined icon). This is not a restriction of the TTaskDialog wrapper, but a limitation of the Windows Task Dialog API. See the official documentation, for instance. There are TD_ERROR_ICON, TD_WARNING_ICON, and TD_INFORMATION_ICON, but no question-mark icon.

当然,任务对话框可以使用任何图标。例如,如果(Win32MajorVersion> = 6)和ThemeServices.ThemesEnabled,然后$ TT $ B与TTaskDialog,您可以执行

Of course, the Task Dialog can use any icon. For instance, you can do

if (Win32MajorVersion >= 6) and ThemeServices.ThemesEnabled then
    with TTaskDialog.Create(Self) do
      try
        Caption := 'Test';
        Title := 'Test';
        Text := 'This is a test.';
        CommonButtons := [tcbYes, tcbNo];
        CustomMainIcon.ReleaseHandle;
        CustomMainIcon.Handle := LoadIcon(0, IDI_QUESTION);
        Flags := [tfUseHiconMain];
        Execute;
      finally
        Free;
      end
  else
    MessageBox(Handle,
               'This is a test.',
               'Test',
               MB_ICONQUESTION or MB_YESNO);



>任务对话框API不可用。

Notice that I fall back on the old MessageBox should the Task Dialog API not be available.

任务对话框http://privat.rejbrand.se/TaskDialogQMark.png

原则上, MessageDlg 函数可以使用额外的逻辑来分开处理问号的情况,不同于信息,警告和错误情况。这将使得 mtConfirmation 即使使用任务对话框也可以给出正确的图标,稍微复杂一些,而且不太优雅的VCL代码。然而,显然,Embarcadero选择了简单的假装你要求信息图标的更简单的选择。

In principle, the MessageDlg function could use additional logic to handle the question-mark case separately, in a way that differs from the information, warning, and error cases. This would have made the mtConfirmation give the right icon even with the Task Dialog, at the expence of slightly more complicated, and less elegant, VCL code. Apparently, however, Embarcadero chose the simpler alternative of simply pretending that you asked for the information icon.

仍然,我想知道为什么微软选择不在TD_QUESTION_ICON常量中包含API。也许这个图标在他们最新的UI指南中不鼓励?

Still, I wonder why Microsoft chose not to include a TD_QUESTION_ICON constant in the API. Perhaps this icon is discouraged in their latest UI guidelines?

这篇关于MessageDlg显示信息图标,而不是确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆