将 CTaskDialog 的主图标设置为问题?

Setting the main icon of a CTaskDialog as a Question?

我正在处理这个 CTaskDialog

代码如下:

CTaskDialog dlg(_T("How would you like to download the data?"), 
                _T("Download Schedule Information"),
                _T("Meeting Schedule Assistant"), TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON);
dlg.SetMainIcon(TD_INFORMATION_ICON);
dlg.SetFooterIcon(TD_INFORMATION_ICON);
dlg.SetFooterText(_T("All assignments for the selected weeks will be reset."));
dlg.AddRadioButton(44444, _T("Download data for all weeks"));
dlg.AddRadioButton(44445, _T("Download data for selected week"));
dlg.AddRadioButton(44446, _T("Download data for selected week and all additional weeks"));
// Set Width in dialog units (40% screen width)
int iPixelWidth = (::GetSystemMetrics(SM_CXSCREEN) / 100) * 40;
int iDialogUnitsWidth = MulDiv(iPixelWidth, 4, LOWORD(GetDialogBaseUnits()));
dlg.SetDialogWidth(iDialogUnitsWidth);

if(dlg.DoModal() == IDOK)
{
    auto iSelection = dlg.GetSelectedRadioButtonID();
}

请问可以设置主图标吗?我只能在源代码中看到这些定义:

#define TD_WARNING_ICON         MAKEINTRESOURCEW(-1)
#define TD_ERROR_ICON           MAKEINTRESOURCEW(-2)
#define TD_INFORMATION_ICON     MAKEINTRESOURCEW(-3)
#define TD_SHIELD_ICON          MAKEINTRESOURCEW(-4)

SetMainIcon member function 就是您要找的。像大多数处理 Win32 资源的函数一样,它有两个重载:

void SetMainIcon(
   HICON hMainIcon
);

void SetMainIcon(
   LPCWSTR lpszMainIcon
);

第一个接受图标资源的句柄 (HICON),而第二个接受标识可以从中加载图标资源的资源的字符串。

如果你想设置任务对话框来显示你的应用程序的图标,那么你可以简单地传入适当的HICON。您还可以使用从应用程序资源加载的自定义图标。

我不是很确定,但我想你问的是如何使用 question-mark 图标。首先请注意,自 Windows 95 以来,在消息框中使用此类图标已被弃用,Microsoft 强烈反对使用它们。建议您使用它们来表示联机帮助的入口点。引用官方 Win32 样式指南的 Standard Icons 部分:

Question mark icons

  • Use the question mark icon only for Help entry points. For more information, see the Help entry point guidelines.
  • Don't use the question mark icon to ask questions. Again, use the question mark icon only for Help entry points. There is no need to ask questions using the question mark icon anyway it's sufficient to present a main instruction as a question. Don't routinely replace question mark icons with warning icons. Replace a question mark icon with a warning icon only if the question has significant consequences. Otherwise, use no icon.

所以,这就是没有定义标准问号图标的原因。这些 TD_*_ICON 定义直接来自任务对话框的 Win32 headers(它们与您在 TASKDIALOGCONFIG structure 中使用的相同),而不是 MFC 包装器的一部分 class.

如果你绝对必须使用这个图标,解决方法如下:

const HICON hiconQuestion = AfxGetApp()->LoadStandardIcon(IDI_QUESTION);
dlg.SetMainIcon(hiconQuestion);

(请注意,相同的 HICON 可以传递给 CTaskDialogSetFooterIcon 成员函数。)