(同一个世界,同一个梦想,交流学习C++Builder XE10,传承c++builder的魅力!欢迎各地朋友加入我的QQ群484979943、860634510、299497712,进群密码“BCB”,同时也请将该群号广为宣传,希望能够广集各方高手,共同进步。)
本人主笔的国内第一本uniGUI教学资料已诞生,分为cbuilder和delphi两个版本,买代码送手册,需要的朋友可以加入我的QQ技术交流群484979943、860634510、299497712给我(群主)留言。资料简介:https://blog.csdn.net/dlboy2018/article/details/88923832
MessageDlg函数主要用于弹出消息提示对话框,并根据你的按键选择执行不同步骤(如下图),uniGUI下MessageDlg函数的使用和VCL下有较大差别,请听我细细道来。
一、VCL窗口程序开发模式下的使用方法
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
if(MessageDlg(AnsiString("确认删除吗?"),mtConfirmation,TMsgDlgButtons()<<mbYes<<mbNo,0)!=mrYes)
{
ShowMessage("No");
}
else
{
ShowMessage("Yes");//在这里写你想干的事情吧
}
}
//---------------------------------------------------------------------------
输入:
参数1:提示消息
参数2:提示种类,如mtWarning、mtError、mtInformation、mtConfirmation、mtCustom
参数3:按钮种类,如mbYes、mbNo、mbOK、mbCancel、mbAbort、mbRetry、mbIgnore、mbAll、mbNoToAll、mbYesToAll、mbHelp、mbClose
参数4:一般写0即可
输出:
mrYes:是
mrNo:否
还有mrNone、mrOK、mrCancel、mrAbort、mrRetry、mrIgnore、mrClose、mrHelp、mrTryAgain、mrContinue、mrAll、mrNoToAll、mrYesToAll
在VCL下可以直接判断MessageDlg函数的返回结果来获知客户行为,在消息弹出时,后续代码都暂停,待客户点击操作后再顺序执行后续代码。但是在uniGUI web下,MessageDlg在客户点击操作后MessageDlg不能返回客户行为,而是通过回调函数来传递客户操作行为,你想干的事情需要在回调函数里写代码。
二、uniGUI web程序开发模式下的使用方法
1、在Main.h声明回调函数callBack
//---------------------------------------------------------------------------
#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <uniGUIForm.hpp>
#include <uniGUIRegClasses.hpp>
#include "uniBitBtn.hpp"
#include "uniButton.hpp"
#include "uniGUIBaseClasses.hpp"
#include "uniGUIClasses.hpp"
//---------------------------------------------------------------------------
class TMainForm : public TUniForm
{
__published: // IDE-managed Components
TUniBitBtn *UniBitBtn1;
void __fastcall callBack(TComponent *Sender,Integer AResult);
void __fastcall UniBitBtn1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
TMainForm *MainForm(void);
//---------------------------------------------------------------------------
#endif
2、在Main.cpp中定义回调函数
void __fastcall TMainForm::callBack(TComponent *Sender,Integer AResult)
{
if(AResult==mrYes)
{
ShowMessage("Yes");//在这里写你想干的事情吧
}
else
{
ShowMessage("No");
}
}
//---------------------------------------------------------------------------
3、如何调用MessageDlg
void __fastcall TMainForm::UniBitBtn1Click(TObject *Sender)
{
MessageDlg("确认删除吗?",System::Uitypes::TMsgDlgType::mtInformation,TMsgDlgButtons()<<System::Uitypes::TMsgDlgBtn::mbYes<<System::Uitypes::TMsgDlgBtn::mbNo,callBack);
//注意:此处不能再有消息提示代码,否则MessageDlg的提示确认框将不出现。
}
注意事项:
参数1:消息
参数2:类型,mtInformation要换成System::Uitypes::TMsgDlgType::mtInformation
参数3:按钮,mbYes要换成System::Uitypes::TMsgDlgBtn::mbYes
mbNo要换成System::Uitypes::TMsgDlgBtn::mbNo
参数4:要写上你定义好的回调函数的名字,本文为callBack
特别注意:MessageDlg函数后面不能再有ShowMessage等消息提示代码,否则MessageDlg本身的提示确认将被覆盖失效.后续提示信息需要放在callBack回调函数里面.