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);
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值