1添加头文件
#include <afxtaskdialog.h>//任务框的 MFC 支持
2添加按钮响应事件
void CTaskDlg::OnBnClickedButton1() { //1、对话框标题 //2、内容的标题 //3、内容的图标 //4、内容的提示 //5、内容的隐藏提示 //6、进度条 //7、单选按钮 //8、运行和提醒 //9、末尾的按钮 //10、多选按钮 //11、末尾的提示 //12、末尾的提示图标 CString strMessage(L"你想把你的改变保存到文档中吗?");//8、运行和提醒 文本 CString strDialogTitle(L"保存文档"); //1、对话框标题 文本 CString strMainInstruction(L"保存文档选项"); //2、内容的标题 文本 CString expandedLabel(L"隐藏额外信息"); //5、内容的隐藏提示 隐藏 CString collapsedLabel(L"显示隐藏信息");//5、内容的隐藏提示 显示 CString expansionInfo(L"你可以将文档保存为XML或者二进制.你最好保存为XML的标准格式."); //5、内容的隐藏提示 隐藏提示 if (CTaskDialog::IsSupported) //检测是否支持任务框 { //基本设置:(内容的标题下的提示语)+(内容的标题)+(对话框的标题)+按下按钮消息 CTaskDialog taskDialog(strMessage, strMainInstruction, strDialogTitle, TDCBF_OK_BUTTON); //详细设置 taskDialog.SetMainIcon(TD_INFORMATION_ICON); //3、内容的图标 taskDialog.SetCommonButtons(TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON); //9、末尾的按钮 否或者取消 taskDialog.LoadCommandControls(IDS_SAVE_OPTION1,IDS_SAVE_OPTION2); //8、运行和提醒 两行 提示文本控件 taskDialog.SetExpansionArea(expansionInfo, collapsedLabel, expandedLabel); //5、内容的隐藏提示 按钮文本 信息文本 taskDialog.SetFooterText(L"末尾的提示:你如果不保存,信息将丢失!"); //11、末尾的提示 taskDialog.SetVerificationCheckboxText(L"记住你的选择"); //10、多选按钮 INT_PTR result = taskDialog.DoModal(); // 此代码将显示任务对话框并检索用户的选择 if (taskDialog.GetVerificationCheckboxState() ) //判断是否勾选了复选框 { // PROCESS IF the user selects the verification checkbox AfxMessageBox(L"xuanze"); } //判断选择的结果,以便进行相应的操作 switch (result) { case IDS_SAVE_OPTION1: // AfxMessageBox(L"You chose to save as XML"); break; case IDS_SAVE_OPTION2: AfxMessageBox(L"You chose to save as binary"); break; case IDNO: AfxMessageBox(L"You chose not to save"); break; case IDCANCEL: AfxMessageBox(L"You chose to cancel"); break; default: // this case should not be hit ASSERT(FALSE); break; } } else { AfxMessageBox(strMessage); } }
3参考资料
http://wenku.baidu.com/view/cff3e431a32d7375a41780dc.html
http://msdn.microsoft.com/zh-cn/library/vstudio/dd465289.aspx