刚出去转了一下, 吹吹风, 回来继续写。
我们现在来说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"); } //---------------------------------------------------------------------------
//--------------------------------------------------------------------------- #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, 输入输出对话框就介绍到这里了, 我们需要有一个直接的参与感, 至于具体细节, 日后需要的时候, 查阅即可。