本文主要是介绍BCB中的输入对话框和输出对话框(也就是消息对话框),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
刚出去转了一下, 吹吹风, 回来继续写。
我们现在来说BCB中的输出对话框, 这个很常见:
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
}
//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{ShowMessage("clicked");
}
//---------------------------------------------------------------------------
上面的ShowMessage对话框太简单, 我们可以采用稍微复杂一点的:
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
}
//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{MessageBox(NULL, "吃饭啦!", "温馨提示:", 0);
}
//---------------------------------------------------------------------------
稍微复杂了一点, 其实也很简单。 其实, 我们并没有用好MessageBox的第四个参数, 我们来看看下面的程序:
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
}
//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{AnsiString s = "不想吃";int result = MessageBox(NULL, "吃饭啦!", "温馨提示:", MB_OKCANCEL);if(IDOK == result) // 1{s = "走起";}ShowMessage(s);
}
//---------------------------------------------------------------------------
当然, 我们也可以采取MessageDlg来实现类似功能, 再次就不再赘述了。
下面, 我们来看看输入消息框:
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
}
//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{AnsiString s = "0";s = InputBox("提示:", "输入你的工资:", s); // 不是 InputBox("提示:", "输入你的工资:", s);ShowMessage(s);
}
//---------------------------------------------------------------------------
当然, 我们也可以用InputQuery, 如下:
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
}
//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{AnsiString s = "0";InputQuery("提示:", "输入你的工资:", s); // s是引用传入ShowMessage(s);
}
//---------------------------------------------------------------------------
上面两个程序的功能没有什么差别。
OK, 输入输出对话框就介绍到这里了, 我们需要有一个直接的参与感, 至于具体细节, 日后需要的时候, 查阅即可。
这篇关于BCB中的输入对话框和输出对话框(也就是消息对话框)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!