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

Visual c++ 将CTaskDialog的主图标设置为问题?,visual-c++,mfc,taskdialog,Visual C++,Mfc,Taskdialog,我有一个我正在处理的CTaskDialog: 代码如下: CTaskDialog dlg(_T("How would you like to download the data?"), _T("Download Schedule Information"), _T("Meeting Schedule Assistant"), TDCBF_OK_BUTTON | TDCB

我有一个我正在处理的
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();
}
const HICON hiconQuestion = AfxGetApp()->LoadStandardIcon(IDI_QUESTION);
dlg.SetMainIcon(hiconQuestion);
是否可以将主图标设置为问题?我只能在源代码中看到这些定义:

#define TD_WARNING_ICON         MAKEINTRESOURCEW(-1)
#define TD_ERROR_ICON           MAKEINTRESOURCEW(-2)
#define TD_INFORMATION_ICON     MAKEINTRESOURCEW(-3)
#define TD_SHIELD_ICON          MAKEINTRESOURCEW(-4)
这就是你要找的。与大多数处理Win32资源的函数一样,它有两个重载:

void SetMainIcon(
   HICON hMainIcon
);

void SetMainIcon(
   LPCWSTR lpszMainIcon
);
第一个获取图标资源的句柄(
HICON
),而第二个获取标识可从中加载图标资源的资源的字符串

如果要将任务对话框设置为显示应用程序的图标,则只需传入相应的
HICON
。您还可以使用从应用程序资源加载的自定义图标

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

  • 问号图标仅用于帮助入口点。有关更多信息,请参阅指南
  • 不要使用问号图标提问。同样,问号图标仅用于帮助入口点。无需使用问号图标提问,只要将主要说明作为问题呈现即可。 不要经常用警告图标替换问号图标。仅当问题具有重大后果时,才用警告图标替换问号图标。否则,请不要使用图标
所以,这就是为什么没有定义标准问号图标的原因。这些
TD_*\u图标
定义直接来自任务对话框的Win32标题(它们与您在中使用的标题相同),而不是MFC包装类的一部分

如果您必须使用此图标,解决方法如下:

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();
}
const HICON hiconQuestion = AfxGetApp()->LoadStandardIcon(IDI_QUESTION);
dlg.SetMainIcon(hiconQuestion);

(请注意,相同的
HICON
可以传递到
CTaskDialog
SetFooterIcon
成员函数。)

谢谢。我假设一个问题图标,因为它是一个问题!啊!让我看看我是否可以使用我的应用程序图标。如果这是一个破坏性的行为,那么你应该使用警告图标。否则,也许根本不考虑使用图标?这就是标准Windows应用程序所做的(例如,记事本、绘画等)。非常好的建议!谢谢你的详尽回答和有用的指导。