MFC中弹出对话框

VS2010 C++ 中新的弹出对话框

1 添加头函数

#include "afxdialogex.h"
#include "afxtaskdialog.h"

2 代码如下

        //qiangguo 2010-5-26
	CString message("My message to the user");
	CString dialogTitle("My Task Dialog title");
	CString emptyString;
	// TODO: Add your control notification handler code here
	CString expandedLabel("Hide extra information");
	CString collapsedLabel("Show extra information");
	CString expansionInfo("This is the additional information to the user,\nextended over two lines.");


	if (CTaskDialog::IsSupported())
	{
		// 1 直接使用
		HRESULT result2 = CTaskDialog::ShowDialog(L"My error message", L"Error", L"New Title", TEMP_LINE1, TEMP_LINE2);

		// 2 详细设置
	    CTaskDialog taskDialog(message, emptyString, dialogTitle, TDCBF_OK_BUTTON);
		taskDialog.SetMainIcon(TD_WARNING_ICON);
		//taskDialog.DoModal();

		taskDialog.SetMainInstruction(L"Warning");
		taskDialog.SetCommonButtons(TDCBF_YES_BUTTON | TDCBF_NO_BUTTON | TDCBF_CANCEL_BUTTON);
		taskDialog.LoadCommandControls(TEMP_LINE1, TEMP_LINE2);
		taskDialog.SetExpansionArea(expansionInfo, collapsedLabel, expandedLabel);
		taskDialog.SetFooterText(L"This is the a small footnote to the user");
		taskDialog.SetVerificationCheckboxText(L"Remember your selection");
		INT_PTR result = taskDialog.DoModal();

		if (taskDialog.GetVerificationCheckboxState() )
		{
		   // PROCESS IF the user selects the verification checkbox 
		}
		switch (result)
		{
		   case TEMP_LINE1:
			  // PROCESS IF the first command line
			  break;
		   case TEMP_LINE2:
			  // PROCESS IF the second command line
			  break;
		   case IDYES:
			  // PROCESS IF the user clicks yes
			  break;
		   case IDNO:
			  // PROCESS IF the user clicks no
			  break;
		   case IDCANCEL:
			  // PROCESS IF the user clicks cancel
			  break;
		   default:
			  // This case should not be hit because closing the dialog box results in IDCANCEL
			  break;
		}
	}
	else
	{
	   AfxMessageBox(message);
	}
原文地址:https://www.cnblogs.com/dbasys/p/1749839.html