MFC应用实例:[20]使用MessageBox消息对话框
1、新建一个基于对话框的应用程序,应用程序命名为DoMessage。
![MFC应用实例:[20]使用MessageBox消息对话框](https://exp-picture.cdn.bcebos.com/05e24be983aee8d7ed3e195c6b781431deb666a8.jpg)
2、对对话框进行如下的处理,添加提示,错误,退出按钮,和一个静态文本框。
![MFC应用实例:[20]使用MessageBox消息对话框](https://exp-picture.cdn.bcebos.com/e1390a31dfb6326ced72637c89532f63228560a8.jpg)
![MFC应用实例:[20]使用MessageBox消息对话框](https://exp-picture.cdn.bcebos.com/031231632385e0362285bd5bb8e039723c035aa8.jpg)
3、分别对提示,错误,退出这三个按钮添加响应。并添加如下的代码:
void CDoMessageDlg::OnTishi()
{
// TODO: Add your control notification handler code here
MessageBox("简单的消息提示框","提示",MB_ICONINFORMATION);
m_Text.SetWindowText("信息提示");
}
void CDoMessageDlg::OnCuowu()
{
// TODO: Add your control notification handler code here
int nvalue=MessageBox("程序运行出现错误!","错误",MB_ABORTRETRYIGNORE|MB_ICONERROR);
if(nvalue==IDABORT)//用户按下了"终止"按钮
m_Text.SetWindowText("用户选择了终止程序");
else if(nvalue==IDRETRY)//用户按下了"终止"按钮
m_Text.SetWindowText("用户选择了重试程序");
else//用户按下了"忽略"按钮
m_Text.SetWindowText("用户选择了忽略程序");
}
void CDoMessageDlg::OnTuichu()
{
// TODO: Add your control notification handler code here
int nvalue= MessageBox("是否真的要退出程序?","退出",4+32+256);
if(nvalue==IDYES)//用户按下了"是"按钮
m_Text.SetWindowText("用户选择了退出程序");
else
m_Text.SetWindowText("用户取消了退出程序");
}
![MFC应用实例:[20]使用MessageBox消息对话框](https://exp-picture.cdn.bcebos.com/e3d059e833e03972f9174159b5863048604356a8.jpg)
4、应用程序点击提示按钮时运行结果如下
![MFC应用实例:[20]使用MessageBox消息对话框](https://exp-picture.cdn.bcebos.com/3c42a5ea3e863048a9572d67c33104ebf7a752a8.jpg)
5、应用程序点击错误按钮时运行结果如下
![MFC应用实例:[20]使用MessageBox消息对话框](https://exp-picture.cdn.bcebos.com/d695563104ebf6a7921b7898ffee1c324a184fa8.jpg)
6、应用程序点击退出按钮时运行结果如下
![MFC应用实例:[20]使用MessageBox消息对话框](https://exp-picture.cdn.bcebos.com/5e4e9c2b74ee1c329a0cab9f07f1d8a727334ba8.jpg)